Skip to content

AddPDF

Adds a new PDF file to the repository with HTML content and returns the created FileInfo.

1
myFiles.AddPDF(html: string, name: string, options?: PDFOptions):FileInfo

Parameters

string html
    The content of the file in HTML format.

string name
    The name of the file.

PDFOptions options optional
    Optional PDF conversion options.

Returns

The created FileInfo.

Remarks

HTML-to-PDF conversion runs synchronously in the script execution. Invalid conversion options or conversion failures raise a script error; the file is added only after conversion succeeds.

The headerHtml and footerHtml parameters specify the content for a single page and may contain the following parameters:

  • [page]: The current page number.
  • [frompage]: The first page number.
  • [topage]: The total number of pages.
  • [customField]: Other custom properties specified in the options.

Define reusable header HTML for PDF conversion

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<table style="border-bottom: 1px solid black; width: 100%;">
  <tr>
    <td style="width:20%;text-align:center;">[logo]</td>
    <td style="width:50%;text-align:center;font-size:1.3em;">[documentTitle]</td>
    <td style="width:30%">
      Document Number : [documentNumber]<br />
      Page : [page]/[topage]
    </td>
  </tr>
</table>

Convert HTML into a PDF file

1
2
3
var html = '<html><body>Hello!</body></html>';
var pdfFile = $Files.AddPDF(html, 'sample.pdf');
return pdfFile.Id;

See Also