The given URL is just lacking a "page" parameter in order to download specific pages. E.g.
/sfc/servlet.shepherd/version/renditionDownload?rendition=SVGZ&versionId=0687Z000002EkVc&operationContext=CHATTER&page=2
downloads the second page. I'm unaware of any means to know the number of preview pages though. As a workaround one can render as many img tags for pages as can be successfully downloaded. A successful download takes a little time, but can be verified in Javascript by testing the naturalWidth
of the img tag. The following LWC demonstrates this approach.
HTML
<template>
<div lwc:ref="preview"></div>
</template>
Javascript
/* eslint-disable @lwc/lwc/no-async-operation */
import { LightningElement } from 'lwc';
export default class DisplayPdf extends LightningElement {
img;
page = 0;
milliseconds = 100;
renderAttemptNumber = 0;
versionId = '068J6000006Gco6IAC';
hasRendered = false;
renderedCallback() {
if(this.hasRendered) {
return;
}
this.hasRendered = true;
this.appendImage();
}
appendImage() {
if(!this.img || this.img.naturalWidth > 0) {
this.img = document.createElement('img');
this.img.src = `/sfc/servlet.shepherd/version/renditionDownload?rendition=SVGZ&versionId=${this.versionId}&operationContext=CHATTER&page=${this.page}`;
this.refs.preview.appendChild(this.img);
this.page++;
this.renderAttemptNumber = 0;
setTimeout(() => {this.appendImage();}, this.milliseconds);
} else {
this.renderAttemptNumber++;
if(this.renderAttemptNumber < 10) {
setTimeout(() => {this.appendImage();}, this.milliseconds);
} else {
this.img.remove();
}
}
}
}
The img.remove()
makes sure no broken images are shown in the page (longer than a a second or so).
Here is some related information (although most of it is not about previews, but the actual file). Nowadays, in most cases where a link suffices, the NavigationMixin might do the job.