question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set margin only for first page

See original GitHub issue

Hi, i exporting pdf from an API and i draw, insert and set tables an images. In header i put an image and a title, set a margin top so i can see these elements and in details have a page breaks. In this case in second page the margin top persist and draw me a white space. I want to reset this margin but only if page if not the first.

` var pdf = new jsPDF(‘p’, ‘pt’, ‘letter’); pdf.setFont(‘DINBold’); pdf.setFontSize(22); pdf.setTextColor(26, 40, 88); pdf.text("Tabla ",350, 80); pdf.addImage(imgData, ‘JPEG’, 40, 40, 200, 50);

            pdf.setFont('Times New Roman');
            pdf.setFontSize(10);
            pdf.setTextColor(0, 0, 0);
            pdf.setDrawColor(104, 176, 224);
            pdf.setFillColor(104, 176, 224);
         
            pdf.rect(40, 136, 510, 20, 'FD');
            pdf.rect(40, 256, 510, 20, 'FD');
            pdf.rect(40, 356, 510, 20, 'FD');

            pdf.setDrawColor(120, 197, 49);
            pdf.setFillColor(120, 197, 49);

            pdf.rect(550, 136, 20, 20, 'FD');
            pdf.rect(550, 256, 20, 20, 'FD');
            pdf.rect(550, 356, 20, 20, 'FD');

            pdf.setDrawColor(221, 221, 221);
            pdf.setFillColor(221, 221, 221);
            //pdf.rect(40, 170, 530, 70, 'FD');
            
            pdf.setTextColor(255, 255, 255);
            pdf.text("Tabla",43, 150);
            
            pdf.setTextColor(27, 40, 88);
            pdf.text("Número:  ",50, 186);
            pdf.text("Fecha:  ",350, 186);

            pdf.text(datos.numeroCuenta,150, 186);
            pdf.text(datos.fecha,450, 186);                              
            
            pdf.autoTable(movimientos.columns, movimientos.rows, {
              styles: {overflow: 'linebreak'},
              columnStyles: { 
                  fechaMovimiento: {columnWidth: 120}, 
                  descripcionMovimiento:{columnWidth:200}, 
                 
              },
              margin: {top: 210},
              addPageContent: function(data) {
                  pdf.setTextColor(255, 255, 255);
                  pdf.text("Tabla "+ datos.fecha + " "+ datos.fecha +" N° "+ datos.numeroCuenta);
                }
            });

pdf.save(“tabla.pdf”); ` Thanks in advance! screenshot13

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
followshihabcommented, Aug 17, 2019

Try the following code

        let doc = new jsPDF();
        doc.autoTable({
                margin: {top: 50}, // Seting top margin for First Page.
                didDrawPage: function (data) {
                    // Reseting top margin. The change will be reflected only after print the first page.
                    data.settings.margin.top = 10; 
        });
11reactions
RicTheThirdcommented, Sep 21, 2018

I know this is already closed but you can try this: Instead of margin, you can use startY. startY: pdf.pageCount > 1? pdf.autoTableEndPosY() + 20 : 210

Enjoy!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can you change the margins on the first page only?
1. Click on the first page and go into page layout and change margins and choose to apply to whole document. 2. Then...
Read more >
Creating different margins on the first page of a word template
Insert a Section Break (Next Page) from Page Layout > Breaks · Click on the page you want to expand/narrow the margins. ·...
Read more >
How to have different margins on the first page
Different margins = different section ... You may know that margins are a section property. In order to change the page margins (or...
Read more >
How to Change Margin on One Page in MS Word
Once you've successfully set up the section breaks, you can start changing the margins for that section already. Go to the Layout tab...
Read more >
Different margin on first page - TeX - LaTeX Stack Exchange
How can I achieve different margins only on the first page without doing pagebreaks by hand? Any trick (like using wrapfig or something...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found