Skip to main content

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 documentHtml The html string, the pdf document is generated from.

Optional Arguments

  • headerHtml An html string, that will define the header.
  • footerHtml An html string, that will define the footer.
  • paperSize An enum, that contains a few known paper sizes. (Default A4)
  • scale A floating-point number, that sets the scaling (Default 1.0)
  • margins An enum, which lets you choose margins from Large, Normal, None.
  • headerExtraMargin A floating-point margin size (Note: The value is in inches)
  • footerExtraMargin ...
  • orientation An enum, that sets the page orientation to Portrait or Landscape. (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

  • x is the desired document to update.
  • fileName is a string, with the desired file name.
  • generatedPdfContent is the byte array returned from GenerateFromHtml()

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 enumWordFormat, ExcelFormat or PowerPointFormat to 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);
}