Open PDFs from the Salesforce Database
PSPDFKit for Salesforce enables you to open files from your local machine, Salesforce, or an external URL.
You can open the following file types:
-
JPG
-
PDF
-
PNG
-
TIF/TIFF
Open a file in Salesforce in one of the following ways:
-
Using the built-in user interface (UI), you can open files from your local machine or Salesforce.
-
Programmatically, you can open files from Salesforce or an external URL.
For more information on uploading documents to Salesforce, see the Salesforce documentation.
Opening Files Using the Built-In UI
You can open files using the built-in UI in one of the following ways:
Opening a File from a Document Record Page
To add the PSPDFKit button to document record pages, follow the steps outlined below. You only need to do this once.
-
In Salesforce, go to Files.
-
To the right of one of the files in the list, click the down chevron, and click View File Details.
-
In the top-right corner, click Setup > Edit Page.
-
In the list of components on the left, find pspdfkitEditButtonSolution, and drag it to the appropriate place on the page.
-
Optional: Select the color of the button and determine whether it opens in a new tab.
-
Click Save.
To open a file from a document record page, follow these steps:
-
In Salesforce, go to Files.
-
To the right of one of the files in the list, click the down chevron, and click View File Details.
-
Click Edit File with PSPDFKit.
Opening a File from an Account Page
To add the PSPDFKit button to account pages, follow the steps outlined below. You only need to do this once.
-
In Salesforce, go to Objects and Fields > Object Manager.
-
Click Account.
-
In the left navigation panel, click Page Layouts.
-
In the list, click Account Layout.
-
Click Mobile & Lightning Actions.
-
Drag Edit files with PSPDFKit to the Salesforce Mobile and Lightning Experience Actions area.
-
Click Save.
To open a file from an account page, follow these steps:
-
In Salesforce, go to Accounts.
-
Click one of the accounts in the list.
-
Click Edit Files with PSPDFKit.
-
Find the file in the list and click Edit with PSPDFKit.
Opening a File Using the PSPDFKit File Selector
Using the PSPDFKit file selector, you can open files from your local machine or Salesforce.
To open a file using the PSPDFKit file selector, follow these steps:
-
Ensure you’re logged in as a user authorized to use PSPDFKit.
-
In the top-right corner, open the App Launcher.
-
Search for and select PSPDFKit.
-
Click browse to upload local PDF files, or open a file from Salesforce.
Opening Files Programmatically
Programmatically, you can open files in one of the following ways:
Opening Files Programmatically from Salesforce
Before continuing, perform all of the following actions:
-
If you’ve deployed PSPDFKit for Salesforce to an existing project, ensure that you added the file selector to your project.
-
Ensure you’re logged in to Salesforce as a user authorized to use PSPDFKit.
To open files from Salesforce programmatically, follow these steps.
-
In Salesforce, click the Files tab.
-
Right-click the file in the list, and click Copy Link Address.
-
The URL in the copied text is similar to
https://YOUR_SALESFORCE_ORG.lightning.force.com/lightning/r/ContentDocument/DOCUMENT_ID/view
. Use theDOCUMENT_ID
part of the URL. -
In your text editor, open the
PSPDFKit_InitPSPDFKit.page
Visualforce page within theforce-app/main/default/pages
folder, and then paste the following within thescript
tag. ReplaceDOCUMENT_ID
with the document ID:
<script type="text/javascript"> ... openSalesforceFile(DOCUMENT_ID) </script>
-
Run the following command in the terminal to start the Salesforce authentication process:
sfdx force:auth:web:login --setalias mySalesforceOrg --instanceurl https://login.salesforce.com --setdefaultusername
-
In the browser window that opens, log in to your Salesforce organization and authorize the Salesforce CLI.
-
In the terminal, run the following command from the PSPDFKit for Salesforce project’s root folder:
sfdx force:source:deploy -x manifest/package.xml
As a result, the selected document automatically opens when the PSPDFKit file selector page loads.
Opening Files Programmatically from an External URL
To open files from an external URL programmatically, follow these steps.
-
Check the
Access-Control-Allow-Origin
response header from the server that serves the file, and ensure that Salesforce is allowed to load the file. -
In your text editor, paste the following to the Visualforce page where you want the file to open. Replace
https://example.com/source.pdf
with the URL of the file you want to open:
<script type="text/javascript"> PSPDFKit.load({ baseUrl: `${window.location.protocol}//${window.location.host}{!$Resource.PSPDFKit_lib}/`, container: "#pspdfkit", document: "https://example.com/source.pdf", disableWebAssemblyStreaming: true, }) </script>
-
Run the following command in the terminal to start the Salesforce authentication process:
sfdx force:auth:web:login --setalias mySalesforceOrg --instanceurl https://login.salesforce.com --setdefaultusername
-
In the browser window that opens, log in to your Salesforce organization and authorize the Salesforce CLI.
-
In the terminal, run the following command from the PSPDFKit for Salesforce project’s root folder:
sfdx force:source:deploy -x manifest/package.xml