- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 03:25 AM
I need to embed a PDF file for the user to view inside the page in service portal. I have tried the following, and nothing works.
The iframe downloads the atttachment instead of showing it.
<iframe id="inline_document" scrolling="no" style="width:100%;height:900px;border:none" src="sys_attachment.do?view=true&sys_id=bc039edadbe923008fa34410ba9619b3">
</iframe>
The embed gives error saying it can't load the document.
<embed height="200px" src="/sys_attachment.do?sysparm_referring_url=tear_off&view=true&sys_id=bc039edadbe923008fa34410ba9619b3" type="application/pdf" width="200px"/>
The object gives error saying it can't load the document.
<object data="https://elodev.service-now.com/sys_attachment.do?sysparm_referring_url=tear_off&view=true&sys_id=bc039edadbe923008fa34410ba9619b3" type="application/pdf" width="100%" height="50%">
<p>Alternative text - include a link <a href="myfile.pdf">to the PDF!</a></p>
</object>
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 02:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2020 03:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2020 12:33 AM
Good Morning,
Hope you're doing well,
On line 3 in your html code you have a ':' after /pdf, this should be a ';'
Currently:
data="data:application/pdf:base64,{{data.base64}}"
Replace with:
data="data:application/pdf;base64,{{data.base64}}"
Take a look at my second post as well with the new code, you should be able to simplify your code a lot more after you get it working.
Hope this helps,
Kind Regards
Ashley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 10:05 AM
I have the exact same requirement to achieve and used same client and server code as above, there is no error but PDF is not shown on the widget on portal. What is missing here ?
2 Widgets are part of portal page. Page renders 1 other widget but not this widget meant for pdf embed
Server code of widget
(function() { var attach = '99e44c6797bb7910d8a97c9fe153af44'; // sys id of record that has the pdf attachment var gr = new GlideRecord('sys_attachment'); gr.addQuery('sys_id', attach); gr.query(); if(gr.next()) { var sa = new GlideSysAttachment(); var binData = sa.getBytes(gr); var base64 = GlideStringUtil.base64Encode(binData); data.base64 = base64; data = base64; } })();
HTML code
<object data="data:application/pdf;base64,{{data.base64}}" type="application/pdf" width="50%" height="60%" class="internal"> <param name="view" value="fitH" /></object>
Pls help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 10:04 AM
I have the exact same client and server code as above, there is no error but PDF is not shown on the widget on portal. What is missing ?
2 Widgets are part of portal page. Page renders 1 other widget but not this widget meant for pdf embed
Server code of widget
(function() { var attach = '99e44c6797bb7910d8a97c9fe153af44'; // sys id of record that has the pdf attachment var gr = new GlideRecord('sys_attachment'); gr.addQuery('sys_id', attach); gr.query(); if(gr.next()) { var sa = new GlideSysAttachment(); var binData = sa.getBytes(gr); var base64 = GlideStringUtil.base64Encode(binData); data.base64 = base64; data = base64; } })();
HTML code this-
<object data="data:application/pdf;base64,{{data.base64}}" type="application/pdf" width="50%" height="60%" class="internal"> <param name="view" value="fitH" /></object>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2021 10:38 PM
How to use this script on catalog item. Is there any variable need to configure ?