We are looking into the rasterization of a PDF file into another PDF file with the following expectations:
· Processing time must still be be acceptable in reference to “PDF to PDF/A” in-memory and file operations, realizing that the pay-off of better security is achieved through rasterization.
· Processing must occur in-memory as much as possible to eliminate performance issues and other risks in utilizing disk storage.
· Code-wise the conversion must be efficient and straightforward without unnecessary manipulation of source and target page content.
Essentially our use case is to have PDFNet convert and existing PDF document into a new rasterized PDF document. In other words, we just want to convert each page of a PDF document into an image and get those images into a new PDF. Pretty much like what you have for PDF to PDF/A conversion.
using (PDFDoc doc = new PDFDoc(inpdf))
using (PDFDoc newdoc = new PDFDoc())
using (PDFDraw draw = new PDFDraw())
using (ElementBuilder builder = new ElementBuilder())
using (ElementWriter writer = new ElementWriter())
using (ObjSet objset = new ObjSet())
Obj encoder_hint = objset.CreateArray();
encoder_hint.PushBackNumber(9); // Set max compression vs speed.
for (PageIterator itr = doc.GetPageIterator(); itr.HasNext(); itr.Next())
System.Drawing.Bitmap bmp = draw.GetBitmap(itr.Current());
Image image = Image.Create(doc, bmp, encoder_hint);
Page page = doc.PageCreate(itr.Current().GetCropBox());
writer.WritePlacedElement(builder.CreateImage(image, 0, 0, page.GetPageWidth(), page.GetPageHeight()));
catch (PDFNetException e)
The relevant utility function and a drop-in replacement for AddImage C# sample project is attached.
The function has a parameter DPI that you can control quality. If you prefer to use JPEG rather than flate you can comment-out encoder_hint.
Please note that there are still some distinct advantages in using PDF/A Converter (pdftron.PDF.PDFA.PDFComplaince):
It is faster
Output PDF is high quality ( you have vector graphics)
Output PDF size is usually much smaller (unless you rasterize at really low-rez)
Output PDF is searchable
You maintain metadata.