Issue to View PDF file in service portal

Sanaa
Kilo Contributor

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

8 REPLIES 8

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Sanaa,

If it's working for some file, it may be a problem with the file size. Check the following question. Increasing system property "com.glide.attachment.max_get_size" is not recommended because it may decrease performance of an instance.

https://community.servicenow.com/community?id=community_question&sys_id=a4321f21db101fc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=765c64771bf88418ada243f6fe4b...

Hello Marc,

thank you for your reply,

I tried your suggestion but it still not working.

 

did you have any suggestion to resolve this issue.

Thank you.

Sanaa

Marc Mouries
ServiceNow Employee
ServiceNow Employee

have you tried to open these pdf in a web page outside of ServiceNow? Do they all work?

yes, I have, they work fine