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
Solved

Printing PDF document using pd_PrintPage in C#

Posted on 2007-11-30
6
6,505 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 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 4 71
Suggestions of cloud services for small businesses 9 52
ejb stateless example 2 25
What does != "" mean in programming 8 80
Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

839 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