View PDF file in service portal

Juliana
Kilo Expert

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&amp;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&amp;view=true&amp;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>

1 ACCEPTED SOLUTION

Juliana
Kilo Expert

I was able to make it work by converting the content Base64!

 

find_real_file.png

 

find_real_file.png

 

View solution in original post

33 REPLIES 33

Try to look into Variable type Macro - with it you can include custom widget to be displayed in record producer

Thanks, can you please tell me where to increase the page content size ? I can see the PDF file now, but its very small, I need to get it fit on full page.

Hi Juliana,

thanks for post.  What is the best way to create the attachment in the first place?  I have my PP file, and have created my record for it in the [sys_attachment] table, then I created a widget using your code.  But when I put the widget on my portal page, nothing is showing at all.  Any help would be great.  Thanks!

I have added these scripts on my widget and sys attachment has thePDF. used sys if of that here but PDF is not embeding.

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 

  <object data="data&colon;application/pdf;base64,{{data.base64}}" type="application/pdf" width="50%" height="60%" class="internal">
  <param name="view" value="fitH" /></object>