List of usage examples for com.itextpdf.text Chapter addSection
public Section addSection(final Paragraph title)
Section
, adds it to this Section
and returns it. From source file:com.example.drivequickstart.PDFActivity.java
private void addContent(Document document) throws DocumentException { Anchor anchor = new Anchor("ESTIMATING APP", catFont); anchor.setName("ESTIMATING APP"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph("Subcategory 1", subFont); Section subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Hello")); subPara = new Paragraph("Subcategory 2", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Paragraph 1")); subCatPart.add(new Paragraph("Paragraph 2")); subCatPart.add(new Paragraph("Paragraph 3")); try {/*from www. j ava2 s . c om*/ Drawable d = PDFActivity.this.getResources().getDrawable(R.drawable.ic_launcher); Bitmap bitmap = ((BitmapDrawable) d).getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); Image image = Image.getInstance(stream.toByteArray()); subCatPart.add(image); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // Add a list createList(subCatPart); Paragraph paragraph = new Paragraph(); addEmptyLine(paragraph, 5); subCatPart.add(paragraph); // Add a table createTable(subCatPart); // Now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Second Chapter", catFont); anchor.setName("Second Chapter"); // Second parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph("Subcategory", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("This is a very important message")); // Now add all this to the document document.add(catPart); }
From source file:com.example.pdfcreate.MainActivity.java
private static void addContent(Document document) throws DocumentException { Anchor anchor = new Anchor("ESTIMATING APP"); anchor.setName("ESTIMATING APP"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph("Subcategory 1"); Section subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Hello This Is PDF yeeee")); subPara = new Paragraph("Subcategory 2"); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph(str1)); subCatPart.add(new Paragraph(str2)); subCatPart.add(new Paragraph("Paragraph 3")); // Add a list createList(subCatPart);//from www .ja v a 2 s. c om Paragraph paragraph = new Paragraph(); addEmptyLine(paragraph, 5); subCatPart.add(paragraph); // Add a table createTable(subCatPart); // Now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Second Chapter"); anchor.setName("Second Chapter"); // Second parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph("Subcategory"); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("This is a very important message")); // Now add all this to the document document.add(catPart); }
From source file:com.horizzon.inventerium.ExportPdf.java
private static void addContent(Document document) throws DocumentException { Anchor anchor = new Anchor("First Chapter"); anchor.setName("First Chapter"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph("Subcategory 1"); Section subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Hello")); subPara = new Paragraph("Subcategory 2"); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Paragraph 1")); subCatPart.add(new Paragraph("Paragraph 2")); subCatPart.add(new Paragraph("Paragraph 3")); // add a list createList(subCatPart);/*from w ww . j a v a2 s . co m*/ Paragraph paragraph = new Paragraph(); addEmptyLine(paragraph, 5); subCatPart.add(paragraph); // add a table createTable(subCatPart); // now add all this to the document document.add(catPart); // Next section // anchor = new Anchor("Second Chapter", catFont); // anchor.setName("Second Chapter"); // Second parameter is the number of the chapter // catPart = new Chapter(new Paragraph(anchor), 1); // subPara = new Paragraph("Subcategory", subFont); // subCatPart = catPart.addSection(subPara); // subCatPart.add(new Paragraph("This is a very important message")); // now add all this to the document // document.add(catPart); }
From source file:com.imipgroup.hieuvt.pdf.PdfUtils.java
private static void addContent(Document document) { Anchor anchor = new Anchor("First Chapter", catFont); anchor.setName("First Chapter"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph("Subcategory 1", subFont); Section subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Hello")); subPara = new Paragraph("Subcategory 2", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Paragraph 1")); subCatPart.add(new Paragraph("Paragraph 2")); subCatPart.add(new Paragraph("Paragraph 3")); // add a list createList(subCatPart);/*w w w.ja v a 2s. c o m*/ Paragraph paragraph = new Paragraph(); addEmptyLine(paragraph, 5); subCatPart.add(paragraph); // add a table createTable(subCatPart); // now add all this to the document try { document.add(catPart); } catch (DocumentException e) { e.printStackTrace(); } // Next section anchor = new Anchor("Second Chapter", catFont); anchor.setName("Second Chapter"); // Second parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph("Subcategory", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("This is a very important message")); // now add all this to the document try { document.add(catPart); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:com.leenmeij.app.utils.CreatePdf.java
/** * Create the content page of the PDF file * @param document//from w w w . j av a2 s. c o m * @param invoice * @throws DocumentException */ private static void contentPage(Document document, Invoice invoice) throws DocumentException { // Get the customer information User user = new User(); user = user.getById(invoice.getUser_id()); // Create a chapter Chapter catPart = new Chapter(new Paragraph("LeenMeij Factuur gegevens", catFont), 1); // Add a sub paragraph Paragraph subParagraph = new Paragraph("Klantgegevens", subFont); Section subCatPart = catPart.addSection(subParagraph); // Set the user information subCatPart.add(new Paragraph("Naam: " + user.getFirstName() + " " + user.getLastName())); subCatPart.add(new Paragraph("Adres: " + user.getAddressLineOne() + " " + user.getAddressLineTwo())); subCatPart.add(new Paragraph("Woonplaats:" + user.getCity())); subCatPart.add(new Paragraph("Land: " + user.getCountry())); // Add another subparagraph subParagraph = new Paragraph("Huurgegevens:", subFont); subCatPart = catPart.addSection(subParagraph); // Format the date for showing purposes SimpleDateFormat format = new SimpleDateFormat("MM/dd/YYYY"); // Add the dates subCatPart.add(new Paragraph("Startdatum: " + format.format(invoice.getStartdate()))); subCatPart.add(new Paragraph("Einddatum: " + format.format(invoice.getEnddate()))); Paragraph paragraph = new Paragraph(); addEmptyLine(paragraph, 5); subCatPart.add(paragraph); // add a table createTable(subCatPart, invoice); // now add all this to the document document.add(catPart); }
From source file:com.pdg.ticket.utils.FirstPdf.java
private static void addContent(Document document) throws DocumentException { Anchor anchor = new Anchor("First Chapter", catFont); anchor.setName("First Chapter"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph("Subcategory 1", subFont); Section subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Hello")); subPara = new Paragraph("Subcategory 2", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Paragraph 1")); subCatPart.add(new Paragraph("Paragraph 2")); subCatPart.add(new Paragraph("Paragraph 3")); // Add a list //createList(subCatPart); Paragraph paragraph = new Paragraph(); addEmptyLine(paragraph, 5);/*w w w .j av a 2 s.c o m*/ subCatPart.add(paragraph); // Add a table createTable(subCatPart); // Now add all this to the document document.add(catPart); // // Next section // anchor = new Anchor("Second Chapter", catFont); // anchor.setName("Second Chapter"); // // // Second parameter is the number of the chapter // catPart = new Chapter(new Paragraph(anchor), 1); // // subPara = new Paragraph("Subcategory", subFont); // subCatPart = catPart.addSection(subPara); // subCatPart.add(new Paragraph("This is a very important message")); // // // Now add all this to the document // document.add(catPart); }
From source file:com.shashi.itext.write.FirstPdf.java
private static void addContent(Document document) throws DocumentException { Anchor anchor = new Anchor("First Chapter", catFont); anchor.setName("First Chapter"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph("Subcategory 1", subFont); Section subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Hello")); subPara = new Paragraph("Subcategory 2", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Paragraph 1")); subCatPart.add(new Paragraph("Paragraph 2")); subCatPart.add(new Paragraph("Paragraph 3")); // Add a list createList(subCatPart);/*from w w w . j av a2s . c o m*/ Paragraph paragraph = new Paragraph(); addEmptyLine(paragraph, 5); subCatPart.add(paragraph); // Add a table createTable(subCatPart); // Now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Second Chapter", catFont); anchor.setName("Second Chapter"); // Second parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph("Subcategory", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("This is a very important message")); // Now add all this to the document document.add(catPart); }
From source file:com.util.Imprimir.java
public static void addContent(Document document) throws DocumentException { Anchor anchor = new Anchor("Capitulo Primeiro", catFont); anchor.setName("Capitulo Primeiro"); // Second parameter is the number of the chapter Chapter catPart = new Chapter(new Paragraph(anchor), 1); Paragraph subPara = new Paragraph("Subcategoria 1", subFont); Section subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Hello")); subPara = new Paragraph("Subcategoria 2", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("Paragrafo 1")); subCatPart.add(new Paragraph("Paragrafo 2")); subCatPart.add(new Paragraph("Paragrafo 3")); // add a list createList(subCatPart);/*from w w w.java2s. co m*/ Paragraph paragraph = new Paragraph(); addEmptyLine(paragraph, 5); subCatPart.add(paragraph); // add a table createTable(subCatPart); // now add all this to the document document.add(catPart); // Next section anchor = new Anchor("Capitulo Segundo", catFont); anchor.setName("Capitulo Segundo"); // Second parameter is the number of the chapter catPart = new Chapter(new Paragraph(anchor), 1); subPara = new Paragraph("Subcategoria", subFont); subCatPart = catPart.addSection(subPara); subCatPart.add(new Paragraph("This is a very important message")); // now add all this to the document document.add(catPart); }
From source file:com.zaptech.pdfdemo.MainActivity.java
private void addContent(Document document) { try {/*from ww w . j a v a 2 s . c om*/ Anchor anchor = new Anchor("First Chapter", catFont); anchor.setName("First Chapter"); Chapter chapter = new Chapter(new Paragraph(anchor), 1); Paragraph paragraph = new Paragraph("Subcategory 1", subFont); Section section = chapter.addSection(paragraph); section.add(new Paragraph("Hello")); paragraph = new Paragraph("Subcategory 2", subFont); section = chapter.addSection(paragraph); section.add(new Paragraph("Paragraph 1")); section.add(new Paragraph("Paragraph 2")); section.add(new Paragraph("Paragraph 3")); createList(section); Paragraph paragraph1 = new Paragraph(); addEmptyLine(paragraph1, 5); section.add(paragraph1); document.add(chapter); } catch (Exception e) { e.printStackTrace(); } }
From source file:Controller.CrearPDF.java
/** * We create a PDF document with iText using different elements to learn * to use this library.//from w ww. j av a 2 s . c o m * Creamos un documento PDF con iText usando diferentes elementos para aprender * a usar esta librera. * @param pdfNewFile <code>String</code> * pdf File we are going to write. * Fichero pdf en el que vamos a escribir. */ // public void createPDF(File pdfNewFile, ReparacionEntity reparacion) throws Exception { public void createPDF(File pdfNewFile) throws Exception { // We create the document and set the file name. // Creamos el documento e indicamos el nombre del fichero. try { // ClienteController cc = new ClienteController(); // Cliente cliente = cc.buscarPorId(reparacion.getCliente()); Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile)); } catch (FileNotFoundException fileNotFoundException) { System.out.println("No such file was found to generate the PDF " + "(No se encontr el fichero para generar el pdf)" + fileNotFoundException); } document.open(); // We add metadata to PDF // Aadimos los metadatos del PDF document.addTitle("Table export to PDF (Exportamos la tabla a PDF)"); document.addSubject("Using iText (usando iText)"); document.addKeywords("Java, PDF, iText"); document.addAuthor("Cdigo Xules"); document.addCreator("Cdigo Xules"); // First page // Primera pgina Chunk chunk = new Chunk("RDEN DE TRABAJO", categoryFont); Chunk c2 = new Chunk("\n\n\nCentro de Formacin SATCAR6\n" + "Calle Artes Grficas n1 Nave 12 A\n" + "Pinto (28320), Madrid", smallFont); Chunk c3 = new Chunk("Datos del Cliente", smallBold); // Chunk c4 = new Chunk("Nombre: "+cliente.getRazonSocial(),smallBold); // Chunk c5 = new Chunk("Poblacin: "+cliente.getPoblacion(),smallBold); // Chunk c6 = new Chunk("Provincia: "+cliente.getProvincia(),smallBold); // Chunk c7 = new Chunk("Cdigo Postal: "+cliente.getCp(),smallBold); // Chunk c8 = new Chunk("Num Telfono: Pepito"+cliente.getTlf1(),smallBold); Chunk c4 = new Chunk("Nombre: Jesus Eduardo Garcia Toril", smallBold); Chunk c5 = new Chunk("Poblacin: Pinto", smallBold); Chunk c6 = new Chunk("Provincia: Madrid", smallBold); Chunk c7 = new Chunk("Cdigo Postal: 28320", smallBold); Chunk c8 = new Chunk("Num Telfono: 659408182", smallBold); Paragraph parrafo = new Paragraph(chunk); Paragraph p2 = new Paragraph(c2); Paragraph p3 = new Paragraph(c3); Phrase ph1 = new Phrase(c4); Phrase ph2 = new Phrase(c5); Phrase ph3 = new Phrase(c6); Phrase ph4 = new Phrase(c7); Phrase ph5 = new Phrase(c8); // Let's create de first Chapter (Creemos el primer captulo) // We add an image (Aadimos una imagen) Image image; try { parrafo.setAlignment(Element.ALIGN_CENTER); image = Image.getInstance(iTextExampleImage); image.setAbsolutePosition(0, 750); p2.setAlignment(Element.ALIGN_LEFT); document.add(parrafo); document.add(image); document.add(p2); document.add(p3); document.add(ph1); document.add(ph2); document.add(ph3); document.add(ph4); document.add(ph5); } catch (BadElementException ex) { System.out.println("Image BadElementException" + ex); } // Second page - some elements // Segunda pgina - Algunos elementos // List by iText (listas por iText) String text = "test 1 2 3 "; for (int i = 0; i < 5; i++) { text = text + text; } List list = new List(List.UNORDERED); ListItem item = new ListItem(text); item.setAlignment(Element.ALIGN_JUSTIFIED); list.add(item); text = "a b c align "; for (int i = 0; i < 5; i++) { text = text + text; } item = new ListItem(text); item.setAlignment(Element.ALIGN_JUSTIFIED); list.add(item); text = "supercalifragilisticexpialidocious "; for (int i = 0; i < 3; i++) { text = text + text; } item = new ListItem(text); item.setAlignment(Element.ALIGN_JUSTIFIED); list.add(item); // How to use PdfPTable // Utilizacin de PdfPTable // We use various elements to add title and subtitle // Usamos varios elementos para aadir ttulo y subttulo Anchor anchor = new Anchor("Table export to PDF (Exportamos la tabla a PDF)", categoryFont); anchor.setName("Table export to PDF (Exportamos la tabla a PDF)"); Chapter chapTitle = new Chapter(new Paragraph(anchor), 1); Paragraph paragraph = new Paragraph("Do it by Xules (Realizado por Xules)", subcategoryFont); Section paragraphMore = chapTitle.addSection(paragraph); paragraphMore.add(new Paragraph("This is a simple example (Este es un ejemplo sencillo)")); Integer numColumns = 6; Integer numRows = 120; // We create the table (Creamos la tabla). PdfPTable table = new PdfPTable(numColumns); // Now we fill the PDF table // Ahora llenamos la tabla del PDF PdfPCell columnHeader; // Fill table rows (rellenamos las filas de la tabla). for (int column = 0; column < numColumns; column++) { columnHeader = new PdfPCell(new Phrase("COL " + column)); columnHeader.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(columnHeader); } table.setHeaderRows(1); // Fill table rows (rellenamos las filas de la tabla). for (int row = 0; row < numRows; row++) { for (int column = 0; column < numColumns; column++) { table.addCell("Row " + row + " - Col" + column); } } // We add the table (Aadimos la tabla) paragraphMore.add(table); // We add the paragraph with the table (Aadimos el elemento con la tabla). document.add(chapTitle); document.close(); System.out.println("Your PDF file has been generated!(Se ha generado tu hoja PDF!"); } catch (DocumentException documentException) { System.out.println( "The file not exists (Se ha producido un error al generar un documento): " + documentException); } }