com.lowagie.text.HeaderFooter Java Examples

The following examples show how to use com.lowagie.text.HeaderFooter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MPdfWriter.java    From javamelody with Apache License 2.0 6 votes vote down vote up
/**
 * We create a writer that listens to the document and directs a PDF-stream to out
 *
 * @param table
 *           MBasicTable
 * @param document
 *           Document
 * @param out
 *           OutputStream
 * @return DocWriter
 * @throws DocumentException
 *            e
 */
protected DocWriter createWriter(final MBasicTable table, final Document document,
		final OutputStream out) throws DocumentException {
	final PdfWriter writer = PdfWriter.getInstance(document, out);
	// writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);

	// title
	if (table.getName() != null) {
		final HeaderFooter header = new HeaderFooter(new Phrase(table.getName()), false);
		header.setAlignment(Element.ALIGN_LEFT);
		header.setBorder(Rectangle.NO_BORDER);
		document.setHeader(header);
		document.addTitle(table.getName());
	}

	// simple page numbers : x
	// HeaderFooter footer = new HeaderFooter(new Phrase(), true);
	// footer.setAlignment(Element.ALIGN_RIGHT);
	// footer.setBorder(Rectangle.TOP);
	// document.setFooter(footer);

	// add the event handler for advanced page numbers : x/y
	writer.setPageEvent(new AdvancedPageNumberEvents());

	return writer;
}
 
Example #2
Source File: PdfDocumentFactory.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void createWriter(Document document, String title)
		throws DocumentException, IOException {
	final PdfWriter writer = PdfWriter.getInstance(document, output);
	//writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);

	// title
	final HeaderFooter header = new HeaderFooter(new Phrase(title), false);
	header.setAlignment(Element.ALIGN_LEFT);
	header.setBorder(Rectangle.NO_BORDER);
	document.setHeader(header);

	// simple page numbers : x
	//HeaderFooter footer = new HeaderFooter(new Phrase(), true);
	//footer.setAlignment(Element.ALIGN_RIGHT);
	//footer.setBorder(Rectangle.TOP);
	//document.setFooter(footer);

	// add the event handler for advanced page numbers : x/y
	writer.setPageEvent(new PdfAdvancedPageNumberEvents());
}
 
Example #3
Source File: RtfHeaderFooter.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructs a RtfHeaderFooter for a HeaderFooter.
 *  
 * @param doc The RtfDocument this RtfHeaderFooter belongs to
 * @param headerFooter The HeaderFooter to base this RtfHeaderFooter on
 */
protected RtfHeaderFooter(RtfDocument doc, HeaderFooter headerFooter) {
    super(new Phrase(""), false);
    this.document = doc;
    Paragraph par = new Paragraph();
    par.setAlignment(headerFooter.alignment());
    if (headerFooter.getBefore() != null) {
        par.add(headerFooter.getBefore());
    }
    if (headerFooter.isNumbered()) {
        par.add(new RtfPageNumber(this.document));
    }
    if (headerFooter.getAfter() != null) {
        par.add(headerFooter.getAfter());
    }
    try {
        this.content = new Object[1];
        this.content[0] = doc.getMapper().mapElement(par)[0];
        ((RtfBasicElement) this.content[0]).setInHeader(true);
    } catch(DocumentException de) {
        de.printStackTrace();
    }
}
 
Example #4
Source File: RtfHeaderFooterGroup.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Set a HeaderFooter to be displayed at a certain position
 * 
 * @param headerFooter The HeaderFooter to set
 * @param displayAt The display location to use
 */
public void setHeaderFooter(HeaderFooter headerFooter, int displayAt) {
    this.mode = MODE_MULTIPLE;
    switch(displayAt) {
        case RtfHeaderFooter.DISPLAY_ALL_PAGES:
            headerAll = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
        	break;
        case RtfHeaderFooter.DISPLAY_FIRST_PAGE:
            headerFirst = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
            break;
        case RtfHeaderFooter.DISPLAY_LEFT_PAGES:
            headerLeft = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
            break;
        case RtfHeaderFooter.DISPLAY_RIGHT_PAGES:
            headerRight = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
            break;
    }
}
 
Example #5
Source File: RtfDocumentHeader.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Converts a HeaderFooter into a RtfHeaderFooterGroup. Depending on which class
 * the HeaderFooter is, the correct RtfHeaderFooterGroup is created.
 * 
 * @param hf The HeaderFooter to convert.
 * @param type Whether the conversion is being done on a footer or header
 * @return The converted RtfHeaderFooterGroup.
 * @see com.lowagie.text.rtf.headerfooter.RtfHeaderFooter
 * @see com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup
 */
private RtfHeaderFooterGroup convertHeaderFooter(HeaderFooter hf, int type) {
    if(hf != null) {
        if(hf instanceof RtfHeaderFooterGroup) {
            return new RtfHeaderFooterGroup(this.document, (RtfHeaderFooterGroup) hf, type);
        } else if(hf instanceof RtfHeaderFooter) {
            return new RtfHeaderFooterGroup(this.document, (RtfHeaderFooter) hf, type);
        } else {
            return new RtfHeaderFooterGroup(this.document, hf, type);
        }
    } else {
        return new RtfHeaderFooterGroup(this.document, type);
    }
}
 
Example #6
Source File: PdfDocument.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Changes the footer of this document.
 *
 * @param	footer		the new footer
 */

public void setFooter(HeaderFooter footer) {
    if (writer != null && writer.isPaused()) {
        return;
    }
    super.setFooter(footer);
}
 
Example #7
Source File: PdfDocument.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Changes the header of this document.
 *
 * @param header the new header
 */

public void setHeader(HeaderFooter header) {
    if (writer != null && writer.isPaused()) {
        return;
    }
    super.setHeader(header);
}
 
Example #8
Source File: MRtfWriter.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * We create a writer that listens to the document and directs a RTF-stream to out
 *
 * @param table
 *           MBasicTable
 * @param document
 *           Document
 * @param out
 *           OutputStream
 * @return DocWriter
 */
@Override
protected DocWriter createWriter(final MBasicTable table, final Document document,
		final OutputStream out) {
	final RtfWriter2 writer = RtfWriter2.getInstance(document, out);

	// title
	final String title = buildTitle(table);
	if (title != null) {
		final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title));
		header.setAlignment(Element.ALIGN_LEFT);
		header.setBorder(Rectangle.NO_BORDER);
		document.setHeader(header);
		document.addTitle(title);
	}

	// advanced page numbers : x/y
	final Paragraph footerParagraph = new Paragraph();
	final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
	footerParagraph.add(new RtfPageNumber(font));
	footerParagraph.add(new Phrase(" / ", font));
	footerParagraph.add(new RtfTotalPageNumber(font));
	footerParagraph.setAlignment(Element.ALIGN_CENTER);
	final HeaderFooter footer = new RtfHeaderFooter(footerParagraph);
	footer.setBorder(Rectangle.TOP);
	document.setFooter(footer);

	return writer;
}
 
Example #9
Source File: PdfDataEntryFormUtil.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void setFooterOnDocument( Document document, String footerText, Font font )
{
    boolean isNumbered = true;

    HeaderFooter footer = new HeaderFooter( new Phrase( footerText, font ), isNumbered );
    footer.setBorder( Rectangle.NO_BORDER );
    footer.setAlignment( Element.ALIGN_RIGHT );
    document.setFooter( footer );
}
 
Example #10
Source File: PdfDocument.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Changes the header of this document.
 *
 * @param header the new header
 */
@Override
public void setHeader(HeaderFooter header) {
	if (writer != null && writer.isPaused()) {
		return;
	}
	super.setHeader(header);
}
 
Example #11
Source File: RtfHeaderFooter.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructs a RtfHeaderFooter based on a HeaderFooter with a certain type and displayAt
 * location. For internal use only.
 * 
 * @param doc The RtfDocument this RtfHeaderFooter belongs to
 * @param headerFooter The HeaderFooter to base this RtfHeaderFooter on
 * @param type The type of RtfHeaderFooter
 * @param displayAt The display location of this RtfHeaderFooter
 */
protected RtfHeaderFooter(RtfDocument doc, HeaderFooter headerFooter, int type, int displayAt) {
    super(new Phrase(""), false);
    this.document = doc;
    this.type = type;
    this.displayAt = displayAt;
    Paragraph par = new Paragraph();
    par.setAlignment(headerFooter.alignment());
    if (headerFooter.getBefore() != null) {
        par.add(headerFooter.getBefore());
    }
    if (headerFooter.isNumbered()) {
        par.add(new RtfPageNumber(this.document));
    }
    if (headerFooter.getAfter() != null) {
        par.add(headerFooter.getAfter());
    }
    try {
        this.content = new Object[1];
        if(this.document != null) {
            this.content[0] = this.document.getMapper().mapElement(par)[0];
            ((RtfBasicElement) this.content[0]).setInHeader(true);
        } else {
            this.content[0] = par;
        }
    } catch(DocumentException de) {
        de.printStackTrace();
    }
}
 
Example #12
Source File: PdfDocument.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Changes the footer of this document.
 *
 * @param footer the new footer
 */
@Override
public void setFooter(HeaderFooter footer) {
	if (writer != null && writer.isPaused()) {
		return;
	}
	super.setFooter(footer);
}
 
Example #13
Source File: PdfDocument.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Changes the footer of this document.
 *
 * @param	footer		the new footer
 */
public void setFooter(HeaderFooter footer) {
    if (writer != null && writer.isPaused()) {
        return;
    }
    super.setFooter(footer);
}
 
Example #14
Source File: PdfDocument.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Changes the header of this document.
 *
 * @param header the new header
 */
public void setHeader(HeaderFooter header) {
    if (writer != null && writer.isPaused()) {
        return;
    }
    super.setHeader(header);
}
 
Example #15
Source File: RtfHeaderFooterGroup.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructs a RtfHeaderGroup for a certain HeaderFooter
 * 
 * @param doc The RtfDocument this RtfHeaderFooter belongs to
 * @param headerFooter The HeaderFooter to display
 * @param type The type of RtfHeaderFooterGroup to create
 */
public RtfHeaderFooterGroup(RtfDocument doc, HeaderFooter headerFooter, int type) {
    super(new Phrase(""), false);
    this.document = doc;
    this.type = type;
    this.mode = MODE_SINGLE;
    headerAll = new RtfHeaderFooter(doc, headerFooter, type, RtfHeaderFooter.DISPLAY_ALL_PAGES);
    headerAll.setType(this.type);
}
 
Example #16
Source File: HtmlWriter.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Changes the footer of this document.
 *
 * @param footer the new footer
 */

@Override
public void setFooter(HeaderFooter footer) {
	this.footer = footer;
}
 
Example #17
Source File: HTMLWorker.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void setFooter(HeaderFooter footer) {
}
 
Example #18
Source File: HTMLWorker.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void setHeader(HeaderFooter header) {
}
 
Example #19
Source File: HTMLWorker.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void setFooter(HeaderFooter footer) {
}
 
Example #20
Source File: HTMLWorker.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void setHeader(HeaderFooter header) {
}
 
Example #21
Source File: HTMLWorker.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void setFooter(HeaderFooter footer) {
}
 
Example #22
Source File: HTMLWorker.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void setHeader(HeaderFooter header) {
}
 
Example #23
Source File: HtmlWriter.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Changes the header of this document.
 *
 * @param header the new header
 */

@Override
public void setHeader(HeaderFooter header) {
	this.header = header;
}
 
Example #24
Source File: HTMLWorker.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setHeader(HeaderFooter header) {
}
 
Example #25
Source File: HTMLWorker.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setFooter(HeaderFooter footer) {
}
 
Example #26
Source File: HtmlWriter.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
* Changes the footer of this document.
*
* @param footer    the new footer
*/
   
   public void setFooter(HeaderFooter footer) {
       this.footer = footer;
   }
 
Example #27
Source File: HtmlWriter.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
* Changes the header of this document.
*
* @param header    the new header
*/
   
   public void setHeader(HeaderFooter header) {
       this.header = header;
   }
 
Example #28
Source File: RtfDocumentHeader.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Sets the current footer to use
 * 
 * @param footer The HeaderFooter to use as footer
 */
public void setFooter(HeaderFooter footer) {
    this.footer = footer;
}
 
Example #29
Source File: RtfDocumentHeader.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Sets the current header to use
 * 
 * @param header The HeaderFooter to use as header
 */
public void setHeader(HeaderFooter header) {
    this.header = header;
}
 
Example #30
Source File: PatchRtfWriter2.java    From pentaho-reporting with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Sets the header to use
 *
 * @param hf
 *          The HeaderFooter to use
 */
public void setHeader( HeaderFooter hf ) {
  this.rtfDoc.getDocumentHeader().setHeader( hf );
}