0

i have the following function which takes lots of html strings and converts them into pdf files:

  async signedAgreements(documentstoDownload) {
    this.loading = true;

    // Create an array to hold the promises of each download operation
    const downloadLimit = limit(5); // Set the maximum number of concurrent downloads
    const downloadPromises = documentstoDownload.map((documenttoDownload) =>
      downloadLimit(async () => {
        // Create a new element to hold the HTML content
        const wrapper = document.createElement("div");
        wrapper.innerHTML = documenttoDownload.document;

        // Set the options for html2pdf
        const options = {
          margin: 10,
          filename:
            documenttoDownload.school + ": " + documenttoDownload.document_name,
          image: { type: "jpeg", quality: 0.98 },
          html2canvas: { scale: 2, logging: true, scrollX: 0, scrollY: 0 },
          jsPDF: { unit: "mm", format: "a4", orientation: "portrait" },
        };

        // Call the html2pdf function to convert and save as PDF
        await html2pdf().from(wrapper).set(options).save();
      })
    );

    // Wait for all the download promises to complete before proceeding
    await Promise.all(downloadPromises);

    this.loading = false;
  }

However, it isn't displaying the images in the pdf, it just leaves a big space where they should be. Is there a way to include them?

Also is there a way to speed this function up at all? Some documents to download have about 20 pages, and its currently taking about 20 seconds to download 5 of these documents.

Thanks in advance!

  • But the images aren't downloading in my code. How are you getting images to display in yours at all? @KJ – BranchCoder Jul 26 '23 at 06:02
  • @KJ where did you get that document from? My document only has one image and then 9 pages of text? I haven't linked it to this question – BranchCoder Jul 26 '23 at 09:31

0 Answers0