Print using GDI+ and plain PrintDocument object to a pdf file

  • Thread starter Thread starter pamela fluente
  • Start date Start date
P

pamela fluente

hi,

What is the cleanest and effective way to use the PrintDocument object
to print
directly to a pdf file "myfile.pdf" (with no prompt to the user: just
print to file and make pdf) ?

Does anyone have a simple code snippet? Either VB or C# will be
perfect.

-Pam
 
Pam,

This is dependent on the print driver that you are using. Have you
tried setting the PrintFileName property on the PrinterSettings instance
used with your PrintDocument?

Hope this helps.
 
Pam,

This is dependent on the print driver that you are using. Have you
tried setting the PrintFileName property on the PrinterSettings instance
used with your PrintDocument?

Hi Nicholas ,

thanks for you reply. I am afraid I do not get what you mean.

Let's make a simple example. Assume I simply want to send into a new
pdf file (MyFile.PDF) a string, for instance

Private Sub PrintDocument1_PrintPage1(ByVal sender As Object,
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument1.PrintPage
e.Graphics.DrawString("How are you?", New
Font(FontFamily.GenericSansSerif, 18, FontStyle.Bold,
GraphicsUnit.Pixel), Brushes.Green, Point.Empty)
End Sub

without prompting the user. What would your suggestion be in this
case ?

-P
 
Pamela,

Are you tring to create a PDF by printing to it using the PrintDoc?

If so, no way. PrintDoc can draw on a canvas like a bitmap or printer
canvas, but it cannot create a PDF.

If you want to create a PDF you can check iTextSharp a free and very good
dll for creating PDF's.

Rick
 
Pamela,

Are you tring to create a PDF by printing to it using the PrintDoc?

If so, no way. PrintDoc can draw on a canvas like a bitmap or printer
canvas, but it cannot create a PDF.

If you want to create a PDF you can check iTextSharp a free and very good
dll for creating PDF's.
Thanks Rick,

I have downloaded it and tried the examples.
The documents I need to print are by far too complicated, I think, for
that library.
I have thousands of objects and a lot of overlapping pictures with
alpha transparency
an so on. And all the (complex) logic is already implemented as
drawing on a graphics.

Let's try another direction. Is there a product or some api which
allows me to print normally
to a file and then convert the print file to PDF. Similar to what
Adobe Distiller does?
Or, more specifically, is there a kind of DLL version of Distiller (or
similar program ) which allows
creating directly a PDF from a plain print output file, *without*
prompting the user ?

-P
 
You can check PDFCreator. If you know how to create what you want in some
other program, then you can use PDFCreator as the print driver to output to
PDF.

The problem is then that you have to have this installed as a print driver
on all client machines.

Yes, your project sounds complicated, however I think iTextSharp could do it
since I think it can do anything that PDF can implement. The problem is the
overhead in learning how. There is a very good book and very active ng, but
then YOU still need to learn it.

Sorry, I don't have other suggestions.

Rick
 
You can check PDFCreator. If you know how to create what you want in some
other program, then you can use PDFCreator as the print driver to output to
PDF.

The problem is then that you have to have this installed as a print driver
on all client machines.

Yes, your project sounds complicated, however I think iTextSharp could do it
since I think it can do anything that PDF can implement. The problem is the
overhead in learning how. There is a very good book and very active ng, but
then YOU still need to learn it.

Sorry, I don't have other suggestions.

Rick
thanks Rick,

I will try that.

Thank you for the advice.

-P
 
Hi Rick

Im using iTextSharp tool to create a PDF. My requirement is that I need to
print each page from the PDF to different trays in a printer. Im using
PrintDocument to switch betweeen trays. Now that, I need to send the PDF
content of a single page to print using Graphics.DrawImage. Is there any way
of doing this?
 
Back
Top