PDF tools
Jetveo offers a built-in tool for manipulating PDF documents. Accessible at App.Tools.Pdf.
Generating PDF documents
The primary purpose of this tool is generating a pdf document from an html string. The html string is typically generated from a template. The tool provides a method App.Tools.Pdf.GenerateFromHtml() That takes in 8 arguments:
string documentHtmlThe html string, the pdf document is generated from.
Optional Arguments
headerHtmlAn html string, that will define the header.footerHtmlAn html string, that will define the footer.paperSizeAn enum, that contains a few known paper sizes. (Default A4)scaleA floating-point number, that sets the scaling (Default 1.0)marginsAn enum, which lets you choose margins fromLarge,Normal,None.headerExtraMarginA floating-point margin size (Note: The value is in inches)footerExtraMargin...orientationAn enum, that sets the page orientation toPortraitorLandscape. (Default Portrait)
The method returns a byte array, containing the pdf file content. To add the generated document as a revision,
use x.AddRevision(fileName, generatedPdfContent), where
xis the desired document to update.fileNameis a string, with the desired file name.generatedPdfContentis the byte array returned fromGenerateFromHtml()
Here is a simple usage example
public void GenerateAgreementPdf(Customer customer)
{
var html_string = App.Templates.AgreementTemplate.Render(customer);
var pdf_content = App.Tools.Pdf.GenerateFromHtml(html_string);
string file_name = $"agreement_{customer.Name}.pdf";
customer.Agreement.AddRevision(file_name, pdf_content);
}
Converting Office documents to PDF
The tool can also convert Word documents, Excel spreadsheets and PowerPoint presentations to PDF:
App.Tools.Pdf.GenerateFromWord()for Word documents (docx, docm, doc, odt, rtf)App.Tools.Pdf.GenerateFromExcel()for Excel spreadsheets (xlsx, xlsm, xls, ods)App.Tools.Pdf.GenerateFromPowerPoint()for PowerPoint presentations (pptx, pptm, ppt, odp)
Each method takes the source document as a byte array and returns a byte array containing the pdf file content. The source document format can be provided in two ways:
- A file name — the format is detected from the file name extension. The extension is matched case-insensitively and an unsupported extension throws an exception.
- A format enum —
WordFormat,ExcelFormatorPowerPointFormatto state the format explicitly. When omitted, the modern Office format (Docx,Xlsx,Pptx) is assumed.
The maximum size of the source document is 100 MB.
Here is a simple usage example
public void ConvertContractToPdf(Contract contract)
{
var revision = contract.Document.GetLatestRevision();
// The format is detected from the file name extension
var pdf_content = App.Tools.Pdf.GenerateFromWord(revision.Content, revision.FileName);
// Or state the format explicitly
// var pdf_content = App.Tools.Pdf.GenerateFromWord(word_content, PdfTool.WordFormat.Docx);
contract.ContractPdf.AddRevision("contract.pdf", pdf_content);
}