Pdf2 Class Reference

Configuration Pdf2.init() Pdf2.setFilename(filename) Pdf2.setFooter(text) Pdf2.setHeader() Pdf2.setWatermark(text, color) Pdf2.addStyle(selector, css) Generate Text Pdf2.add(html) Pdf2.addHeader(title) Pdf2.addTitle(title) Pdf2.addText(text) Table Generation Pdf2.startTable(headers, styles, className) Pdf2.startTitleBlock(title) Pdf2.addRow(labels, style) Pdf2.stopTable()
Image and Signature Pdf2.addImage(fileid, height) Pdf2.addSignature(label, base64) Pdf2.addFloorPlan() Other Pdf2.addPageBreak() Pdf2.formatAddress(contact, company) Actions Pdf2.download() Pdf2.email(emails) Pdf2.archiveEmail(email, subject, body)

How to use

The call to Pdf2.download() or Pdf2.email() requires a working Internet Connection.
Simplest Example
Pdf2.init();
Pdf2.setFilename("sample1.pdf");
Pdf2.add("<h1>Hello World</h1>")
Pdf2.download();
Adding Header and Footer
Pdf2.init();
Pdf2.setFilename("sample1.pdf");
Pdf2.setHeader(); // it adds the predefined company log and address from the Upvise account
Pdf2.setFooter("This is a footer note\nIt can span 2 lines");
Pdf2.add("<h1>Hello World</h1>")
Pdf2.download();
Adding a Table
Pdf2.init();
Pdf2.setFilename("sample1.pdf");
Pdf2.startTable(["Column 1", "Column 1", "Column 1"], []);
Pdf2.addRow(["Mercury", "Venus", "Earth"]);
Pdf2.addRow(["Mars", "Jupiter", "Saturn"]);
Pdf2.stopTable();
Pdf2.download();
Adding CSS Style to a Table
Pdf2.init();
Pdf2.setFilename("sample1.pdf");
Pdf2.addStyle("TABLE.mytable", "width:100%;border:1px solid gray;");
Pdf2.addStyle("TABLE.mytable THEAD TD", "background-color:blue;color:white;");
Pdf2.addStyle("TABLE.mytable TD", "padding:1em;border:1px solid gray;");
Pdf2.startTable(["Column 1", "Column 1", "Column 1"], [null, "width:200px", "width:150px"], "mytable");
Pdf2.addRow(["Mercury", "Venus", "Earth"]);
Pdf2.addRow(["Mars", "Jupiter", "Saturn"]);
Pdf2.stopTable();
Pdf2.download();

Configuration

Pdf2.init()

Inits the PDF document. To be called at the beginning of the generation of the document.

Pdf2.setFilename (filename)

Set the short filename for the pdf file. This method MUST alwasy be called before Pdf.email() or Pdf.download()

Pdf2.setFilename("My Report.pdf");

Pdf2.setHeader()

Adds the company logo and address, as defined in the Forms or Sales web app options.

Pdf2.setFooter(text)

Defines the text footer to be added at the bottom of each PDF page

Pdf2.setFooter("My Footer first line\nMy Footer second line");

Pdf2.setWatermark(text, color)

Specify the watermark text background for the PDF. text (string) is the text of the watermark (rendered as a 45 degree Arial font 70px) in the middle of each page, color (string) is optional and defines the text color.

Pdf2.setWatermark("Draft", "#FF0000");

Pdf2.addStyle(selector, css)

Adds a new CSS rule. selector is a string indicating the HTML element to match and css is the CSS definition

Pdf2.init();
Pdf2.addStyle("H1", "margin:2em;font-weight:bold;text-transform:uppercase;")
Pdf2.addStyle("TABLE.test TR TD", "border:1px solid black;vertical-align:top;");

Generate Text

Pdf2.add(html)

Adds any HTML string to the PDF output

Pdf.add("<table class=mytable><tr><td colspan=3><h1>My Title</h1></td></tr><tr><td>Column 1</td><td>Column 2</td><td>Column 3</td></tr></table>");

Pdf2.addTitle(title)

Add a title (string) to the Pdf document, similar to H1 html tag

Pdf2.addTitle("Job Report")

Pdf2.addHeader(header)

Adds a section header separator

Pdf2.addText(label, text)

Generate Table

Pdf2.startTable(headers, styles, className)

Starts a new table. headers is an optional array of table headers, styles is an optional array of CSS declration foreach header, className is an optional CSS classname for the table.

Use Pdf2.addRow() to add row and Pdf2.stopTable() to terminate the table
Pdf2.startTable(["Column1", "Column2", "Column3"], ["", "width:150px", "width:200px"]);

Pdf2.startTitleBlock(title)

Starts a new table with title as the header. Each row must have 4 columns. Use this as a title block on top on your PDF document. Use Pdf2.addRow(["label1", "value2", "label2", "value2"]) to add label / value pair to the block, followed by PDf2.stopTable();

Pdf2.startTitleBlock("My Document title");
Pdf2.addRow(["Date", "12/03/2015", "Created By", "John Stone"]);
Pdf2.addRow(["Site", " Changi Airport", "Level", "2"]);
Pdf2.stopTable();

Pdf2.addRow(labels, style)

Adds a new table row. labels is an array of string for the columns. style is an optional inline CSS declaration to apply on each row

Pdf2.startTable();
Pdf2.addRow(["Mercury", "Venus", "Earth"]);
Pdf2.addRow(["red", "green", "blue"]);
Pdf2.stopTable();

Pdf2.stopTable()

Stops a table

Adding Images & Signature

Pdf2.addImage(fileid, height)

Adds an images. fileidis the file id coming from system.files table, height is an optional height for the image.

Pdf2.addSignature(label, base64)

Adds a signature image. label is a string label and signature is a Base64 encoded string representing the signature.

Pdf2.addFloorplan()

Adds the current floorplan currently displayed in the page to the pdf along with all markers.

Other

Pdf2.formatAddress(contact, company)

returns a array of string containing the formatted address for the contact and company record. contact and company must come from a previous query on the "Contacts.contacts" and "Contacts.companies" table

Pdf2.addPageBreak()

Adds a page break

Download & Email

Pdf2.download()

Download the PDF. This must be the last function call.

Pdf2.email(emails)

Email the pdf as an attached file. emails is an optional string contaiing the recipients list. This will start the native email client on mobile. This must be the last function call.

Pdf2.email('kphm@gmail.com;mark@gmail.com')

Pdf2.archiveEmail(email, subject, body)

Generate the PDF and send it as an attached file from the cloud server to the email string address. subject and body are optional strings. If present the subject and body of the email are set to these strings. If not, the defaut subject is: "Archive: [UserName] [FileName]" and the body is empty.

Pdf2.archiveEmail('admin@mydomain.com','My subject','Body of email')
This method works even if the device is offline