WinPDF.PageImageAtSize
----------------------

Renders a page to an image.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [WinPDF](component_WinPDF.md) | [13.2](newinversion132.md) | ❌ No | ✅ Yes | ❌ No | ✅ Yes, on Windows | ❌ No |

MBS( "WinPDF.PageImageAtSize"; PDFRef; Page; Width; Height { ; ImageType; FileName } ) 

**MBS**( **"WinPDF.PageImageAtSize";** /\* Renders a page to an image. \*/  
**$PDFRef**; /\* The reference number for the PDF document.e.g. $PDF \*/   
**$Page**; /\* The page index.  
Zero based.e.g. 0 \*/   
**$Width**; /\* The page width to use.  
If zero, we calculate it proportionally from the height.e.g. 800 \*/   
**$Height**; /\* The page height to use.  
If zero, we calculate it proportionally from the width.e.g. 600 \*/   
**$ImageType**; /\* Optional; The desired image type.  
JPEG, PNG, BMP, TIFF, GIF or HEIF.  
Default is JPEG.e.g. "JPEG" \*/   
**$FileName**) /\* Optional; The file name to use for the returned image.e.g. "page.jpg" \*/ 

### 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](WinPDFLoadContainer.md)"; 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](WinPDFRelease.md)"; $pdf ) \]   
 Exit Script \[ Text Result: \]   
 End If  
 Set Variable \[ $r ; Value: MBS ( "[WinPDF.Release](WinPDFRelease.md)"; $pdf ) \]   
 End If  
Else If \[ MBS ("IsMacOS") or MBS ("IsIOS") \]   
 Set Variable \[ $preview ; Value: MBS ( "[PDFKit.GetPDFPageImage](PDFKitGetPDFPageImage.md)"; $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](WinPDFLoadContainer.md)"; $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](WinPDFRelease.md)"; pdf)  
\];   
// if no error, return image  
If(e2; ""; image))  
### See also

- [IsError](IsError.md)
- [IsIOS](IsIOS.md)
- [IsMacOS](IsMacOS.md)
- [IsWindows](IsWindows.md)
- [PDFKit.GetPDFPageImage](PDFKitGetPDFPageImage.md)
- [WinPDF.LoadContainer](WinPDFLoadContainer.md)
- [WinPDF.PageImage](WinPDFPageImage.md)
- [WinPDF.Release](WinPDFRelease.md)

### Release notes

- **Version 13.2**
    - Fixed problem in [WinPDF.PageImageAtSize](https://www.mbsplugins.eu/WinPDFPageImageAtSize.shtml) when passing width and height as zero.

### Example Databases

- [Containers/Create Container Preview](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Containers/Create%20Container%20Preview.shtml#1ScriptAnchor_)
- [Win Only/WinPDF](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Win%20Only/WinPDF.shtml#2ScriptAnchor_)

### Blog Entries

- [New in MBS FileMaker Plugin 13.2](https://www.mbsplugins.de/archive/2023-05-17/New_in_MBS_FileMaker_Plugin_13/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 13.2pr4](https://www.mbsplugins.de/archive/2023-04-25/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Windows PDF Functions](https://www.mbsplugins.de/archive/2023-04-11/Windows_PDF_Functions/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

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

  
[WinPDF.PageImage](WinPDFPageImage.md) - [WinPDF.PagePreferredZoom](WinPDFPagePreferredZoom.md)

[HTML Version](WinPDFPageImageAtSize.shtml)