Java Code Examples for com.lowagie.text.Paragraph#setAlignment()
The following examples show how to use
com.lowagie.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: PdfThreadInformationsReport.java From javamelody with Apache License 2.0 | 6 votes |
@Override void toPdf() throws DocumentException, IOException { writeHeader(); for (final ThreadInformations threadInformations : threadInformationsList) { nextRow(); writeThreadInformations(threadInformations); } addTableToDocument(); final Paragraph tempsThreads = new Paragraph(getString("Temps_threads") + '\n', cellFont); tempsThreads.setAlignment(Element.ALIGN_RIGHT); addToDocument(tempsThreads); // rq stack-trace: on n'inclue pas dans le pdf les stack-traces des threads // car c'est très verbeux et cela remplirait des pages pour pas grand chose // d'autant que si le pdf est généré de nuit pour être envoyé par mail // alors ces stack-traces n'ont pas beaucoup d'intérêt // if (stackTrace != null && !stackTrace.isEmpty()) { // // même si stackTraceEnabled, ce thread n'a pas forcément de stack-trace // writeln(threadInformations.getName()); // for (final StackTraceElement stackTraceElement : stackTrace) { // writeln(stackTraceElement.toString()); // } // } }
Example 2
Source File: CustomerInvoiceWriteoffBatchServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
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 3
Source File: PdfCounterReport.java From javamelody with Apache License 2.0 | 6 votes |
private void writeFooter() throws DocumentException { final List<CounterRequest> requests = counterRequestAggregation.getRequests(); final CounterRequest globalRequest = counterRequestAggregation.getGlobalRequest(); // delta ni négatif ni à 0 final long deltaMillis = Math .max(System.currentTimeMillis() - counter.getStartDate().getTime(), 1); final long hitsParMinute = 60 * 1000 * globalRequest.getHits() / deltaMillis; final String key; if (isJobCounter()) { key = "nb_jobs"; } else if (isErrorCounter()) { key = "nb_erreurs"; } else { key = "nb_requetes"; } final Paragraph footer = new Paragraph(getFormattedString(key, integerFormat.format(hitsParMinute), integerFormat.format(requests.size())), normalFont); footer.setAlignment(Element.ALIGN_RIGHT); addToDocument(footer); }
Example 4
Source File: SpaceWordRatioTest.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Space Word Ratio. */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 350, 50, 50); // step 2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("spacewordratio.pdf")); // step 3 document.open(); // step 4 String text = "Flanders International Filmfestival Ghent - Internationaal Filmfestival van Vlaanderen Gent"; Paragraph p = new Paragraph(text); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.newPage(); writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO); document.add(p); // step 5 document.close(); }
Example 5
Source File: RtfHeaderFooter.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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 6
Source File: CustomerLoadServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
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 7
Source File: Coversheet.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * @see org.kuali.kfs.module.tem.pdf.PdfStream#print(java.io.OutputStream) * @throws Exception */ @Override public void print(final OutputStream stream) throws Exception { final Font titleFont = FontFactory.getFont(FontFactory.HELVETICA, 20, Font.BOLD); final Font headerFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); final Document doc = new Document(); final PdfWriter writer = PdfWriter.getInstance(doc, stream); doc.open(); if(getDocumentNumber()!=null){ Image image=Image.getInstance(new BarcodeHelper().generateBarcodeImage(getDocumentNumber()),null); doc.add(image); } final Paragraph title = new Paragraph("TEM Coversheet", titleFont); doc.add(title); final Paragraph faxNumber = new Paragraph("Fax this page to " + SpringContext.getBean(ParameterService.class).getParameterValueAsString(TravelReimbursementDocument.class, FAX_NUMBER), normalFont); doc.add(faxNumber); final Paragraph header = new Paragraph("", headerFont); header.setAlignment(ALIGN_RIGHT); header.add("Document Number: " + getDocumentNumber()); doc.add(header); doc.add(getInstructionsParagraph()); doc.add(getMailtoParagraph()); doc.add(Chunk.NEWLINE); doc.add(getTripInfo()); doc.add(Chunk.NEWLINE); doc.add(getPersonalInfo()); doc.add(Chunk.NEWLINE); doc.add(getExpenses()); drawAlignmentMarks(writer.getDirectContent()); doc.close(); writer.close(); }
Example 8
Source File: StatisticsPdf.java From JDeSurvey with GNU Affero General Public License v3.0 | 5 votes |
private void writeSubTitle(Document document,String title) throws Exception{ Paragraph titleParagraph = new Paragraph(title,subTitleFont); titleParagraph.setAlignment(Element.ALIGN_LEFT); titleParagraph.setLeading(20); titleParagraph.setSpacingAfter(2); document.add(titleParagraph); }
Example 9
Source File: DocStyleUtils.java From DWSurvey with GNU Affero General Public License v3.0 | 5 votes |
/** * 功能说明:设置段落的样式,设置前半截内容和后半截内容格式不一样的段落样式</BR> * 修改日:2011-04-27 * @author myclover * @param content 前半截内容 * @param font 字体的样式 * @param firstLineIndent 首行缩进多少字符,16f约等于一个字符 * @param appendStr 后半截内容 * @return */ public static Paragraph setParagraphStyle(String content , Font font , float firstLineIndent , String appendStr){ Paragraph par = setParagraphStyle(content, font, 0f, 12f); Phrase phrase = new Phrase(); phrase.add(par); phrase.add(appendStr); Paragraph paragraph = new Paragraph(phrase); paragraph.setFirstLineIndent(firstLineIndent); //设置对齐方式为两端对齐 paragraph.setAlignment(Paragraph.ALIGN_JUSTIFIED_ALL); return paragraph; }
Example 10
Source File: StatisticsPdf.java From JDeSurvey with GNU Affero General Public License v3.0 | 5 votes |
private void writeTitle(Document document,String title) throws Exception{ Paragraph titleParagraph = new Paragraph(title,titleFont); titleParagraph.setAlignment(Element.ALIGN_LEFT); titleParagraph.setLeading(30); titleParagraph.setSpacingAfter(2); document.add(titleParagraph); }
Example 11
Source File: MultiColumnSimpleTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
private static Element newPara(String text, int alignment, int type) { Font font = FontFactory.getFont("Helvetica", 10, type, Color.BLACK); Paragraph p = new Paragraph(text, font); p.setAlignment(alignment); p.setLeading(font.getSize() * 1.2f); return p; }
Example 12
Source File: MultiColumnR2LTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
private static Element newPara(String text, int alignment, int type) { Font font = FontFactory.getFont("Helvetica", 10, type, Color.BLACK); Paragraph p = new Paragraph(text, font); p.setAlignment(alignment); p.setLeading(font.getSize() * 1.2f); return p; }
Example 13
Source File: PageNumberTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Demonstrates creating a footer with the current page number * * */ @Test public void main() throws Exception { Document document = new Document(); RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("PageNumber.rtf")); // Create a new Paragraph for the footer Paragraph par = new Paragraph("Page "); par.setAlignment(Element.ALIGN_RIGHT); // Add the RtfPageNumber to the Paragraph par.add(new RtfPageNumber()); // Create an RtfHeaderFooter with the Paragraph and set it // as a footer for the document RtfHeaderFooter footer = new RtfHeaderFooter(par); document.setFooter(footer); document.open(); for (int i = 1; i <= 300; i++) { document.add(new Paragraph("Line " + i + ".")); } document.close(); }
Example 14
Source File: MRtfWriter.java From javamelody with Apache License 2.0 | 5 votes |
/** * 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 15
Source File: PdfProcessInformationsReport.java From javamelody with Apache License 2.0 | 5 votes |
private void addPsCommandReference() throws DocumentException { final Anchor psAnchor = new Anchor("ps command reference", PdfFonts.BLUE.getFont()); psAnchor.setName("ps command reference"); psAnchor.setReference("http://en.wikipedia.org/wiki/Ps_(Unix)"); psAnchor.setFont(PdfFonts.BLUE.getFont()); final Paragraph psParagraph = new Paragraph(); psParagraph.add(psAnchor); psParagraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(psParagraph); }
Example 16
Source File: MarkupParser.java From MesquiteCore with GNU Lesser General Public License v3.0 | 4 votes |
/** * Retrieves a Paragraph based on some style attributes. * @param font * @param styleattributes a Properties object containing keys and values * @return an iText Paragraph object */ public Element retrieveParagraph(Font font, Properties styleattributes) { Paragraph p = new Paragraph((Phrase)retrievePhrase(font, styleattributes)); if (styleattributes == null) return p; String margin = styleattributes.getProperty(MarkupTags.CSS_KEY_MARGIN); float f; if (margin != null) { f = parseLength(margin); p.setIndentationLeft(f); p.setIndentationRight(f); p.setSpacingBefore(f); p.setSpacingAfter(f); } margin = styleattributes.getProperty(MarkupTags.CSS_KEY_MARGINLEFT); if (margin != null) { f = parseLength(margin); p.setIndentationLeft(f); } margin = styleattributes.getProperty(MarkupTags.CSS_KEY_MARGINRIGHT); if (margin != null) { f = parseLength(margin); p.setIndentationRight(f); } margin = styleattributes.getProperty(MarkupTags.CSS_KEY_MARGINTOP); if (margin != null) { f = parseLength(margin); p.setSpacingBefore(f); } margin = styleattributes.getProperty(MarkupTags.CSS_KEY_MARGINBOTTOM); if (margin != null) { f = parseLength(margin); p.setSpacingAfter(f); } String align = styleattributes.getProperty(MarkupTags.CSS_KEY_TEXTALIGN); if (MarkupTags.CSS_VALUE_TEXTALIGNLEFT.equals(align)) { p.setAlignment(Element.ALIGN_LEFT); } else if (MarkupTags.CSS_VALUE_TEXTALIGNRIGHT.equals(align)) { p.setAlignment(Element.ALIGN_RIGHT); } else if (MarkupTags.CSS_VALUE_TEXTALIGNCENTER.equals(align)) { p.setAlignment(Element.ALIGN_CENTER); } else if (MarkupTags.CSS_VALUE_TEXTALIGNJUSTIFY.equals(align)) { p.setAlignment(Element.ALIGN_JUSTIFIED); } return p; }
Example 17
Source File: PdfCounterRequestContextReport.java From javamelody with Apache License 2.0 | 4 votes |
private void writeFooter() throws DocumentException { final Paragraph footer = new Paragraph(getFormattedString("nb_requete_en_cours", integerFormat.format(rootCurrentContexts.size())), normalFont); footer.setAlignment(Element.ALIGN_RIGHT); addToDocument(footer); }
Example 18
Source File: TemplateImagesTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * PdfTemplates can be wrapped in an Image. */ @Test public void main() throws Exception { // step 1: creation of a document-object Rectangle rect = new Rectangle(PageSize.A4); rect.setBackgroundColor(new Color(238, 221, 88)); Document document = new Document(rect, 50, 50, 50, 50); // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("templateImages.pdf")); // step 3: we open the document document.open(); // step 4: PdfTemplate template = writer.getDirectContent().createTemplate(20, 20); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); String text = "Vertical"; float size = 16; float width = bf.getWidthPoint(text, size); template.beginText(); template.setRGBColorFillF(1, 1, 1); template.setFontAndSize(bf, size); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); template.setHeight(size + 2); template.sanityCheck(); Image img = Image.getInstance(template); img.setRotationDegrees(90); Chunk ck = new Chunk(img, 0, 0); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell = new PdfPCell(img); cell.setPadding(4); cell.setBackgroundColor(new Color(0, 0, 255)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell("I see a template on my right"); table.addCell(cell); table.addCell("I see a template on my left"); table.addCell(cell); table.addCell("I see a template everywhere"); table.addCell(cell); table.addCell("I see a template on my right"); table.addCell(cell); table.addCell("I see a template on my left"); Paragraph p1 = new Paragraph("This is a template "); p1.add(ck); p1.add(" just here."); p1.setLeading(img.getScaledHeight() * 1.1f); document.add(p1); document.add(table); Paragraph p2 = new Paragraph("More templates "); p2.setLeading(img.getScaledHeight() * 1.1f); p2.setAlignment(Element.ALIGN_JUSTIFIED); img.scalePercent(70); for (int k = 0; k < 20; ++k) p2.add(ck); document.add(p2); // step 5: we close the document document.close(); }
Example 19
Source File: ContractsGrantsInvoiceReportServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
/** * Generates the pdf file for printing the envelopes. * * @param list * @param outputStream * @throws DocumentException * @throws IOException */ protected void generateCombinedPdfForEnvelopes(Collection<ContractsGrantsInvoiceDocument> list, OutputStream outputStream) throws DocumentException, IOException { Document document = new Document(new Rectangle(ArConstants.InvoiceEnvelopePdf.LENGTH, ArConstants.InvoiceEnvelopePdf.WIDTH)); PdfWriter.getInstance(document, outputStream); boolean pageAdded = false; for (ContractsGrantsInvoiceDocument invoice : list) { // add a document for (InvoiceAddressDetail invoiceAddressDetail : invoice.getInvoiceAddressDetails()) { if (ArConstants.InvoiceTransmissionMethod.MAIL.equals(invoiceAddressDetail.getInvoiceTransmissionMethodCode())) { CustomerAddress address = invoiceAddressDetail.getCustomerAddress(); Integer numberOfEnvelopesToPrint = address.getCustomerEnvelopesToPrintQuantity(); if (ObjectUtils.isNull(numberOfEnvelopesToPrint)) { numberOfEnvelopesToPrint = 1; } for (int i = 0; i < numberOfEnvelopesToPrint; i++) { // if a page has not already been added then open the document. if (!pageAdded) { document.open(); } pageAdded = true; document.newPage(); // adding the sent From address Organization org = invoice.getInvoiceGeneralDetail().getAward().getPrimaryAwardOrganization().getOrganization(); Paragraph sentBy = generateAddressParagraph(org.getOrganizationName(), org.getOrganizationLine1Address(), org.getOrganizationLine2Address(), org.getOrganizationCityName(), org.getOrganizationStateCode(), org.getOrganizationZipCode(), ArConstants.PdfReportFonts.ENVELOPE_SMALL_FONT); sentBy.setIndentationLeft(ArConstants.InvoiceEnvelopePdf.INDENTATION_LEFT); sentBy.setAlignment(Element.ALIGN_LEFT); // adding the send To address String string; Paragraph sendTo = generateAddressParagraph(address.getCustomerAddressName(), address.getCustomerLine1StreetAddress(), address.getCustomerLine2StreetAddress(), address.getCustomerCityName(), address.getCustomerStateCode(), address.getCustomerZipCode(), ArConstants.PdfReportFonts.ENVELOPE_TITLE_FONT); sendTo.setAlignment(Element.ALIGN_CENTER); sendTo.add(new Paragraph(KFSConstants.BLANK_SPACE)); document.add(sentBy); document.add(sendTo); } } } } if (pageAdded) { document.close(); } }
Example 20
Source File: ExtendedHeaderFooterTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Extended headers / footers example * * */ @Test public void main() throws Exception { Document document = new Document(); RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendedHeaderFooter.rtf")); // Create the Paragraphs that will be used in the header. Paragraph date = new Paragraph("01.01.2010"); date.setAlignment(Paragraph.ALIGN_RIGHT); Paragraph address = new Paragraph("TheFirm\nTheRoad 24, TheCity\n" + "+00 99 11 22 33 44"); // Create the RtfHeaderFooter with an array containing the Paragraphs to // add RtfHeaderFooter header = new RtfHeaderFooter(new Element[] { date, address }); // Set the header document.setHeader(header); // Create the table that will be used as the footer Table footer = new Table(2); footer.setBorder(0); footer.getDefaultCell().setBorder(0); footer.setWidth(100); footer.addCell(new Cell("(c) Mark Hall")); Paragraph pageNumber = new Paragraph("Page "); // The RtfPageNumber is an RTF specific element that adds a page number // field pageNumber.add(new RtfPageNumber()); pageNumber.setAlignment(Paragraph.ALIGN_RIGHT); footer.addCell(new Cell(pageNumber)); // Create the RtfHeaderFooter and set it as the footer to use document.setFooter(new RtfHeaderFooter(footer)); document.open(); document.add(new Paragraph("This document has headers and footers created" + " using the RtfHeaderFooter class.")); document.close(); }