Solved

Printing PDF document using pd_PrintPage in C#

Posted on 2007-11-30
6
6,514 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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