com.lowagie.text.Chunk Java Examples

The following examples show how to use com.lowagie.text.Chunk. 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: PdfWebTable.java    From unitime with Apache License 2.0 6 votes vote down vote up
private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color, Color bgColor) {
	Font font = PdfFont.getFont(bold, italic, underline, color);
	Chunk chunk = new Chunk(text, font);
	if (bgColor!=null) chunk.setBackground(bgColor);
	if (cell.getPhrase()==null) {
	    cell.setPhrase(new Paragraph(chunk));
		cell.setVerticalAlignment(Element.ALIGN_TOP);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	} else {
		cell.getPhrase().add(chunk);
	}
	float width = 0; 
	if (text.indexOf('\n')>=0) {
		for (StringTokenizer s = new StringTokenizer(text,"\n"); s.hasMoreTokens();)
			width = Math.max(width,font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
	} else 
		width = Math.max(width,font.getBaseFont().getWidthPoint(text, font.getSize()));
	return width;
}
 
Example #2
Source File: CustomerLoadServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void writeFileNameSectionTitle(Document pdfDoc, String filenameLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_LEFT);
    Chunk chunk = new Chunk(filenameLine, font);
    chunk.setBackground(Color.LIGHT_GRAY, 5, 5, 5, 5);
    paragraph.add(chunk);

    //  blank line
    paragraph.add(new Chunk("", font));

    try {
        pdfDoc.add(paragraph);
    }
    catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}
 
Example #3
Source File: RtfDestinationDocument.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean handleCloseGroup() {
	this.onCloseGroup();	// event handler
	
	if(this.rtfParser.isImport()) {
		if(this.buffer.length()>0) {
			writeBuffer();
		}
		writeText("}");
	}
	if(this.rtfParser.isConvert()) {
		if(this.buffer.length() > 0 && this.iTextParagraph == null) {
			this.iTextParagraph = new Paragraph();
		}
		if(this.buffer.length() > 0 ) {
			Chunk chunk = new Chunk();
			chunk.append(this.buffer.toString());
			this.iTextParagraph.add(chunk);
		}
		if(this.iTextParagraph != null) {
			addParagraphToDocument();
		}
	}
	return true;
}
 
Example #4
Source File: JavaScriptActionTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a document with a javascript action.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("JavaScriptAction.pdf"));
	// step 3: we add Javascript as Metadata and we open the document
	document.open();
	// step 4: we add some content
	Paragraph p = new Paragraph(new Chunk("Click to say Hello").setAction(PdfAction.javaScript(
			"app.alert('Hello');\r", writer)));
	document.add(p);

	// step 5: we close the document
	document.close();

}
 
Example #5
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeMemoryInformations(MemoryInformations memoryInformations)
		throws BadElementException, IOException {
	addCell(memoryInformations.getMemoryDetails().replace(" Mo", ' ' + getString("Mo")));
	final long usedPermGen = memoryInformations.getUsedPermGen();
	if (usedPermGen > 0) {
		// perm gen est à 0 sous jrockit
		final long maxPermGen = memoryInformations.getMaxPermGen();
		addCell(getString("Memoire_Perm_Gen") + ':');
		if (maxPermGen > 0) {
			final Phrase permGenPhrase = new Phrase(
					integerFormat.format(usedPermGen / 1024 / 1024) + ' ' + getString("Mo")
							+ DIVIDE + integerFormat.format(maxPermGen / 1024 / 1024) + ' '
							+ getString("Mo") + BAR_SEPARATOR,
					cellFont);
			final Image permGenImage = Image.getInstance(
					Bar.toBarWithAlert(memoryInformations.getUsedPermGenPercentage()), null);
			permGenImage.scalePercent(50);
			permGenPhrase.add(new Chunk(permGenImage, 0, 0));
			currentTable.addCell(permGenPhrase);
		} else {
			addCell(integerFormat.format(usedPermGen / 1024 / 1024) + ' ' + getString("Mo"));
		}
	}
}
 
Example #6
Source File: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void setAnchor(Chunk chunk, JRPrintAnchor anchor, JRPrintElement element)
{
	String anchorName = anchor.getAnchorName();
	if (anchorName != null)
	{
		chunk.setLocalDestination(anchorName);

		if (anchor.getBookmarkLevel() != JRAnchor.NO_BOOKMARK)
		{
			int x = OrientationEnum.PORTRAIT.equals(pageFormat.getOrientation()) 
					? getOffsetX() + element.getX() 
					: getOffsetY() + element.getY();
			int y = OrientationEnum.PORTRAIT.equals(pageFormat.getOrientation()) 
					? getOffsetY() + element.getY() 
					: getOffsetX() + element.getX();
			addBookmark(anchor.getBookmarkLevel(), anchor.getAnchorName(), x, y);
		}
	}
}
 
Example #7
Source File: RtfChunk.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructs a RtfChunk based on the content of a Chunk
 * 
 * @param doc The RtfDocument that this Chunk belongs to
 * @param chunk The Chunk that this RtfChunk is based on
 */
public RtfChunk(RtfDocument doc, Chunk chunk) {
    super(doc);
    
    if(chunk == null) {
        return;
    }
    
    if(chunk.getAttributes() != null && chunk.getAttributes().get(Chunk.SUBSUPSCRIPT) != null) {
        this.superSubScript = ((Float)chunk.getAttributes().get(Chunk.SUBSUPSCRIPT)).floatValue();
    }
    if(chunk.getAttributes() != null && chunk.getAttributes().get(Chunk.BACKGROUND) != null) {
        this.background = new RtfColor(this.document, (Color) ((Object[]) chunk.getAttributes().get(Chunk.BACKGROUND))[0]);
    }
    font = new RtfFont(doc, chunk.getFont());
    content = chunk.getContent();
}
 
Example #8
Source File: CustomerInvoiceWriteoffBatchServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void writeInvoiceSectionMessage(com.lowagie.text.Document pdfDoc, String resultLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT);
    paragraph.add(new Chunk(resultLine, font));

    //  blank line
    paragraph.add(new Chunk("", font));

    try {
        pdfDoc.add(paragraph);
    }
    catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}
 
Example #9
Source File: InvestmentSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
    Document pdf = (Document) document; 
    pdf.setPageSize(PageSize.A3); 
    pdf.open();  
     
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
    String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png";  
    Image image=Image.getInstance(logo);
    image.scaleAbsolute(100f, 50f);
    pdf.add(image); 
    // add a couple of blank lines
       pdf.add( Chunk.NEWLINE );
       pdf.add( Chunk.NEWLINE );
    Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
    fontbold.setColor(55, 55, 55);;
    pdf.add(new Paragraph("Investment Summary",fontbold));
    // add a couple of blank lines
    pdf.add( Chunk.NEWLINE );
    pdf.add( Chunk.NEWLINE );
}
 
Example #10
Source File: PdfPCell.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructs a <CODE>PdfPCell</CODE> with an <CODE>Image</CODE>.
 * The default padding is 0.25 for a border width of 0.5.
 * 
 * @param image the <CODE>Image</CODE>
 * @param fit <CODE>true</CODE> to fit the image to the cell
 */
public PdfPCell(Image image, boolean fit) {
    super(0, 0, 0, 0);
    borderWidth = 0.5f;
    border = BOX;
    if (fit) {
        this.image = image;
        column.setLeading(0, 1);
        setPadding(borderWidth / 2);
    }
    else {
        column.addText(this.phrase = new Phrase(new Chunk(image, 0, 0)));
        column.setLeading(0, 1);
        setPadding(0);
    }
}
 
Example #11
Source File: CustomerLoadServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void writeCustomerSectionTitle(Document pdfDoc, String customerNameLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD + Font.UNDERLINE);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_LEFT);
    paragraph.add(new Chunk(customerNameLine, font));

    //  blank line
    paragraph.add(new Chunk("", font));

    try {
        pdfDoc.add(paragraph);
    }
    catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}
 
Example #12
Source File: PdfPCell.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Constructs a <CODE>PdfPCell</CODE> with an <CODE>Image</CODE>.
 * The default padding is 0.25 for a border width of 0.5.
 * 
 * @param image the <CODE>Image</CODE>
 * @param fit <CODE>true</CODE> to fit the image to the cell
 */
public PdfPCell(Image image, boolean fit) {
    super(0, 0, 0, 0);
    borderWidth = 0.5f;
    border = BOX;
    if (fit) {
        this.image = image;
        column.setLeading(0, 1);
        setPadding(borderWidth / 2);
    }
    else {
        column.addText(this.phrase = new Phrase(new Chunk(image, 0, 0)));
        column.setLeading(0, 1);
        setPadding(0);
    }
}
 
Example #13
Source File: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void writePageAnchor(int pageIndex) throws DocumentException 
{
	Map<Attribute,Object> attributes = new HashMap<Attribute,Object>();
	fontUtil.getAttributesWithoutAwtFont(attributes, new JRBasePrintText(jasperPrint.getDefaultStyleProvider()));
	Font pdfFont = getFont(attributes, getLocale(), false);
	Chunk chunk = new Chunk(" ", pdfFont);
	
	chunk.setLocalDestination(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1));

	tagHelper.startPageAnchor();
	
	ColumnText colText = new ColumnText(pdfContentByte);
	colText.setSimpleColumn(
		new Phrase(chunk),
		0,
		pageFormat.getPageHeight(),
		1,
		1,
		0,
		Element.ALIGN_LEFT
		);

	colText.go();

	tagHelper.endPageAnchor();
}
 
Example #14
Source File: CustomerInvoiceWriteoffBatchServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void writeInvoiceSectionTitle(com.lowagie.text.Document pdfDoc, String customerNameLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD + Font.UNDERLINE);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(com.lowagie.text.Element.ALIGN_LEFT);
    paragraph.add(new Chunk(customerNameLine, font));

    //  blank line
    paragraph.add(new Chunk("", font));

    try {
        pdfDoc.add(paragraph);
    }
    catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}
 
Example #15
Source File: PdfWebTable.java    From unitime with Apache License 2.0 6 votes vote down vote up
private float addImage(PdfPCell cell, String name) {
	try {
		java.awt.Image awtImage = (java.awt.Image)iImages.get(name);
		if (awtImage==null) return 0;
		Image img = Image.getInstance(awtImage, Color.WHITE);
		Chunk ck = new Chunk(img, 0, 0);
		if (cell.getPhrase()==null) {
			cell.setPhrase(new Paragraph(ck));
			cell.setVerticalAlignment(Element.ALIGN_TOP);
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		} else {
			cell.getPhrase().add(ck);
		}
		return awtImage.getWidth(null);
	} catch (Exception e) {
		return 0;
	}
}
 
Example #16
Source File: CustomerLoadServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void writeCustomerSectionResult(Document pdfDoc, String resultLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_LEFT);
    paragraph.add(new Chunk(resultLine, font));

    //  blank line
    paragraph.add(new Chunk("", font));

    try {
        pdfDoc.add(paragraph);
    }
    catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}
 
Example #17
Source File: NewPageTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a PDF document with different pages.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file

	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("NewPage.pdf"));

	// step 3: we open the document
	document.open();

	// step 4:
	document.add(new Paragraph("This is the first page."));
	document.newPage();
	document.add(new Paragraph("This is a new page"));
	document.newPage();
	document.newPage();
	document.add(new Paragraph(
			"We invoked new page twice, yet there was no blank page added. Between the second page and this one. This is normal behaviour."));
	document.newPage();
	writer.setPageEmpty(false);
	document.newPage();
	document.add(new Paragraph("We told the writer the page wasn't empty."));
	document.newPage();
	document.add(Chunk.NEWLINE);
	document.newPage();
	document.add(new Paragraph("You can also add something invisible if you want a blank page."));
	document.add(Chunk.NEXTPAGE);
	document.add(new Paragraph("Using Chunk.NEXTPAGE also jumps to the next page"));

	// step 5: we close the document
	document.close();
}
 
Example #18
Source File: OutSimplePdf.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Performs the action: generate a PDF from a GET or POST.
 * 
 * @param request	the Servlets request object
 * @param response	the Servlets request object
 * @param methodGetPost	the method that was used in the form
 */
public void makePdf(HttpServletRequest request, HttpServletResponse response, String methodGetPost) {
	try {

		// take the message from the URL or create default message
		String msg = request.getParameter("msg");
		if (msg == null || msg.trim().length() <= 0)
			msg = "[ specify a message in the 'msg' argument on the URL ]";

		// create simple doc and write to a ByteArrayOutputStream
		Document document = new Document();
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		PdfWriter.getInstance(document, baos);
		document.open();
		document.add(new Paragraph(msg));
		document.add(Chunk.NEWLINE);
		document.add(new Paragraph("The method used to generate this PDF was: " + methodGetPost));
		document.close();

		// setting some response headers
		response.setHeader("Expires", "0");
		response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
		response.setHeader("Pragma", "public");
		// setting the content type
		response.setContentType("application/pdf");
		// the contentlength is needed for MSIE!!!
		response.setContentLength(baos.size());
		// write ByteArrayOutputStream to the ServletOutputStream
		ServletOutputStream out = response.getOutputStream();
		baos.writeTo(out);
		out.flush();

	} catch (Exception e2) {
		System.out.println("Error in " + getClass().getName() + "\n" + e2);
	}
}
 
Example #19
Source File: FactoryProperties.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Chunk createChunk(String text, ChainedProperties props) {
	Font font = getFont(props);
	float size = font.getSize();
	size /= 2;
	Chunk ck = new Chunk(text, font);
	if (props.hasProperty("sub"))
		ck.setTextRise(-size);
	else if (props.hasProperty("sup"))
		ck.setTextRise(size);
	ck.setHyphenation(getHyphenation(props));
	return ck;
}
 
Example #20
Source File: ActionsTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a document with some goto actions.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();
	Document remote = new Document();

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Actions.pdf"));
	PdfWriter.getInstance(remote, PdfTestBase.getOutputStream("remote.pdf"));
	// step 3:
	document.open();
	remote.open();
	// step 4: we add some content
	PdfAction action = PdfAction.gotoLocalPage(2, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), writer);
	writer.setOpenAction(action);
	document.add(new Paragraph("Page 1"));
	document.newPage();
	document.add(new Paragraph("Page 2"));
	document.add(new Chunk("goto page 1").setAction(PdfAction.gotoLocalPage(1, new PdfDestination(
			PdfDestination.FITH, 500), writer)));
	document.add(Chunk.NEWLINE);
	document.add(new Chunk("goto another document").setAction(PdfAction.gotoRemotePage("remote.pdf", "test", false,
			true)));
	remote.add(new Paragraph("Some remote document"));
	remote.newPage();
	Paragraph p = new Paragraph("This paragraph contains a ");
	p.add(new Chunk("local destination").setLocalDestination("test"));
	remote.add(p);

	// step 5: we close the document
	document.close();
	remote.close();
}
 
Example #21
Source File: PdfOutline.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructs a <CODE>PdfOutline</CODE>.
 * <P>
 * This is the constructor for an <CODE>outline entry</CODE>.
 *
 * @param parent the parent of this outline item
 * @param action the <CODE>PdfAction</CODE> for this outline item
 * @param title the title of this outline item
 * @param open <CODE>true</CODE> if the children are visible
 */
public PdfOutline(PdfOutline parent, PdfAction action, Paragraph title, boolean open) {
    super();
    StringBuffer buf = new StringBuffer();
    for (Iterator i = title.getChunks().iterator(); i.hasNext(); ) {
        Chunk chunk = (Chunk) i.next();
        buf.append(chunk.content());
    }
    this.action = action;
    initOutline(parent, buf.toString(), open);
}
 
Example #22
Source File: Coversheet.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates instructions section of the coverpage
 *
 * @returns a {@link Paragraph} for the PDF
 */
protected Paragraph getInstructionsParagraph() {
    final Font headerFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    final Paragraph retval = new Paragraph();
    retval.add(new Chunk("Instructions", headerFont));
    retval.add(Chunk.NEWLINE);
    retval.add(new Phrase(getInstructions(), normalFont));
    return retval;
}
 
Example #23
Source File: HelloWorldMultipleTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Generates simple PDF, RTF and HTML files using only one Document object.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();
	// step 2:
	// we create 3 different writers that listen to the document
	PdfWriter pdf = PdfWriter.getInstance(document,PdfTestBase.getOutputStream("HelloWorldPdf.pdf"));
	RtfWriter2 rtf = RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("HelloWorldRtf.rtf"));
	HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("HelloWorldHtml.html"));

	// step 3: we open the document
	document.open();
	// step 4: we add a paragraph to the document
	document.add(new Paragraph("Hello World"));
	// we make references
	Anchor pdfRef = new Anchor("see Hello World in PDF.");
	pdfRef.setReference("./HelloWorldPdf.pdf");
	Anchor rtfRef = new Anchor("see Hello World in RTF.");
	rtfRef.setReference("./HelloWorldRtf.rtf");

	// we add the references, but only to the HTML page:

	pdf.pause();
	rtf.pause();
	document.add(pdfRef);
	document.add(Chunk.NEWLINE);
	document.add(rtfRef);
	pdf.resume();
	rtf.resume();

	// step 5: we close the document
	document.close();
}
 
Example #24
Source File: IndexEvents.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create an index entry.
 *
 * @param text  The text.
 * @param in1   The first level.
 * @param in2   The second level.
 * @param in3   The third level.
 */
public void create(final Chunk text, final String in1, final String in2,
        final String in3) {

    String tag = "idx_" + (indexcounter++);
    text.setGenericTag(tag);
    text.setLocalDestination(tag);
    Entry entry = new Entry(in1, in2, in3, tag);
    indexentry.add(entry);
}
 
Example #25
Source File: TransactionSummaryController.java    From primefaces-blueprints with The Unlicense 5 votes vote down vote up
public void postProcessPDF(Object document) throws IOException,
		BadElementException, DocumentException {
	Document pdf = (Document) document;
	pdf.add(Chunk.NEWLINE);
	Font fontbold = FontFactory.getFont("Times-Roman", 14, Font.BOLD);
	pdf.add(new Paragraph("Disclaimer", fontbold));
	pdf.add(Chunk.NEWLINE);
	pdf.add(new Paragraph(
			"The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice."));
	pdf.add(new Paragraph(
			"This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. "));
}
 
Example #26
Source File: PdfExamGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void addText(PdfPCell cell, String text, boolean bold) {
    if (text==null) return;
    if (text.indexOf("<span")>=0)
        text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
    text = text.replaceAll("<br>", "\n");
    text = text.replaceAll("<BR>", "\n");
    if (cell.getPhrase()==null) {
        cell.setPhrase(new Paragraph(text, PdfFont.getFont(bold)));
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    } else {
        cell.getPhrase().add(new Chunk("\n"+text, PdfFont.getFont(bold)));
    }
}
 
Example #27
Source File: SurveyPdf.java    From JDeSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeAnswer(Document document,String questionText , boolean answerValue , 
						 String falseMessage,String trueMessage) throws Exception{
	
	
	//String falseString ="False";  
	//String trueString = "True";
	
	Paragraph questionParagraph = new Paragraph();
	questionParagraph.setLeading(14, 0);
	questionParagraph.add(new Chunk(questionText.trim() + ": ",boldedFont)); 
    questionParagraph.add(new Chunk(answerValue ? trueMessage : falseMessage ,normalFont));  
	document.add(questionParagraph);
}
 
Example #28
Source File: ColumnText.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Adds a <CODE>Phrase</CODE> to the current text array.
 * Will not have any effect if addElement() was called before.
 * 
 * @param phrase the text
 */
public void addText(Phrase phrase) {
    if (phrase == null || composite)
        return;
    addWaitingPhrase();
    if (bidiLine == null) {
        waitPhrase = phrase;
        return;
    }
    for (Iterator j = phrase.getChunks().iterator(); j.hasNext();) {
        bidiLine.addChunk(new PdfChunk((Chunk)j.next(), null));
    }
}
 
Example #29
Source File: PdfCounterRequestContextReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeDurations(List<CounterRequestContext> contexts)
		throws DocumentException, IOException {
	getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

	final Paragraph paragraph = new Paragraph("", cellFont);
	boolean first = true;
	for (final CounterRequestContext context : contexts) {
		if (!first) {
			paragraph.add(new Chunk('\n', cellFont));
		}
		final int duration = context.getDuration(timeOfSnapshot);
		final Counter parentCounter = context.getParentCounter();
		final PdfCounterReport counterReport = counterReportsByCounterName
				.get(parentCounter.getName());
		if (parentCounter.getIconName() != null) {
			paragraph.add(new Chunk(getImage(parentCounter.getIconName()), 0, -1));
		}
		final Font slaFont;
		if (counterReport == null) {
			slaFont = infoCellFont;
		} else {
			slaFont = counterReport.getSlaFont(duration);
		}
		paragraph.add(new Phrase(integerFormat.format(duration), slaFont));
		first = false;
	}
	addCell(paragraph);
}
 
Example #30
Source File: PdfChunk.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Correction for the tab position based on the left starting position.
 * @param	newValue	the new value for the left X.
 * @since	2.1.2
 */
void adjustLeft(float newValue) {
	Object[] o = (Object[])attributes.get(Chunk.TAB);
	if (o != null) {
		attributes.put(Chunk.TAB, new Object[]{o[0], o[1], o[2], new Float(newValue)});
	}
}