Xojo Conferences

DynaPDF Manual - Page 584

Previous Page 583   Index   Next Page 585

Function Reference
Page 584 of 770
Note that the return value of the function must be zero, otherwise no image will be returned. See
Return values at the end of the function description.
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;
pdfImportPageEx(PDF, PageNum);
memset(&img, 0, sizeof(img));
img.StructSize = sizeof(img);
= psFitBest;
= TRasterFlags(rfInitBlack | rfExclFormFields | rfExclAnnotations);
= true;
= 1.0;
= 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);
pdfEditPage(PDF, 1);
SI32 i, count = pdfGetPageAnnotCount(PDF);
out.StructSize = sizeof(out);
for (i = 0; i < count; i++)
pdfGetPageAnnotEx(PDF, i, annot);

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

Next topic: RenderPage (Rendering Engine)