2

I'm creating a Windows Application with several forms in Microsoft Visual Studio 2005. I want the user to be able to export the current open form as a PDF-file. I ran into some answers recommending PDFSharp, but I have no clue how to use it... I tried to figure it out by reading forums, other questions and answers, but I've just no clue where to get started. So, can someone please help me get started, by telling me how to use PDFSharp in my project?

I've already tried the following: Converting windows form in C# to PDF using PdfSharp

After adding the reference "PdfSharp", from my GDI+ folder, to my project, I'm not able to create a variable as a PdfDocument type.

Or if you guys have other suggestions/recommendations on how to save a Windows Form to pdf, please let me know.

Community
  • 1
  • 1
FJPoort
  • 225
  • 2
  • 7
  • 16
  • Why are you using such an old version of Visual Studio? Are you sure that PdfSharp is compiled against a supported version of the .NET Framework? Visual Studio 2005 was limited to .NET Framework 2.0 and is unable to support .NET Framework 3.5, 4.0, and 4.5 which are the only supported versions of the .NET Framework – Security Hound Sep 21 '12 at 12:53
  • Are you using version 1.32? According to the [README file](http://sourceforge.net/projects/pdfsharp/files/pdfsharp/PDFsharp%201.32/) for version 1.32, you need to use 1.31 with VS 2005. – Anders Gustafsson Sep 21 '12 at 12:54
  • I'm an intern at a company where they have a license to Visual Studio 2005. Can't help it :( But you say this version is incompatible with PdfSharp? That would declare a lot... – FJPoort Sep 21 '12 at 12:55
  • @AndersGustafsson I will immediately check it out! – FJPoort Sep 21 '12 at 12:56
  • I've downloaded 1.32 indeed. Now downloading 1.31, hope this will help. – FJPoort Sep 21 '12 at 12:58
  • @AndersGustafsson It didn't work. When I try to type PdfDocument I only see PdfSharp of PdfSharpException. Maybe iTextSharp is a solution? – FJPoort Sep 21 '12 at 13:07
  • @FJPoort Can't you use one of the newer Express versions of Visual Studio? You won't need to worry about licensing and it do what you need it to in regards to this project. – JMK Sep 21 '12 at 13:14
  • @yms Well, problem solved! I was using PdfSharp instead of PdfSharp.Pdf. Thanks! Add it as answer, and I will accept it :) – FJPoort Sep 21 '12 at 13:28
  • @Anders Gustafsson: PDFsharp 1.32 is compatible with VS 2005. But the source code version no longer includes solutions for VS 2005. – I liked the old Stack Overflow Sep 22 '12 at 05:43

1 Answers1

0

Just include using PdfSharp.Pdf; at the beginning of your C# files.

yms
  • 10,361
  • 3
  • 38
  • 68
  • I was surprised to see that this detail was omitted in every sample code I have seen for PdfSharp, which is not very user friendly. – yms Sep 21 '12 at 13:38
  • It works great now. Next problem, how to save it with the values of textboxes? when I leave them epmty, there's no problem and image en pdf are saved. Then I give input and get output in textboxes, I click export, and I get a message "A generic error occurred in GDI+". In visual studio output window: A first chance exception of type 'System.FormatException' occurred in mscorlib.dll A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll – FJPoort Sep 21 '12 at 13:49
  • Actually, I do not know much about PdfSharp, I think it will be better for you to post a new question about this other issue. – yms Sep 21 '12 at 13:58
  • @YMS: Complete PDFsharp samples (as included with the source code ZIP) do have the using statements; code snippets shown here and there often omit the using statements (but VS should suggest the usings when you type the correct class name and have a reference to the lib/project). – I liked the old Stack Overflow Sep 22 '12 at 05:46