Copy link to clipboard
Copied
I want to print my pdf from an external button, like this.
Copy link to clipboard
Copied
It's my code
class ViewSDKClient {
constructor(base64File, clientId, documentId) {
this.readyPromise = new Promise((resolve) => {
if (window.AdobeDC) {
resolve()
} else {
document.addEventListener('adobe_dc_view_sdk.ready', () => {
resolve()
})
}
})
this.adobeDCView = undefined
this.base64File = base64File;
this.clientId = clientId;
this.documentId = documentId;
}
ready() {
return this.readyPromise
}
previewFile(divId, viewerConfig) {
const config = {
clientId: this.clientId,
}
if (divId) {
config.divId = divId
}
this.adobeDCView = new window.AdobeDC.View(config)
function base64ToArrayBuffer(base64) {
var bin = window.atob(base64)
var len = bin.length
var uInt8Array = new Uint8Array(len)
for (var i = 0; i < len; i++) {
uInt8Array[i] = bin.charCodeAt(i)
}
return uInt8Array.buffer;
}
const previewFilePromise = this.adobeDCView.previewFile(
{
content: { promise: Promise.resolve(base64ToArrayBuffer(this.base64File)) },
metaData: {fileName: this.documentId+'.pdf'},
},
viewerConfig,
)
previewFilePromise.then(adobeViewer => {
adobeViewer.getAPIs().then(apis => {
debugger
apis.getPDFMetadata()
.then(result => console.log(result))
.catch(error => console.log(error));
});
});
return previewFilePromise
}
previewFileUsingFilePromise(divId, filePromise, fileName) {
this.adobeDCView = new window.AdobeDC.View({
clientId: this.clientId,
divId,
})
this.adobeDCView.previewFile(
{
content: {promise: filePromise,},
metaData: {fileName: fileName,},
},
{},
)
}
registerSaveApiHandler() {
const saveApiHandler = (metaData, content, options) => {
console.log(metaData, content, options)
return new Promise((resolve) => {
setTimeout(() => {
const response = {
code: window.AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
data: {
metaData: Object.assign(metaData, {
updatedAt: new Date().getTime(),
}),
},
}
resolve(response)
}, 2000)
})
}
this.adobeDCView.registerCallback(
window.AdobeDC.View.Enum.CallbackType.SAVE_API,
saveApiHandler,
{},
)
}
registerEventsHandler() {
this.adobeDCView.registerCallback(
window.AdobeDC.View.Enum.CallbackType.EVENT_LISTENER,
(event) => {
console.log(event)
},
{
enablePDFAnalytics: true,
},
)
}
}
export default ViewSDKClient
Copy link to clipboard
Copied
Currently, that's not possible using Embed API. printing must be triggered manually. There is no API to make the viewer print.