Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Printing PDF document using pd_PrintPage in C#

Posted on 2007-11-30
6
Medium Priority
?
6,529 Views
Last Modified: 2010-04-21
I am trying to use the following code to print a PDF document from a C# application. It works for a JPEG file but not for a PDF file. I get a message saying, "Not a valid Parameter" while trying to use PDF. I am using Bitmap in ev.Graphics.DrawImage. Can any one help me please? Thank you.


private void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            Rectangle rect = new Rectangle(10,10, 500, 500);
           // Rectangle rectText = new Rectangle(40, 40, 300, 100);
           // StringFormat sf = new StringFormat();
          //  Bitmap b = new Bitmap("C:\\Program Files\\FSH Communications\\RoutePrt\\tmp\\rp2007112910331855.pdf");
            Bitmap b = new Bitmap("C:\\Program Files\\FSH Communications\\RoutePrt\\tmp\\test3.jpg");
            ev.Graphics.DrawImage(b, rect);
          //  ev.Graphics.DrawString("TEXT", new Font("Impact", 20), new SolidBrush(Color.Red), rectText, sf);
        }

Open in new window

0
Comment
Question by:sstukwila
  • 3
  • 3
6 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 20388218
The Bitmap class does not support the PDF format; so you cannot load it the way you've attempted to.

Two possible options for you, are:

  - Convert your PDF's into TIFF format (as Bitmap supports TIFF); or

  - Download a PDF library
    (here's a list: http://csharp-source.net/open-source/pdf-libraries).
     These libraries allow you to draw to the PDF's (if you wish to), and
     can send the PDF's straight to the printer.
0
 

Author Comment

by:sstukwila
ID: 20388921
Hi Mr. InteractiveMind,

Thanks a lot for your guidance. I am not seeing any direct way of converting PDF's to TIFF's inside C#. These PDF files are created inside C#. Can you please let me know if there is a way of doing this inside C#?

Reg Open Source PDF library, I have never used an open source before. So, I am not sure how it works. PDFSharp says that it allows sending output to a printer. In my case, I have the PDF's created already. I just need to find a way to print them out at runtime. I will give a try by downloading the PDFSharp files.

Thanks a lot.
0
 
LVL 25

Accepted Solution

by:
InteractiveMind earned 2000 total points
ID: 20389254
You would need to use an external library to convert the PDF's to TIFF's.
Unfortunately, most of them cost money.

Your best (free) option would really be to go with one of the open source libraries (PDFSharp seems like a good choice), and print directly from that.

Let me know how you get on with PDFSharp.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:sstukwila
ID: 20409500
Hi Mr. Interactive Mind,

PDFSharp worked. I had to work on it for may be 1 hour to get it work. It is a big relief for me. Thanks a lot for your help. I wanted to check with you to see if it is safe and secure to use open source code like this? Can you please let me know your thoughts on this? Thank you.
0
 

Author Closing Comment

by:sstukwila
ID: 31412064
Thank you
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 20410798
Glad to hear it's working.

In many cases, especially for these popular open source projects, the code is often "safer" and more "secure" than typical industry-standard code - because the software has been tested and used by hundreds, or even thousands, of developers. So, especially for the later versions, practically all bugs have been ironed out.

Best of luck.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are like me and like multiple layers of protection, read on!
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question