37
Views
6
Comments
download pdf using html2pdf.js scripts
Question
Application Type
Reactive

iam trying to download pdf my script 

var delayInMilliseconds = 20000; //20 secondsetTimeout(function() {  //your code to be executed after 10 second  var element = document.getElementById($parameters.ContainerId);var opt = {    margin: 0.5,    filename: $parameters.Filename,    html2canvas: { scale: 2 },    jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }};html2pdf().set(opt).from(element)        .then(function(){          var doc = $('.html2pdf__container');          doc.find('.show-on-export').css('display', 'block');          //doc.find('.show-on-export').show(); // show content hide by CSS.        }).save();$actions.Isloading()}, delayInMilliseconds);


.show-on-export { display: none}

its downloading blank pdf


2024-12-02 13-16-47
Vipin Yadav

Hi @Navya Vani,

If possible, please share your OML file so that I can check it and get back to you. 

Thanks,

Vipin Yadav

2024-12-02 13-16-47
Vipin Yadav

Hi @Navya Vani ,

I have attached oml files with examples for your reference. Additionally, I have included the screenshot below. Please check.

Demo URL - https://vyadav.outsystemscloud.com/PdfExport/Screen1



Thanks,

Vipin Yadav

PdfExport.oml
2024-12-02 13-16-47
Vipin Yadav

Below Javascript I have added -

var element = document.getElementById($parameters.ElementId);// Check if the element existsif (element) {  html2pdf().from(element).set({    margin: [0, 0, 1, 0],     filename: $parameters.Filename,    pageBreak: { mode: 'css', before: 'page-break-before' },    jsPDF: { orientation: 'landscape', unit: 'in', format: 'letter' }  }).toPdf().get('pdf').then(function (pdf) {    var totalPages = pdf.internal.getNumberOfPages();    for (var i = 1; i <= totalPages; i++) {      pdf.setPage(i);      pdf.setFontSize(10);      pdf.setTextColor(150);      pdf.text('Page ' + i + ' of ' + totalPages, (pdf.internal.pageSize.getWidth() / 3.75), (pdf.internal.pageSize.getHeight() - 0.75));    }  }).save();} else {  console.error("Element not found: " + $parameters.ElementId);}

Thanks,

Vipin Yadav

2021-01-04 08-13-48
Toto
 
MVP

Hi @Navya Vani,


Is your question the same with your coworker @Peruri Satya Siva Teja on https://www.outsystems.com/forums/discussion/101060/pdf-generation-without-using-forge-components/ ?


Please refrain to create multiple post with the same question with multiple people. 

Because this already have @Vipin Yadav answering, lets continue in here


Thanks

2020-07-21 19-28-50
Rajat Agrawal
Champion

Hi @Navya Vani 

can you please apply below script

function downloadPdf() {

var element = document.getElementById($parameters.ContainerId);

    var doc = $('.html2pdf__container');

    doc.find('.show-on-export').css('display', 'block'); 

var opt = { margin: 0.5,

        filename: $parameters.Filename,

        html2canvas: { scale: 2 },

        jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }

    };

    html2pdf().set(opt).from(element)

        .then(function() {

            doc.find('.show-on-export').css('display', 'none');

        }).save();

    

    $actions.Isloading(); // Hide loading indicator

}

var delayInMilliseconds = 20000; // 20 seconds

setTimeout(downloadPdf, delayInMilliseconds);

Regards ,
Rajat


2024-05-14 05-39-17
Jothikarthika - EONE

Hi 

Could you try running this script? 

var element = document.getElementById($parameters.ElementId);   

// Generate the PDF.

  html2pdf().from(element).set({  margin:       [0, 0, 1, 0],     filename: $parameters.Filename,    pageBreak: { mode: 'css', before:'page-break-before'},    jsPDF: {orientation: 'landscape', unit: 'in', format: 'letter'}  }).toPdf().get('pdf').then(function (pdf) {    var totalPages = pdf.internal.getNumberOfPages();    for (i = 1; i <= totalPages; i++) {        pdf.setPage(i);      pdf.setFontSize(10);      pdf.setTextColor(150);    pdf.text('Page ' + i + ' of ' + totalPages, (pdf.internal.pageSize.getWidth()/3.75), (pdf.internal.pageSize.getHeight()-0.75));                     }  }).save();


Best Regards,

Jothikarthika


htmltopdf.txt
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.