Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

DynaPDF Manual - Page 568

Previous Page 567   Index   Next Page 569

Function Reference
Page 568 of 750
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;
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);
 

Previous topic: Raw image output

Next topic: RenderPage (Rendering Engine)