Convert HTML to PDF Custom Button

Introduction

In FieldFX, you can add the ability to convert a HTML file to PDF on request in Back Office. The HTML file will be converted to PDF on save (or on sync if created in Mobile).

You can define the PDF file name when the report is converted and also define which SObject(s) to perform the conversion. The conversion can be on a job and ticket, but not on a quote.

FieldFX sends out an error e-mail if the conversion is not successfully.

You can trigger the conversion manually, if the automation fails. You can save the generated PDF documents under Files.

You also can delete the original HTML file get deleted once the equivalent PDF is created.

You must upgrade your FieldFX Managed Package to v1.509 and FieldFX Lightning Managed Package to v1.209 before you add the button.

Step-by-Step Guides

These step by step guides detail the setup and use of the Convert HTML to PDF button.

These steps detail how to setup the button for a Job. To use the button on Tickets and Quotes, you must repeat the setup steps for the Ticket and Quote object.
Setup Tasks Use Tasks

The task steps are the same except for the object used.

Setup the HTML to PDF button

Repeat these steps to add the same button to a ticket or a quote.

Create Action Button in FX Back Office

  1. Log into FieldFX Back Office.

  2. From Setup, enter object in the Quick Find box.

  3. Select Object Manager and then

    For a Job: For a Quote: For a Ticket:

    Select the Job object.

    Select the Quote object.

    Select the Ticket object.

  4. Select Buttons, Links, and Actions from the menu.

  5. Click New Action.

    This action must be added to the Job, Quote, and Ticket objects.
  6. At the New Action screen, complete the following:

    Field Action

    Action Type

    Select Lightning Web Components.

    Lightning Web Component

    Select FX5:convertHTMLToPDF.

    Standard Label Type

    Leave at --None--.

    Label

    Enter HTML to PDF

    Name

    When you click on this field, it’s automatically populated by what you entered in the Label field. The spaces are replaced with underscores.

    Description
    (Optional)

    You can enter a short description of the button’s description.

  7. Click Save.

  8. Continue with Add to Page Layout section.

Add to Page Layouts

  1. While still in the Job, Quote, or Ticket object, select Page Layouts.

  2. Select the object:

    • For a Job: Job Layout.

    • For a Quote: Quote

    • For a Ticket: Ticket

  3. Click Mobile & Lightning Actions.

  4. Find the new HTML to PDF action that you created.

  5. Drag HTML to PDF and drop it into the Salesforce Mobile and Lightning Experience Actions block under Job Detail.

    If you don’t see the list of actions but see this message, this section is predefined by Salesforce.

    Actions predefined by Salesforce

    Click the …override the predefined actions… link to expose those actions and add the custom action.

    • Only three buttons appear on the Job record. You can access the HTML to PDF button by selecting the down arrow and scrolling down the menu to HTML to PDF

    • If you want the new button to appear on the Job Record, drag the button to the first position in the Salesforce Mobile and Lightning Experience Actions block on the Job page layout

  6. To save the changes, click Save.
    The layout is saved and the list of page layouts reappears.

  7. Continue with Add the URL to Remote Settings.

Add the URL to Remote Settings

For more information, see Add Remote Site Settings for Lightning Components.

If you have already added the Remote Site URL for another object, you won’t have to add it again. It already exists in your org.
  1. While still in Setup, use the Quick Find box and type remote.

  2. Select Remote Site Settings.

  3. Click New Remote Site.

  4. At the Remote Site Edit, complete the following:

    Field Action Remote Site

    Name

    Enter the name for the site, such as Convert_HTML_to_PDF.

    The Remote Site Setting API Name can only contain underscores and alphanumeric characters. The name must:

    • Begin with a letter

    • Not include spaces

    • Not end with an underscore

    • Not contain 2 consecutive underscores

    Remote Site URL

    Enter the custom URL.

    See Add Remote Site Settings for Lightning Components on how to add a remote site custom URL.

    Disable Protocol
    Security checkbox

    Select this checkbox to allow s-controls to access this remote site regardless of HTTP or HTTPS session security. Only select this checkbox if you understand the security implications.

    Description
    (Optional)

    You can enter a brief description for the URL.

    Active checkbox

    Leave selected.

  5. Click Save.

  6. Continue with Add New AppSetting Fields section.

Add New AppSetting Fields

With the button defined and on the page layout, you need to set up these AppSettings:

These AppSettings have been added as part of FieldFX Managed Package v1.509 and should exist in your org upon upgrade.

Required
AppSettings:

  • Automatically Convert to PDF - Sets up the automatic converts an HTML to a PDF

  • Failure Notification Email - Sends a notification email if the conversion fails

  • Delete HTML Original - Deletes the original HTML once the PDF is created

  1. From Setup, enter Custom Metadata in the Quick Find box.

  2. Select Custom Metadata Types.

  3. In the AppSetting row, click Manage Records.

  4. In the AppSettings window, click New.

  5. Complete these AppSettings:

    Field Convert to PDF Failure Notification Email Delete HTML Original

    Label
    (Required)

    Automatically Convert to PDF

    FailureNotificationEmail

    Delete HTML Original

    App Setting Name
    (Required)

    AutoConverttoPDF

    FailureNotificationEmail

    DeleteHTMLOriginal

    Protect Component checkbox

    Leave unchecked.

    Active checkbox

    Leave unchecked.

    Value
    (Required)

    Set to false.

  6. Click Save & New.

Use Convert HTML to PDF

With the Convert HTML to PDF button available, you can convert HTML files to a PDF and attach it to a job, ticket, or quote.

  1. In your org, click:

    Use this tab…​ For …​

    Jobs

    Jobs

    Quote

    Quote

    Ticket

    Ticket

  2. Select a listed job, quote, or ticket.

  3. Click HTML to PDF.

  4. At the HTMLToPDF modal,

    1. If you want to delete the original HTML file, click the Delete Original toggle off.

    2. By default, the HTML file is also saved with the PDF file.

    3. Click Convert HTML Reports. If successful, Success appears at the bottom of the modal.

  5. Close the HTML to PDF modal.

  6. Refresh the page.
    The PDF also appears in the Notes & Attachments block on the Related tab.