• react--pdf-lib给PDF添加水印兼容IE11


    import { degrees, PDFDocument, rgb, StandardFonts } from 'pdf-lib';

    export async function modifyPdf(url, texts) {
      const text = `${texts}`;
      const existingPdfBytes = await fetch(url).then(res => res.arrayBuffer());
      const pdfDoc = await PDFDocument.load(existingPdfBytes);
      const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica);
      const page = pdfDoc.getPages();
      const firstPage = page[0];
      const { height } = firstPage.getSize();
      page.forEach(item => {
        item.drawText(text, {
          x: 10,
          y: height - 100,
          size: 30,
          font: helveticaFont,
          color: rgb(0.82, 0.86, 0.89),
          rotate: degrees(45),
        });
        item.drawText(text, {
          x: 480,
          y: height - 65,
          size: 30,
          font: helveticaFont,
          color: rgb(0.82, 0.86, 0.89),
          rotate: degrees(45),
        });
        item.drawText(text, {
          x: 15,
          y: height - 200,
          size: 30,
          font: helveticaFont,
          color: rgb(0.82, 0.86, 0.89),
          rotate: degrees(45),
        });
      });
      if (window.navigator && window.navigator.msSaveOrOpenBlob) {
        const blob = new Blob([await pdfDoc.save()], { type: 'application/pdf' });
        window.navigator.msSaveBlob(blob,'预览.pdf');
      } else {
        const pdfUrl = URL.createObjectURL(
          new Blob([await pdfDoc.save()], { type: 'application/pdf' }),
        );
        window.open(pdfUrl, '_blank');
      }
    }
  • 相关阅读:
    (字典树)Revenge of Fibonacci -- HDU -- 4099
    (字符串 KMP)Blue Jeans -- POJ -- 3080:
    (广搜)聪明的打字员 -- POJ --1184
    (线段树 点更新 区间求和)lightoj1112
    Jquery弹窗插件Lhgdialog的用法
    SQL Server数据库大型应用解决方案总结
    C# 使用XmlDocument类对XML文档进行操作
    反射实例【转】
    如何使用dynamic
    [C#]DataTable常用操作总结
  • 原文地址:https://www.cnblogs.com/huangzhenhui/p/13595103.html
Copyright © 2020-2023  润新知