How to Display PDF Preview within a Record?


Does someone know how I can display the attached pdf on an iFrame?

I just want a PDF file preview displayed within a Kintone record.


  1. Upload the PDF file on the Attachment field

  2. When viewing the record, a preview of the attached PDF should display

Thank you in advance.

Hello German!

This javascript is something that you are looking for. It’s a javascript to render PDF on browser or such.

In kintone, you just need to implement it in the space element.

For your reference, the following page shows the sample code of doing so. Though it is in Japanese,
you would probably figure it out by looking at those sample codes.

I got this working by referencing the Preview Data URI format PDF Qiita tutorial’s code, but I didn’t need the pdf.js.
I just used jQuery for bits of the code.

At first, I couldn’t get the width to adjust.
But I later realized the width was set as the same as the Blank Space element’s width (in the App’s settings).

Here’s the code I used, pretty much copied from the link xD

:zap: Make sure to include jQuery

(function () {
  'use strict';
  var SPACEFIELD_ID = "preview"; //Element ID of the Space field  
  var ATTACHMENT_FIELD_FIELDCODE = "pdffile"; //Field code of the attachment field  

  function getFile(url) {
    var df = new $.Deferred();
    var xhr = new XMLHttpRequest();'GET', url, true);
    xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
    xhr.responseType = 'blob';

    xhr.onload = function (e) {
      if (this.status === 200) {

    return df.promise();
  }'', function (event) {
    var record = event.record;

    var space =;
    var fileKey = record[ATTACHMENT_FIELD_FIELDCODE].value[0].fileKey;
    var fileUrl = '/k/v1/file.json?fileKey=' + fileKey;

    var promise = getFile(fileUrl);
    promise.done(function (pdfData) {
      var url = window.URL || window.webkitURL;
      var imageUrl = url.createObjectURL(pdfData);
      var preview = '\<object data="' + imageUrl + '" type="application/pdf" width="100%" height="100%"\>';
      preview += '\</object\>';
      $(space).append(preview).css('height', '1200');

Thanks guys for the answer I have made the requirement because of your help :slight_smile:

Hope you guys are still there for our company’s future projects with kintone

Yay, excellent! :smiley:

 have a problem running this script with IE11, I found an error this picture

Hello Nattapon!

Just to make sure, did you try it out with other browsers and it’s only happening in IE11?

The problem is only IE11.


Hello Nattapon,

Thanks for your reply and screenshots.

Since you said it’s working on other browsers,
the problem could be the IE settings, so can you check whether these apply to you?

Kintone Help - When Internet Explorer Cannot Display a Page Correctly

1 Like