eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
4.07k stars 1.38k forks source link

I want o set both orientation in same pdf #691

Open Siddhesh220398 opened 6 months ago

Siddhesh220398 commented 6 months ago

Hi, I want to add both orientation portrait and landscape in same pdf but it's not working. Can you help me out how to set opt on every page. Below I had share code.

const downloadPDF2 = (elements, pdfOptions) => {

      let worker = html2pdf()
        .set(pdfOptions)
        .from(elements[0])

      if (elements.length > 1) {
        worker = worker.toPdf() // worker is now a jsPDF instance

        // add each element/page individually to the PDF render process
        elements.slice(1).forEach((element, index) => {
          worker = worker
            .get('pdf')
            .then(pdf => {
              pdf.addPage()
            })
            .from(element)
            .toContainer()
            .toCanvas()
            .toPdf()
        })
      }

      worker = worker.save().then(
        function (pdf) {
            $('body').find('.process-div').html('');
            $('body').find('.btn-d').css('display','inline');
        },
         function(){
            $('body').find('.process-div').html('PDF Genration Fail Please Try Again!');
            $('body').find('.btn-d').css('display','inline');
        }).catch(function (error) {
            console.log(error);
            /* This is fired when the promise executes without the DOM */
        });
    }