Jump to content

Export HTML or all Text Area Content to a multipages PDF document


sihem merah

Recommended Posts

Dear community,

This isn't a question, but rather sharing a tip (as I could not find any answer to it in the community)and calling for improvements if anyone tries it out. I managed to do it using some Javascriptwith the jsPDF package.

It's all in the HTML code of the attached DXP.

But here are some details:

 

 

 

jsPDF

 

 

@CHARSET 'UTF-8';

.page-break {

page-break-after: always; {

page-break-inside: avoid;

clear:both;

}

.page-break-before {

page-break-before: always;

page-break-inside: avoid;

clear:both;

}

 

 

 

 

Generate PDF

 

 

 

 

 

First Page

 

 

 

Knocky

Flor

Ella

Juan

 

 

 

Second page

 

 

 

Breed

Jack Russell

Poodle

Streetdog

Cocker Spaniel

 

 

 

 

 

 

margins = {

top: 40,

bottom: 40,

left: 10,

width: 750

};

 

generate = function()

{

var pdf = new jsPDF('p', 'pt', 'a4');

//pdf.setFontSize(10);

pdf.fromHTML(document.getElementById('sample-pdfwrapper'),

margins.left, // x coord

margins.top,

{

// y coord

width: margins.width// max width of content on PDF

},function(dispose) {

headerFooterFormatting(pdf, pdf.internal.getNumberOfPages());

},

margins);

pdf.save('sample-file.pdf');

};

 

function headerFooterFormatting(doc, totalPages)

{

for(var i = totalPages; i >= 1; i--)

{

doc.setPage(i);

//header

header(doc);

 

footer(doc, i, totalPages);

doc.page++;

}

};

 

function header(doc)

{

doc.setFontSize(30);

doc.setTextColor(40);

doc.setFontStyle('normal');

 

 

};

 

function footer(doc, pageNumber, totalPages){

 

var str = "Page " + pageNumber + " of " + totalPages

 

doc.setFontSize(10);

doc.text(str, margins.left, doc.internal.pageSize.height - 20);

 

};

 

 

 

 

 

 

 

Hope this helps,

Sihem

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...