Generating header/footer with flying saucer (xHTMLRenderer) and iText

后端 未结 3 1228
野的像风
野的像风 2020-12-08 10:57

I realize this question has been asked before (I looked at all the solutions and tried them all) but I am still trying to generate a pdf document with a header and footer th

3条回答
  •  难免孤独
    2020-12-08 11:08

    Here is a working example:

    package com.sg2net.test;
    
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    
    import org.xhtmlrenderer.pdf.ITextRenderer;
    
    import com.lowagie.text.DocumentException;
    
    public class XHTMLRenderer8 {
    
        /**
         * @author Giovanni Cuccu
         */
        public static void main(String[] args) throws FileNotFoundException, DocumentException {
            ITextRenderer renderer = new ITextRenderer();
            String content="\n" +
              "
    Header
    Page1
    Page2
    "; renderer.setDocumentFromString(content); renderer.layout(); renderer.createPDF(new FileOutputStream("test.pdf")); } }

    This is using the following XHTML document

    
    
    
    
    
        
    Header
    Page1
    Page2

提交回复
热议问题