Skip to content

Mix orientation (landscape & portrait) with the html() function #3632

@braadworst

Description

@braadworst

Given the following piece of code I am trying to generate a PDF document as output where some of the page are in landscape and some are in portrait. each call to html() generates a well formatted page. If everything is in portrait the code and jsPDF is working fine, but as soon as I want to add a page in landscape the whole renderer goes bananas.

I've been on this now for hours, something that seems to be simple, but I cannot get it fixed. I was thinking about just creating a new instance for each page that I need to output and then merge them together. Is there a way that you can merge pages (jsPDF instances together in one?, been looking at the internal API for this, but I am not sure what I am looking at .write(), .out(), .putStream())

Help would ben appreciated

    let offsetHeight = 0;

    addSectionToPdf(0);

    function addSectionToPdf(pageNumber) {
      const section = sections.at(pageNumber);
      const nextSection = sections.at(pageNumber + 1);
      section.classList.add('export');
      update((pageNumber + 1) / total * 100);

      if (nextSection) {
        pdf.addPage(getDimensions(nextSection), getOrientation(nextSection));
      }

      pdf.html(section, {
        y: offsetHeight,
        fontFaces: getFonts(),
        html2canvas: {
          onclone: () => {
            fastCompressImages(pdf, section);
            createLinks(pdf, section, pageNumbers);
          }
        },
        callback(pdf) {
          if (pageNumber + 1 === total) {
            pdf.save(fileName);
            hide();
          } else {
            section.classList.remove('export');
            offsetHeight += getDimensions(section).at(1);
            
            addSectionToPdf(pageNumber + 1);
          }
        }
      });
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions