Alter the default header/footer when printing to PDF

后端 未结 7 1645
攒了一身酷
攒了一身酷 2020-12-14 02:21

I\'m trying to use Google Chrome as a replacement of PhantomJS to render HTML into PDF. So far it\'s been working well for me. The only issue I have that I have not found an

7条回答
  •  庸人自扰
    2020-12-14 02:53

    As mentioned by Alec Jacobson in the comments, using margin:0 on the page along with margin:1.6cm on the body works only for one page.

    What worked for me was to wrap my content in a table, using thead for the top margin and tfoot for the bottom margin. Thead and tfoot are repeated on all pages and your main page content goes in the tbody of the table.

    Example:

    `

         
             
                
                    Header    
                
            
        
    
        
            
                
    
                    Page Content
    
                
            
        
    
        
            
                
    
                    Footer
    
                
            
        
    
    `
    

    Would have liked to have added to the comment thread but don't have enough reputation.

提交回复
热议问题