| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 
 | import * as tauriFs from "tauri/api/fs";
 
async mergePDF() {
      const temp1Url = "./template/temp1.pdf";
      const temp1PdfBytes = await fetch(temp1Url).then((res) =>
        res.arrayBuffer().catch((err) => alert(err))
      );
 
      const pdfDoc = await PDFDocument.create();  //==> vient de PDF-LIB
      const [temp1] = await pdfDoc.embedPdf(temp1PdfBytes);
      const page1 = pdfDoc.addPage();
      page1.drawPage(temp1);
 
      const pdfBytes = await pdfDoc.save();  // ==> retourne un Uint8Array
      //const pdfBase64 = await pdfDoc.saveAsBase64();
      //var blob = new Blob([pdfBytes], { type: "application/pdf" });
 
      await tauriDialog
        .save({})
        .then((data) => {
          this.pathTauri = data;    //pathTauri est bien déclaré plus tot dans mon code
          this.msgTauri = "Ecriture dans " + this.pathTauri;
        })
        .catch((err) => console.log("Error:", err));
 
      await tauriFs.writeFile({ path: this.pathTauri, contents: pdfBytes });  // j'ai aussi essayé avec pdfBase64 et blob... même avec temp1PdfBytes
    }, | 
Partager