DynaPDF Manual - Page 641

Previous Page 640   Index   Next Page 642

Function Reference
Page 641 of 839
How to create image files
It is also possible to create image files from rendered annotations or fields. To achieve this, create a
new image with CreateImage() beforehand and call RenderAnnotOrField() afterwards. The
rendered image is passed to AddRasImage() internally. If the output format is TIFF, more than one
image can be added to the output image. The parameter Filter is only used if CreateImage() was
called beforehand. The output image must finally be closed with CloseImage(). If the image was
created in memory call GetImageBuffer() as usual.
Example (C++):
void RenderPDFPage(const PPDF* PDF, const char* InFile, UI32 PageNum, const char* OutDir)
{
UI32 w, h;
TPDFBitmap out;
char path[MAX_PATH]; TPDFRasterImage img; TPDFAnnotationEx annot;
// We do not create a PDF file in this example
pdfCreateNewPDF(PDF, NULL);
pdfSetImportFlags(PDF, ifImportAll | ifImportAsPage);
pdfSetImportFlags2(PDF, if2UseProxy);
if ((retval = pdfOpenImportFile(PDF, InFile, ptOpen, NULL)) < 0) return retval;
pdfAppend(PDF);
pdfImportPageEx(PDF, PageNum);
pdfEndPage(PDF);
memset(&img, 0, sizeof(img));
img.StructSize = sizeof(img);
img.DefScale
= psFitBest;
img.Flags
= TRasterFlags(rfInitBlack | rfExclFormFields | rfExclAnnotations);
img.InitWhite
= true;
img.Matrix.a
= 1.0;
img.Matrix.d
= 1.0;
IPGE* page = pdfGetPageObject(PDF, 1);
rasCalcPagePixelSize(page, psFitBest, 1.0, 2500, 2500, rfDefault, &w, &h);
BYTE* buffer = (BYTE*)malloc(w * 4 * h);
IRAS* ras = rasCreateRasterizer(PDF, NULL, buffer, w, h, w * 4, pxfRGBA);
pdfRenderPage(PDF, page, ras, &img);
sprintf(path, "%s/page.png", OutDir);
pdfCreateImage(PDF, path, ifmPNG);
pdfAddRasImage(PDF, ras, cfFlate);
pdfCloseImage(PDF);
rasDeleteRasterizer(&ras);
free(buffer);
pdfEditPage(PDF, 1);
SI32 i, count = pdfGetPageAnnotCount(PDF);
out.StructSize = sizeof(out);
for (i = 0; i < count; i++)
{
pdfGetPageAnnotEx(PDF, i, annot);
sprintf(path, "%s/annot_%2d.png", OutDir, i);
// We store the result as PNG image in this example
 

Previous topic: The Button State (parameter State), Raw image output

Next topic: RenderPage (Rendering Engine)