Java Code Examples for com.itextpdf.text.Paragraph#setAlignment()

The following examples show how to use com.itextpdf.text.Paragraph#setAlignment() . 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: AbstractPdfReportBuilder.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
protected Paragraph createReportTitle(ReportTitle reportTitle) {
	Paragraph paragraph = new Paragraph();
	paragraph.setAlignment(Element.ALIGN_CENTER);
	if (reportTitle != null && reportTitle.isShowTitle()) {
		TextChunk titleChunk = new TextChunk();
		titleChunk.setText(reportTitle.getTitle());
		titleChunk.setFontSize(reportTitle.getStyle().getFontSize());
		titleChunk.setFontColor(reportTitle.getStyle().getFontColor());
		paragraph.add(createChunk(titleChunk));
		paragraph.add(Chunk.NEWLINE);
		paragraph.add(Chunk.NEWLINE);
	}
	return paragraph;
}
 
Example 2
Source File: PDF2TextExample.java    From tutorials with MIT License 6 votes vote down vote up
private static void generatePDFFromTxt(String filename) throws IOException, DocumentException {
	Document pdfDoc = new Document(PageSize.A4);
	PdfWriter.getInstance(pdfDoc, new FileOutputStream("src/output/txt.pdf"))
			.setPdfVersion(PdfWriter.PDF_VERSION_1_7);
	pdfDoc.open();
	
	Font myfont = new Font();
	myfont.setStyle(Font.NORMAL);
	myfont.setSize(11);
	pdfDoc.add(new Paragraph("\n"));
	
	BufferedReader br = new BufferedReader(new FileReader(filename));
	String strLine;
	while ((strLine = br.readLine()) != null) {
		Paragraph para = new Paragraph(strLine + "\n", myfont);
		para.setAlignment(Element.ALIGN_JUSTIFIED);
		pdfDoc.add(para);
	}
	
	pdfDoc.close();
	br.close();
}
 
Example 3
Source File: Helper.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
Paragraph getParagraph(String name, Font font, int alignment) {
    Paragraph paragraph = new Paragraph(name, font);
    if (alignment == PDF_ALIGNMENT_RIGHT)
        paragraph.setAlignment(Element.ALIGN_RIGHT);
    else if (alignment == PDF_ALIGNMENT_CENTER)
        paragraph.setAlignment(Element.ALIGN_CENTER);
    else
        paragraph.setAlignment(Element.ALIGN_LEFT);
    return paragraph;
}
 
Example 4
Source File: RootTitle.java    From xiaoyaoji with GNU General Public License v3.0 5 votes vote down vote up
public RootTitle(Document doc, String title) {
	Paragraph placeHolder = new Paragraph("\n");
	placeHolder.setSpacingAfter(doc.getPageSize().getHeight() * 0.1f);
	add(placeHolder);
	Paragraph p = new Paragraph(title, new Font(BaseInfo.cjkFont, 24f, Font.BOLD, BaseColor.BLACK));
	p.setAlignment(ALIGN_CENTER);
	p.setSpacingAfter(100);
	add(p);
}
 
Example 5
Source File: PdfReportPageNumber.java    From bdf3 with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a header to every page
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	PdfPTable table = new PdfPTable(3);
	try {
		table.setWidths(new int[]{40,5,10});
		table.setTotalWidth(100);
		table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
		Font font=new Font(chineseFont,8);
		font.setColor(new BaseColor(55,55,55));
		Paragraph paragraph=new Paragraph("第   "+writer.getPageNumber()+" 页   共",font);
		paragraph.setAlignment(Element.ALIGN_RIGHT);
		table.addCell(paragraph);
		Image img=Image.getInstance(total);
		img.scaleAbsolute(28, 28);
		PdfPCell cell = new PdfPCell(img);
		cell.setBorder(Rectangle.NO_BORDER);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		PdfPCell c = new PdfPCell(new Paragraph("页",font));
		c.setHorizontalAlignment(Element.ALIGN_LEFT);
		c.setBorder(Rectangle.NO_BORDER);
		table.addCell(c);
		float center=(document.getPageSize().getWidth())/2-120/2;
		table.writeSelectedRows(0, -1,center,30, writer.getDirectContent());
	}
	catch(DocumentException de) {
		throw new ExceptionConverter(de);
	}
}
 
Example 6
Source File: AbstractPdfReportBuilder.java    From bdf3 with Apache License 2.0 4 votes vote down vote up
protected Paragraph createParagraph(TextChunk textChunk) {
	Paragraph paragraph = new Paragraph(textChunk.getText(), createFont(textChunk));
	paragraph.setAlignment(textChunk.getAlign());
	return paragraph;
}