我这里有一个 CodePen ,它使用免费的Adobe DC View SDK准确显示了这个功能。除非您覆盖本机浏览器查看器,否则您无法控制 PDF 体验。我的示例的相关代码如下。在我的示例中,PDF 是从另一个域获取的,但“content”参数将接受任何解析为 PDF 内容的 ArrayBuffer 的 Promise。您的 PDF 可以存储在任何地方或动态创建,然后显示在 HTML 页面中。
document.addEventListener("adobe_dc_view_sdk.ready", function () {
/*
The clientId is tied to a specific domain. To display a PDF hosted
on a different domain using the Adobe View SDK, we need to fetch the file
first then pass it to the "content" parameter as a Promise.
*/
fetch("https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf")
.then((res) => res.blob())
.then((blob) => {
var adobeDCView = new AdobeDC.View({
// This clientId can be used for any CodePen example
clientId: "YOUR_CLIENT_ID",
// The id of the container for the PDF Viewer
divId: "adobe-dc-view"
});
adobeDCView.previewFile(
{
// The file content
content: { promise: Promise.resolve(blob.arrayBuffer()) },
metaData: { fileName: "Bodea Brochure.pdf" }
},
{
embedMode: "FULL_WINDOW", // possible values are "FULL_WINDOW", "SIZED_CONTAINER" and "IN_LINE"
defaultViewMode: "FIT_WIDTH", // possible values are "FIT_WIDTH" and "FIT_PAGE"
showDownloadPDF: true,
showPrintPDF: true,
showLeftHandPanel: true,
showAnnotationTools: true
}
);
});
});
您可以在此处获取自己的凭据