Select to view content in your preferred language

Create PDF ?

12846
76
07-20-2010 06:02 AM
CraigPerreault
Deactivated User
Does anyone have a code sample to create a PDF file using the Silverlight API?
0 Kudos
76 Replies
MarkCederholm
Frequent Contributor
Sorry, I should have been more specific.  In PDFExporter.cs, comment out all the _streamOutPDF lines and move your SaveFileDialog lines to just before the document.Save line.  If that's actually the problem, then I'll revise the class accordingly.
0 Kudos
KevinSesock
Emerging Contributor
Attempting to set a WriteTimeout (System.IO.Stream.WriteTimeout) on PDFstream.WriteTimeout =4000; fails with "Timeouts are not supported on this stream". I'm stumped, as I have no idea what alternatives I have.

Leave it to me to find the one situation that is just plain bizarre.

You're right though, when you say that it is taking a while. I think I can time the whole operation on my watch, it's easily over 5 seconds.
0 Kudos
KevinSesock
Emerging Contributor
Sorry, I should have been more specific.  In PDFExporter.cs, comment out all the _streamOutPDF lines and move your SaveFileDialog lines to just before the document.Save line.  If that's actually the problem, then I'll revise the class accordingly.


Close. Unfortunately SaveFileDialog has to be called by a user-initiated event, like a Button_Click event. I created a new property for a SaveFileDialog object, and passed it in from my Button_Click event after showing the dialog, then created the stream from the SaveFileDialog.OpenFile() method inside PDFExporter.cs. Thanks for the suggestion, I now have a PDF file to work with.

Unfortunately, I seem to be missing layers. How exactly does your class determine the order of your layers?
0 Kudos
KevinSesock
Emerging Contributor
Close. Unfortunately SaveFileDialog has to be called by a user-initiated event, like a Button_Click event. I created a new property for a SaveFileDialog object, and passed it in from my Button_Click event after showing the dialog, then created the stream from the SaveFileDialog.OpenFile() method inside PDFExporter.cs. Thanks for the suggestion, I now have a PDF file to work with.

Unfortunately, I seem to be missing layers. How exactly does your class determine the order of your layers?


Not only am I missing layers, but a Dynamic Service Layer is drawing... oddly. As in, the colors of the Dynamic Service Layer are messed up. I assume this is in the bmp conversion method. Any thoughts?

Mark:

I'd be happy to email you the pdfs that were output if you'd like to take a look. Otherwise I'll debug later, right now I've got to get other things taken care of in my app, so maybe I can find a fix if you don't have the time.
0 Kudos
TomArnold1
New Contributor
Can someone send an example of they are using the export to pdf?  Thank you.
0 Kudos
CraigPerreault
Deactivated User
using PdfSharp.Pdf;

        private void PDFbutton_MouseLeftButtonUp(object sender, MouseEventArgs e)
        {
                    SaveFileDialog savePDF = new SaveFileDialog();
                    savePDF.Filter = "PDF file format|*.pdf";
                    savePDF.DefaultExt = ".pdf";
                    if (savePDF.ShowDialog() == true)
                    {
                        System.IO.Stream PDFstream = savePDF.OpenFile();
                        PDFExporter PDFNew = new PDFExporter();
                        PDFNew.SetMap(myMap);
                        PDFNew.SetOutputStream(PDFstream);
                        PDFNew.DoExport();
                    }
        }
0 Kudos
DavidAshton
Frequent Contributor
Can someone tell me where to place the download dll from the PDF libary: http://silverpdf.codeplex.com/



I tried to register the PDF library silverPDF.dll but no luck

So I just added it to my vs project as a ref.... but I'm getting an error message stating it could load the assembly file silverPDF.dll

If I go to the file and right click it and click register.  The "Register ArcGIS Assembly" dialog window pops up.  I can either select Desktop or Server.  I tired both and they both give me the error "Registration Failed" - Could not load file or assembly 'System Windows, Version = 2.0.5.0 culture=neutral, PublicKeyToken 7cec85d7bea7798e or one of its dependencies.  The system cannont find the specified.


O.K. Here's a little more info.  After just adding it to the references in VS I ran debug and got an error stating it was being blocked but I unblocked it after downloading so I went into the debug directory and unblocked again.  No the application luanches but it just hangs and never gets past the original silverlight blue logo.  When I take out all the PDF stuff the app is fine. 



Thanks
0 Kudos
DavidAshton
Frequent Contributor
I got it....

Thanks Kevin! Great Tool.
0 Kudos
VikramS
Frequent Contributor
Hi DAvid ,

Can u please tell me how did u register silver.dll . I am also getting the same error .. Thank u very much

I got it....

Thanks Kevin! Great Tool.
0 Kudos
DavidAshton
Frequent Contributor
I just opened my project in VS.
Right click on References
Click Add Reference
Click the Browse button and browse to the dll.  This add the dll to your VS project
0 Kudos