Issue to View PDF file in service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 11:25 AM
Hello experts,
I have a feature to embed a pdf file in the service portal page, but it doesn't work for all pdf files.
I use this script
HTML
<object data="{{data.base64}}"
type="application/pdf" width="100%" height="1000px" class="internal" id="pdfPreview">
<param name="view" value="fitH" />
</object>
server side
var gr = new GlideRecord('sys_attachment');
gr.addQuery('sys_id', attach_ID);
gr.query();
if (gr.next()) {
var sa = new GlideSysAttachment();
var binData = sa.getBytes(gr);
var base64 = GlideStringUtil.base64Encode(binData);
data.base64 = 'data:application/pdf;base64,' + base64 + '#toolbar=0';
}
Is there a problem in my code? Are there any suggestions to work around this problem?
thank you in advance for your help
Cordially
Sanaa
- Labels:
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 01:15 PM
Hello,
Please provide more information as to when it works versus when it doesn't work.
If it works sometimes...then the code must be mostly fine.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2022 03:41 AM
Hello Allen,
thank you for your reply, i faced this issue with file > 2,91 Mo.
I can't upload pdf in the portal but it works fine outside the portal.
I can download pdf and view it.
did you have any suggestion to resolve this issue.
Thank you.
Sanaa

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2022 06:59 PM
You might be encountering one of these two issues:
1. The PDFs that don't work are larger in size, check
The default maximum size limit for an attachment file that can be added to a record in the ServiceNow platform is 1024 MB for a new out-of-box instance. This limit can be adjusted by following this procedure:
- Login to the instance with an account having admin rights to the instance.
- Using the Menu Navigator, browse to the following location on the instance: System Properties -> Security.
- Locate the property on the page with the heading "Maximum file attachment size in megabytes". Below this heading is a field in which the specified value can be typed to specify the number in MB of the maximum allowable attachment size.
- Change the value ( you need to be in the Global scope) and test again
2. The PDFs that don't work have been created in a specific tool
Even though PDF is supposed to be a Portable format, some PDFs require a specific tool to view them. One example is PDF created in Adobe LiveCycle Designer.
https://www.adobe.com/go/lc_xfa
If you can view the PDF outside of ServiceNow it will work inside ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2022 03:46 AM
Hello Marc,
thank you for your reply,
even I change the size it doesn't work.
I can download pdf and view it outside the portal, but if i try inside the portal it doesn't work.
did you have any suggestion to resolve this issue.
Thank you.
Sanaa