Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

WinPDF.PageImageAtSize

Renders a page to an image.

Component Version macOS Windows Linux Server iOS SDK
WinPDF 13.2 ❌ No ✅ Yes ❌ No ✅ Yes, on Windows ❌ No
MBS( "WinPDF.PageImageAtSize"; PDFRef; Page; Width; Height { ; ImageType; FileName } )   More

Parameters

Parameter Description Example Flags
PDFRef The reference number for the PDF document. $PDF
Page The page index.
Zero based.
0
Width The page width to use.
If zero, we calculate it proportionally from the height.
800
Height The page height to use.
If zero, we calculate it proportionally from the width.
600
ImageType The desired image type.
JPEG, PNG, BMP, TIFF, GIF or HEIF.
Default is JPEG.
"JPEG" Optional
FileName The file name to use for the returned image. "page.jpg" Optional

Result

Returns container value or error.

Description

Renders a page to an image.
Outputs a stream of data, which represents a Portable Document Format (PDF) page's contents as image.
Takes a set of display settings, applies them to the output of a Portable Document Format (PDF) page's contents, and creates a stream with the customized, rendered output as an synchronous action. This asynchronous action can be used to create a customized display image of the Portable Document Format (PDF) page.

The given width and height is a requested size for the PDF engine in Windows, which may to pick its own size.

Examples

Make preview of page:

If [ MBS("IsWindows") ]
    Set Variable [ $pdf ; Value: MBS( "WinPDF.LoadContainer"; Get Preview::Input) ]
    If [ MBS("IsError") = 0 ]
        Set Variable [ $NewImage ; Value: MBS( "WinPDF.PageImageAtSize"; $pdf; 0; 0; 600; "JPEG"; "page.jpg") ]
        If [ MBS("IsError") = 0 ]
            Set Field [ Get Preview::Preview ; $NewImage ]
            Set Field [ Get Preview::Made using ; "WinPDF" ]
            Set Variable [ $r ; Value: MBS( "WinPDF.Release"; $pdf) ]
            Exit Script [ Text Result: ]
        End If
        Set Variable [ $r ; Value: MBS( "WinPDF.Release"; $pdf) ]
    End If
Else If [ MBS("IsMacOS") or MBS("IsIOS") ]
    Set Variable [ $preview ; Value: MBS( "PDFKit.GetPDFPageImage"; $Input; 0; "JPEG"; "input.jpg"; 72) ]
    If [ MBS("IsError") = 0 ]
        Set Field [ Get Preview::Preview ; $preview ]
        Set Field [ Get Preview::Made using ; "PDFKit" ]
        Exit Script [ Text Result: ]
    End If
End If

Render preview in one Let statement:

Let([
// open from container value in variable
pdf = MBS( "WinPDF.LoadContainer"; $Container );
e1 = MBS("isError");
page = 0;
// render preview
image = If(e1; ""; MBS( "WinPDF.PageImageAtSize"; pdf; page; 0; 600; "JPEG"; "preview.jpg"));
e2 = MBS("isError");
// free resources
r = MBS( "WinPDF.Release"; pdf)
];
// if no error, return image
If(e2; ""; image))

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 8th March 2023, last changed 16th April 2023


WinPDF.PageImage - WinPDF.PagePreferredZoom