Sometimes we’ll have a client ask to ‘display a PDF’ on a site, with I think their expectation that they’ll be able to just upload it and display on a page as if it was an image.
In these cases I normally just do a few exports of that PDF to PNG, add those to the page and link the image blocks to the original PDF for download.
But it got me revisiting how to embed PDFs, as over the years the support and methods have changed a little.
As a quick test I created a template for the File block, using an object tag:
<?php defined('C5_EXECUTE') or die('Access Denied.');
$c = Page::getCurrentPage();
$f = $controller->getFileObject();
$fp = new Permissions($f);
if ($f && $fp->canViewFile()) {?>
<div style="height: 0;padding-bottom: 147%; width: 100%; position: relative">
<object type="application/pdf" data="<?= $f->getURL(); ?>"
style="border: none; position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 100%; height: 100%;"
title="<?php echo h(stripslashes($controller->getLinkText())) ?>">
<a href="<?php echo $f->getForceDownloadURL() ?>">
<?= t('Download'); ?> <?php echo h(stripslashes($controller->getLinkText())) ?>
</a>
</object>
</div>
<?php
}
if (!$f && $c->isEditMode()) {
?>
<div class="ccm-edit-mode-disabled-item"><?= t('Empty File Block.') ?></div>
<?php
}
That’s been hardcoded to be roughly the right dimensions for an A4 portrait document, and is responsive. That works on Chrome, Firefox and desktop Safari. Using an iframe or embed tag seems to work just as well.
But on iOS, it renders the first page, but with no controls, and no ability to scroll to the second page. (i’m not surprised, as iOS traditionally hasn’t supported PDFs in the browser). It doesn’t even fall back to the link inside the object tag, it just pretends to be able to support inline PDFs.
So how do you approach it, especially with Concrete?
There’s an approach using https://drive.google.com/viewerng/viewer, and I’ve used an Adobe script approach in the past as well… but a ‘native’ approach without third parties would be preferable I’d think.
There’s also https://pdfobject.com, which really does browser detection to force fallbacks.
Thoughts?