5

I need to get the page border while download a pdf file using the jspdf function.

How can I achieve this. I am able to set border for tables alone and not able to set for the pages.

var doc = new jsPDF('p', 'pt'); doc.setFontSize(12); doc.setTextColor(0); doc.setFontStyle('bold'); doc.text('Col and row span', 40, 50); var elem = document.getElementById("table1"); var elem1 = document.getElementById("tbl1"); var elem1 = document.getElementById("example"); var res = doc.autoTableHtmlToJson(elem); var res1 = doc.autoTableHtmlToJson(elem1); doc.text('Theme "plain"', 40, doc.autoTableEndPosY() + 30); doc.autoTable(res.columns, res.data, { startY: 90, theme: 'grid', drawHeaderRow: function(cell, data) { return false; }, pageBreak: 'avoid', margin: { right: 305 } }); doc.autoTable(res.columns, res.data, { startY: 90, pageBreak: 'avoid', theme: 'grid', drawHeaderRow: function(cell, data) { return false; }, margin: { left: 305 } }); doc.autoTable(res1.columns, res1.data, { startY: doc.autoTableEndPosY() + 30, }); 

how can i set border for this doc?

3
  • Please add some code which you have tried Commented Dec 29, 2016 at 10:31
  • @dhruvjadia var doc = new jsPDF('p', 'pt'); doc.setFontSize(12); doc.setTextColor(0); doc.setFontStyle('bold'); doc.text('Col and row span', 40, 50); Commented Dec 29, 2016 at 10:33
  • add page code in your question Commented Dec 29, 2016 at 10:35

2 Answers 2

6

If you by page border mean a border around the entire page, try something like this:

doc.rect(20, 20, doc.internal.pageSize.width - 40, doc.internal.pageSize.height - 40, 'S'); 
Sign up to request clarification or add additional context in comments.

2 Comments

Any suggestion for multiple pages? it's working for only the first page.
refer my answer
2

For multiple pages we can do like this

for (let i = 0; i < doc.getNumberOfPages(); i++) { doc.setPage(i + 1) doc.setDrawColor("#000000"); doc.rect(5, 5, pdf.internal.pageSize.width - 10, pdf.internal.pageSize.height - 10, 'S'); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.