PDF document preview

Certified Associate Developer

I have a use case that needs to display a PDF or doc type document in a “FIT”/preview format. I thought the documentImage would work however it only works up to “LARGE” and not “FIT”. Is this a problem for anyone else and has anyone found a way to display a PDF?

ENV:18.1

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Hi Samuel,

    We had exactly the same issue that you are facing currently and we came up with a workaround for this which works perfectly as we wanted it to. May be this can help you as well.

    Pre-requisite:

    Latest version of Appian is required (it is 18.1 when this reply was posted)

    The browser used is "Google Chrome" with the below extension installed

    Extension name: PDF JS PDF Viewer (v 2.0.466 or higher)

    Source: Chrome Web Store 

    License: Free

     

    Here's how you do it:

    1. Create a webAPI component that takes the appian documentID as a parameter and returns a response in the below format:

    (In version18.1 you can use the 'Document Download' template to automatically generate this code)

    Headers

    Content-Type: application/pdf

    Content-Disposition: inline; filename="<fileName>.pdf"

    Body

    The document itself (todocument(<documentID>))

    (Exception handling is not specified here. But must be in place.)

    2. Now your webAPI will have a URL that would look something like this: <siteURL>/suite/webapi/document/12345         (12345 will be your appian documentID)

    If the pre-requisite mentioned above is in place then you will already see the PDF displayed in your browser on entering the above URL with an existing documentID. This will be your first test to see if this approach would suit your needs.

    3. In your SAIL interface you can now use the a!webContentField and pass this URL for the source parameter. Use the height to get the desired preview size.

  • Hi Sunil ,

    I have followed above approach , when the hit the web- Api in the browser it shows an error of PDF not able to download.
    I have doubt on the toDocument function , how that function will understand that the Id which I am passing Id a document Id in the KC , as when i check the definition of toDocument function , it will return you a document , it did not care about the what is the parameter is ..

     

    Let me know if i am missing anything .

     

    Regards

     

    Manish

  • 0
    Certified Lead Developer
    in reply to manishk0001
    Hi Manish,

    The toDocument function takes a documentID as parameter and returns the appian document object. The documentID's are unique for every document created in your appian environment irrespective of the KC.

    How did you create your webapi? What exactly does your webapi return as response?
Reply Children