PDF on iPhone

I’m using webview to display PDF’s on my app. It looks great on the preview but on the app itself on my actual iPhone, it doesn’t display the PDF properly, it just shows one image from the PDF. Any idea?

1 Like

Do you store that file on Glide’s storage or somewhere else?

I store it on my own server. Does it matter?

I haven’t tested this case but does that link work with an image component?

Hello, when I attach it as an image, it shows just the first image of the PDF but not the PDF itself. It looks like a bug. Any idea?

1 Like

Okay, you and I are on the same page today @SuperMerabh! I am trying to display PDF for the first time today. Read all the threads I could find and have tried webview and image components and it’s not working. For me, I upload via file picker and I see the resultant url link in the sheet but webview is blank on GDE and scrolls up/down and sideways in phone, but still only one page. Image displays only first page - no scroll. Did you happen to figure it out or anyone else have any ideas what is going wrong? I do not want to try cloudinary yet. May get there but trying to use native Glide capabilities first.

Yes we are @deena, I am very new to this app so I’m not familiar with all the other options. I just used a direct URL to the PDFs. Worked great on the preview but not on iphone. I eventually gave up and just put a button linking to the PDF.

1 Like

Try this

1 Like

Just adding to this, this works well if you use Google Drive as the source. If you try this kind of embed with a PDF outside of Drive it will likely hit some hourly limits and not displaying to your users.

One downside with displaying a PDF using an image component is that the “Tap to Enlarge” action doesn’t work with PDF files. To work around this, I generate a png image of all my PDF’s using ConvertAPI.

So if a user views a PDF in the app, they actually see an image, which is zoomable.
But if they choose to download the file or have it emailed to them, then they get a PDF* file.

* they actually get a password protected PDF, but that’s another story :wink:

2 Likes

Could you please share how you password protect the downloaded/ email file?

I’d like to apply it to .csv’s which I imagine would be the same.

I use the same API I mentioned in my previous post - https://www.convertapi.com

function password_protect_pdf(file_id, folder_id, password) {
  var file = DriveApp.getFileById(file_id);
  var blob = file.getBlob();
  var file_string = Utilities.base64Encode(blob.getBytes());
  var url = CONVERT_API;
  var obj = {
    "Parameters": [
      {
        "Name": "File",
        "FileValue": {
          "Name": file_id + '.pdf',
          "Data": file_string
        }
      },
      {
        "Name": "UserPassword",
        "Value": password
      },
    ]
  };

  var json = JSON.stringify(obj);
  var payload = json;
  var options = {
    method: 'POST',
    payload: payload,
    contentType: "application/json; charset=utf-8",
  };
  var response = UrlFetchApp.fetch(url, options);
  var json = response.getContentText();
  var data = JSON.parse(json);
  var text = data.Files[0].FileData;
  var protected_file_id = decode_and_save_pdf(text, file_id, folder_id);
  return protected_file_id;
}
1 Like