Exporting Widgets
Using Facilio script, you can export any connected app widget as PDF or screenshot with customizable options.
#
Export as PDFnew NameSpace("connectedApp").exportAsPDF(fileName, connectedAppLinkName, widgetLinkName, pdfOptions, context)
- is used to export any connected app widget as PDF.
Params
Param | Description |
---|---|
fileName | File name of the exported pdf to be saved |
connectedAppLinkName | Unique link name of the connected app |
widgetLinkName | Unique link name of the widget to export |
pdfOptions | (Optional) To customize the pdf appearance, refer to PDF options. |
context | (Optional) To pass any data to the widget. It can be accessible via app.getContext() function from inside widget. |
PDF Options
Property | Type | Description | Default |
---|---|---|---|
format | string | (Optional)Letter : 8.5in x 11inLegal : 8.5in x 14inTabloid : 11in x 17inLedger : 17in x 11inA0 : 33.1in x 46.8inA1 : 23.4in x 33.1inA2 : 16.54in x 23.4inA3 : 11.7in x 16.54inA4 : 8.27in x 11.7inA5 : 5.83in x 8.27inA6 : 4.13in x 5.83in | letter |
headerTemplate? | string | (Optional) HTML template for the print header. Should be valid HTML with the following classes used to inject values into them:date - formatted print datetitle - document titleurl - document locationpageNumber - current page number.totalPages - total pages in the document | |
footerTemplate? | string | (Optional) HTML template for the print footer. Should be valid HTML with the following classes used to inject values into them:date - formatted print datetitle - document titleurl - document locationpageNumber - current page number.totalPages - total pages in the document | |
width? | string/number | (Optional) Sets the width of paper. You can pass in a number or a string with a unit. | |
height? | string/number | (Optional) Sets the height of paper. You can pass in a number or a string with a unit. | |
landscape? | boolean | (Optional) Whether to print in landscape orientation. | false |
marginTop | number | (Optional) Set the PDF top margin. | no margins are set. |
marginBottom | number | (Optional) Set the PDF bottom margin. | no margins are set. |
marginLeft | number | (Optional) Set the PDF left margin. | no margins are set. |
marginRight | number | (Optional) Set the PDF right margin. | no margins are set. |
omitBackground? | boolean | (Optional) Hides default white background and allows generating pdfs with transparency. | |
printBackground? | boolean | (Optional) Set to true to print background graphics. | false |
pageRanges? | string | (Optional) Paper ranges to print, e.g. 1-5 , 8 , 11-13 . | The empty string, which means all pages are printed. |
scale? | number | (Optional) Scales the rendering of the web page. Amount must be between 0.1 and 2 . | 1 |
Example
pdfOptions = {};pdfOptions.format = ‘A3’;
context = {};context.data = 123;
fileId = new NameSpace("connectedApp").exportAsPDF("widget.pdf", "connectedapp", "workorder_report", pdfOptions, context);
log fileId;
#
Export as Imagenew NameSpace("connectedApp").exportAsImage(fileName, connectedAppLinkName, widgetLinkName, screenshotOptions, context)
- is used to export any connected app widget as an image.
Params:
Param | Description |
---|---|
fileName | File name of the exported pdf to be saved |
connectedAppLinkName | Unique link name of the connected app |
widgetLinkName | Unique link name of the widget to export |
screenshotOptions | (Optional) To customize the screenshot appearance, refer to Screenshot options. |
context | (Optional) To pass any data to the widget. It can be accessible via app.getContext() function from inside widget. |
Screenshot Options:
Property | Type | Description | Default |
---|---|---|---|
selector? | string | (Optional) If you want to screenshot a particular element, you can pass a selector of the element. | |
format? | string | (Optional) Format of the screenshot.png / jpeg / webp | png |
omitBackground? | boolean | (Optional) Hides default white background and allows generating pdfs with transparency. | |
quality? | number | (Optional) Quality of the image, between 0-100. Not applicable to png images. |
Example
screenshotOptions = {};screenshotOptions.fullPage = true;screenshotOptions.format = "jpeg";
context = {};context.data = 1244;
fileId= new NameSpace("connectedApp").exportAsImage("widget.jpeg", "connectedapp", "qrcode", screenshotOptions, context);
log fileId;