I have a whole bunch of 2D graphics that is being used for both rendering controls on screen and used to print, it's pretty custom graphics that couldn't be done by any 3rd party re开发者_如何学编程porting tools or off the shelf controls.
The program can generate PDF files of the printed content but when I wrote it I cheated and just print the Graphics
object to an in memory image and then embed that into the PDF page.
Since the users are emailing the documents they're finding they are too large.
I've started writing the PDF from scratch using iText, however is there a way to get System.Drawing.Graphics
content directly into PDF? The way iText works and Graphics works is completely different.
try this library http://www.pdfsharp.com/PDFsharp/
Edit: Above library has been moved to http://www.pdfsharp.net/
You can direct what your drawing with Graphics to a WMF (EMF) and then hand that to iText.
Do you mean that you have a System.Drawing.Image
? If so you can pass that directly to iTextSharp.text.Image.GetInstance()
which will give you an iTextSharp Image
object. Otherwise you can draw directly to the PDF canvas, see this post for more.
One (hacky) way would be to simply use a PDF printer driver like this one. You can reuse the same GDI+ code through the printing API.
精彩评论