Javascript PDFlib是否添加密码?
PDFlib是否可以添加用户和所有者密码?我在你的网站上看到了这一点,但我不知道如何在我的代码中添加密码选项 我将pdf保存为base64格式,并使用此库在每张图纸的边缘添加一个文本。但我想有可能保护它的密码,如果它不能被编辑Javascript PDFlib是否添加密码?,javascript,pdflib,Javascript,Pdflib,PDFlib是否可以添加用户和所有者密码?我在你的网站上看到了这一点,但我不知道如何在我的代码中添加密码选项 我将pdf保存为base64格式,并使用此库在每张图纸的边缘添加一个文本。但我想有可能保护它的密码,如果它不能被编辑 const { degrees, PDFDocument, rgb, StandardFonts } = PDFLib modifyPdf(); async function modifyPdf() { // Fetch an existing
const { degrees, PDFDocument, rgb, StandardFonts } = PDFLib
modifyPdf();
async function modifyPdf() {
// Fetch an existing PDF document
const url = '<?php echo $pdf;?>'
const existingPdfBytes = await fetch(url).then(res => res.arrayBuffer())
// Load a PDFDocument from the existing PDF bytes
const pdfDoc = await PDFDocument.load(existingPdfBytes)
// Embed the Helvetica font
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica)
// Get document pages
const pages = pdfDoc.getPages()
// Iterate every pages
pages.forEach(page => {
// Get the width and height of the page
const {
width,
height
} = page.getSize()
// Draw a string of text diagonally across the page
page.drawText('Firmado por <?php echo $usuarionombre;?>, en fecha <?php echo $fechafirma;?>!', {
x: 12,
y: height / 2 - 300,
size: 12,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(90),
})
})
// Serialize the PDFDocument to bytes (a Uint8Array)
const pdfBytes = await pdfDoc.save()
// esto es para descargar el pdf
//download(pdfBytes, "pdf-lib_modification_example.pdf", "application/pdf");
// This step is only necessary if you don't already have a Buffer Object
var blob = new Blob([pdfBytes])
var reader = new FileReader();
reader.onload = function(event){
var base64 = event.target.result
var res = base64.replace("data:application/octet-stream;base64,", "");
var sites = ['data:application/pdf;base64, '+res]
document.getElementById('myIframe').src = sites[Math.floor(Math.random() * sites.length)];
};
reader.readAsDataURL(blob);
const{degrees,PDFDocument,rgb,StandardFonts}=PDFLib
修改PDF();
异步函数modifyPdf(){
//获取现有的PDF文档
常量url=''
const existingPdfBytes=等待获取(url)。然后(res=>res.arrayBuffer())
//从现有PDF字节加载PDFDocument
const pdfDoc=等待PDFDocument.load(现有pdfBytes)
//嵌入Helvetica字体
const helveticaFont=wait pdfDoc.embedFont(StandardFonts.Helvetica)
//获取文档页面
const pages=pdfDoc.getPages()
//迭代每一页
pages.forEach(第=>{
//获取页面的宽度和高度
常数{
宽度,
高度
}=page.getSize()
//在页面上沿对角线绘制一串文本
第页drawText('Firmado por,en fecha!'){
x:12,
y:高度/2-300,
尺码:12,
字体:helveticaFont,
颜色:rgb(0.95,0.1,0.1),
旋转:90度,
})
})
//将PDFDocument序列化为字节(Uint8Array)
const pdfBytes=await pdfDoc.save()
//esto es para descargar el pdf
//下载(pdfBytes,“pdf-lib_modification_example.pdf”,“application/pdf”);
//只有当您还没有缓冲区对象时,才需要此步骤
var blob=新blob([pdfBytes])
var reader=new FileReader();
reader.onload=函数(事件){
var base64=event.target.result
var res=base64.replace(“数据:应用程序/八位字节流;base64,”,“”);
var sites=['数据:应用程序/pdf;base64'+res]
document.getElementById('myIframe').src=sites[Math.floor(Math.random()*sites.length)];
};
reader.readAsDataURL(blob);