Solved

Printing PDF document using pd_PrintPage in C#

Posted on 2007-11-30
6
6,513 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
This article was originally published on Monitis Blog, you can check it here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sourc…
Introduction to Processes
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…

734 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