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
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
Thanks Sunil for your quick response . I tried some thing like below in webApi: local!document: What I am passing as document ID passing as the parameter. like you explain i have two component the HttpResponse and the Body local!document: http!request.queryParameters.document, a!httpResponse( headers: { a!httpHeader( name:"Content-Type", value:"application/pdf" ), a!httpHeader( name: "Content-Disposition", value: "inline;filename=Data.pdf" ) }, body: { todocument(local!document) } )
I guess I am doing some basic mistake .let me know what is wrong .
Cheers
Hi Manish,
I think this is causing the issue:
body: {
todocument(local!document)
}
Please remove the braces in the body element.
should be
body: todocument(local!document)
Please try this and let me know if it works.
Regards,
Sunil Zacharia