Generating PDF documents with text-only header and/or footer

PD4PageMark header = new PD4PageMark();
      header.setAreaHeight( 20 );
      header.setTitleTemplate( "title: $[title]" );
      header.setTitleAlignment( PD4PageMark.CENTER_ALIGN );
      header.setPageNumberAlignment( PD4PageMark.LEFT_ALIGN );
      header.setPageNumberTemplate( "#$[page]" );
                 
      PD4PageMark footer = new PD4PageMark();
      footer.setAreaHeight( 30 );
      footer.setFontSize( 20 );
      footer.setColor( Color.red );
      footer.setPagesToSkip( 1 );
      footer.setTitleTemplate( "[ $[title] ]" );
      footer.setPageNumberTemplate( "page: $[page]" );
      footer.setTitleAlignment( PD4PageMark.RIGHT_ALIGN );
      footer.setPageNumberAlignment( PD4PageMark.LEFT_ALIGN );
 
      pd4ml.setPageHeader( header );
      pd4ml.setPageFooter( footer );

Converting HTML obtained from input stream to PDF

File f = new File("D:/tools/test.pdf");
java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
OutputStream sos = System.out;
 
      File fz = new File("D:/tools/yahoo.htm");
      java.io.FileInputStream fis = new java.io.FileInputStream(fz);
      InputStreamReader isr = new InputStreamReader( fis, "UTF-8" );
                 
      PD4ML html = new PD4ML();
      html.setPageSize( new Dimension(450, 450) );
      html.setPageInsets( new Insets(20, 50, 10, 10) );
      html.setHtmlWidth( 750 );
      html.enableImgSplit( false );
 
      URL base = new URL( "file:D:/tools/" );
 
      // alternatively base can be specified with <base href="..."> tag
      html.render( isr, fos, base );

Converting HTML addressed by URL to PDF

import org.zefer.pd4ml.PD4ML;
   import org.zefer.pd4ml.PD4Constants;
    ...
 2  protected Dimension format = PD4Constants.A4;
   protected boolean landscapeValue = false;
   protected int topValue = 10;
   protected int leftValue = 10;
   protected int rightValue = 10;
   protected int bottomValue = 10;
   protected String unitsValue = "mm";
   protected String proxyHost = "";
   protected int proxyPort = 0;
 
3  protected int userSpaceWidth = 780;
 
   ...
 
   private void runConverter(String urlstring, File output) throws IOException {
 
         if (urlstring.length() > 0) {
                if (!urlstring.startsWith("http://") && !urlstring.startsWith("file:")) {
                              urlstring = "http://" + urlstring;
                }
 
4               java.io.FileOutputStream fos = new java.io.FileOutputStream(output);
               
5               if ( proxyHost != null && proxyHost.length() != 0 && proxyPort != 0 ) {
                       System.getProperties().setProperty("proxySet", "true");
                       System.getProperties().setProperty("proxyHost", proxyHost);
                       System.getProperties().setProperty("proxyPort", "" + proxyPort);
                }
 
6               PD4ML pd4ml = new PD4ML();
 
7               try {                                                              
                       pd4ml.setPageSize( landscapeValue ? pd4ml.changePageOrientation( format ): format );
                    } catch (Exception e) {
                       e.printStackTrace();
                    }
                      
                if ( unitsValue.equals("mm") ) {
                       pd4ml.setPageInsetsMM( new Insets(topValue, leftValue,
bottomValue, rightValue) );
                } else {
                       pd4ml.setPageInsets( new Insets(topValue, leftValue,
bottomValue, rightValue) );
                }
 
                pd4ml.setHtmlWidth( userSpaceWidth );
               
8               pd4ml.render( urlstring, fos );
         }
   }
 
       ...

Comments:
1. Import the PD4ML converter class
2. Define HTML-to-PDF converting parameter values if needed. See API reference for more info.
3. Specify user space width. It has an analogy to Web-browser window horizontal size. From common web-browsing experience you can guess, that changing of the size can affect the HTML document representation: HTML elements arrangement, vertical size etc. See API reference for more info.
4. Preparing output stream for PDF generation.
5. Specifying proxy settings if the source HTML document is behind the firewall.
6. Instantiating PD4ML converter.
7. Passing to it HTML-to-PDF converting parameters.
8. Performing HTML-to-PDF translation. Note: using of an URL is not mandatory. PD4ML can read a source HTML from input stream. See API reference for more info.