List of usage examples for com.itextpdf.text Document newPage
public boolean newPage()
From source file:org.smap.sdal.managers.PDFSurveyManager.java
License:Open Source License
private void processForm(Parser parser, Document document, ArrayList<Result> record, String basePath, String serverRoot, boolean generateBlank, int depth, int length, int[] repIndexes, GlobalVariables gv, boolean appendix, ArrayList<ArrayList<Result>> parentRecords, String remoteUser, int oId) throws DocumentException, IOException, SQLException { // Check that the depth of repeats hasn't exceeded the maximum if (depth > repIndexes.length - 1) { depth = repIndexes.length - 1;/* ww w . java2 s . c o m*/ } boolean firstQuestion = true; for (int j = 0; j < record.size(); j++) { Result r = record.get(j); if (r.type.equals("form")) { firstQuestion = true; // Make sure there is a gap when we return from the sub form // If this is a blank template check to see the number of times we should repeat this sub form if (generateBlank) { int blankRepeats = getBlankRepeats(r.appearance); for (int k = 0; k < blankRepeats; k++) { repIndexes[depth] = k; processForm(parser, document, r.subForm.get(0), basePath, serverRoot, generateBlank, depth + 1, k, repIndexes, gv, appendix, null, remoteUser, oId); } } else { for (int k = 0; k < r.subForm.size(); k++) { // Maintain array list of parent records in order to look up ${values} parentRecords.add(0, record); // Push this record in at the beginning of the list as we want to search most recent first repIndexes[depth] = k; processForm(parser, document, r.subForm.get(k), basePath, serverRoot, generateBlank, depth + 1, k, repIndexes, gv, appendix, parentRecords, remoteUser, oId); } } } else { // Process the question Form form = survey.forms.get(r.fIdx); Question question = getQuestionFromResult(sd, r, form); if (question != null) { if (includeResult(r, question, appendix, gv, generateBlank)) { if (question.type.equals("begin group")) { if (question.isNewPage()) { document.newPage(); } } else if (question.type.equals("end group")) { //ignore } else { Row row = prepareRow(record, survey, j, gv, length, appendix, parentRecords, generateBlank); PdfPTable newTable = processRow(parser, row, basePath, serverRoot, generateBlank, depth, repIndexes, gv, remoteUser, oId); newTable.setWidthPercentage(100); newTable.setKeepTogether(true); // Add a gap if this is the first question of the record // or the previous row was at a different depth if (firstQuestion) { newTable.setSpacingBefore(5); } else { newTable.setSpacingBefore(row.spaceBefore()); } firstQuestion = false; // Start a new page if the first question needs to be on a new page if (row.items.get(0).isNewPage) { document.newPage(); } document.add(newTable); j += row.items.size() - 1; // Jump over multiple questions if more than one was added to the row } } } else { log.info("Question Idx not found: " + r.qIdx); } } } return; }
From source file:org.tvd.thptty.management.report.Report.java
@SuppressWarnings("unused") private void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);/*from ww w . j ava 2 s . com*/ // Lets write a big header preface.add(new Paragraph("Title of the document", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes something which is very important ", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph("This document is a preliminary " + "version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:org.tvd.thptty.management.util.Report.java
private void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); preface.setFont(smallBold);//from www .j av a 2 s . c o m // We add one empty line addEmptyLine(preface, 1); // Lets write a big header preface.add(new Paragraph("Title of Dng the document", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes something which is very important ", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph("This document is a preliminary " + "version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:org.zaproxy.zap.extension.alertReport.AlertReportExportPDF.java
License:Apache License
private static void addTitlePage(Document document, ExtensionAlertReportExport extensionExport) throws DocumentException { document.addHeader("Header1", "Header2"); Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 3);//from w w w .j a v a 2 s. co m // add logo first page addImage(preface, extensionExport.getParams().getLogoFileName(), 40f); addEmptyLine(preface, 4); // Lets write a big header Paragraph paragraph = new Paragraph(extensionExport.getParams().getTitleReport(), titleFont); paragraph.setAlignment(Paragraph.ALIGN_CENTER); preface.add(paragraph); addEmptyLine(preface, 3); paragraph = new Paragraph(extensionExport.getParams().getCustomerName(), catFont); paragraph.setAlignment(Paragraph.ALIGN_CENTER); preface.add(paragraph); addEmptyLine(preface, 15); preface.add(new Paragraph( extensionExport.getMessages().getString("alertreport.export.message.export.pdf.confidential"), smallBold)); preface.add(new Paragraph(extensionExport.getParams().getConfidentialText(), litleFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:org.zaproxy.zap.extension.alertReport.AlertReportExportPDF.java
License:Apache License
private static void addContent(Document document, java.util.List<Alert> alerts, ExtensionAlertReportExport extensionExport) throws DocumentException { Alert alert = alerts.get(0);//from w ww . java 2 s .co m Anchor anchor = new Anchor(alert.getAttack(), catFont); anchor.setName(alert.getAttack()); Paragraph content = new Paragraph(); content.add(new Paragraph(alert.getAlert(), catFont)); content.add(new Paragraph( extensionExport.getMessages().getString("alertreport.export.message.export.pdf.description"), subFont)); content.add(new Paragraph(getFieldAlertProperty(alert.getPluginId(), "description", alert.getDescription(), extensionExport))); addEmptyLine(content, 1); content.add(new Paragraph( extensionExport.getMessages().getString("alertreport.export.message.export.pdf.risk"), subFont)); content.add(new Paragraph(getFieldAlertProperty(alert.getPluginId(), "risk." + String.valueOf(alert.getRisk()), Alert.MSG_RISK[alert.getRisk()], extensionExport))); addEmptyLine(content, 1); content.add(new Paragraph( extensionExport.getMessages().getString("alertreport.export.message.export.pdf.reability"), subFont)); content.add(new Paragraph( getFieldAlertProperty(alert.getPluginId(), "reliability." + String.valueOf(alert.getReliability()), Alert.MSG_RELIABILITY[alert.getReliability()], extensionExport))); addEmptyLine(content, 1); content.add(new Paragraph( extensionExport.getMessages().getString("alertreport.export.message.export.pdf.urls"), subFont)); // write all url with the same pluginid for (int i = 0; i < alerts.size(); i++) { Alert alertAux = alerts.get(i); // add url link and attack anchor = new Anchor((i + 1) + "-" + alertAux.getUri()); anchor.setReference(alertAux.getUri()); content.add(anchor); if (!alertAux.getParam().isEmpty()) { content.add( new Paragraph(" " + extensionExport.getMessages() .getString("alertreport.export.message.export.pdf.parameters") + ": " + alertAux.getParam())); addEmptyLine(content, 1); } if (!alertAux.getAttack().isEmpty()) { content.add(new Paragraph( extensionExport.getMessages().getString("alertreport.export.message.export.pdf.attack"), subFont)); content.add(new Paragraph(alertAux.getAttack())); addEmptyLine(content, 1); } // add images test addEmptyLine(content, 1); String images = alertAux.getOtherInfo(); if (!images.isEmpty()) { String[] list = images.split("\n"); // for (int j = 0, lengh = list.length/2; j <= lengh; j += 2) { for (int j = 0; j < list.length; j++) { if (!((j + 1) >= list.length)) { String step = list[j]; Paragraph paragraph = new Paragraph(step); content.add(paragraph); addEmptyLine(content, 1); // add step and image String imageName = ""; String path = extensionExport.getParams().getWorkingDirImages(); if (((j + 1) < list.length) && (!list[j + 1].isEmpty())) { imageName = list[j + 1]; // if exist an image try { if ((imageName.endsWith(".png") || imageName.endsWith(".jpg")) && (!path.isEmpty())) { addImage(content, path + "/" + imageName, 60f); addEmptyLine(content, 1); paragraph = new Paragraph(extensionExport.getMessages() .getString("alertreport.export.message.export.pdf.image") + ": " + Integer.toString(j), litleFont); paragraph.setAlignment(Paragraph.ALIGN_CENTER); content.add(paragraph); } else { paragraph = new Paragraph(imageName); content.add(paragraph); addEmptyLine(content, 1); } } catch (Exception e) { logger.error(e.getMessage(), e); } } j++; } } } addEmptyLine(content, 1); } if (!alert.getSolution().equals("")) { addEmptyLine(content, 1); content.add(new Paragraph( extensionExport.getMessages().getString("alertreport.export.message.export.pdf.solution"), subFont)); content.add(new Paragraph( getFieldAlertProperty(alert.getPluginId(), "solution", alert.getSolution(), extensionExport))); } addEmptyLine(content, 1); if (!alert.getReference().equals("")) { content.add(new Paragraph( extensionExport.getMessages().getString("alertreport.export.message.export.pdf.references"), subFont)); content.add(new Paragraph(alert.getReference())); addEmptyLine(content, 1); } document.add(content); // Start a new page document.newPage(); }
From source file:PDF.Reportes.java
public void reportesPDF(HttpServletResponse response, int tr, ServletContext d, String usuario, String contra, String horario, int opc) { String reporteT = ""; try {//w ww.j a v a 2 s. c om Document reporte = new Document(); Calendar cal = Calendar.getInstance(); Paragraph intro = new Paragraph(); intro.setAlignment(Element.ALIGN_CENTER); String linea = "/Imagenes/rallita.png"; String absolute_url_linea = d.getRealPath(linea); Image linea_div = Image.getInstance(absolute_url_linea); Paragraph vacio = new Paragraph(" ", FontFactory.getFont("arial", 10)); vacio.setAlignment(Element.ALIGN_CENTER); if (tr == 0) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png"); writer.setPageEvent(event); reporte.open(); reporte.add(vacio); reporte.add(vacio); ArrayList<JFreeChart> graf = grafica(usuario, contra); if (graf == null) { intro = new Paragraph( "Lo sentimos, por el momento an no existe informacin para este reporte.", FontFactory.getFont("arial", 18)); reporte.add(intro); } else { for (int i = 0; i < graf.size(); i++) { BufferedImage bufferedImage = graf.get(i).createBufferedImage(500, 300); Image chart = Image.getInstance(writer, bufferedImage, 1.0f); reporte.add(vacio); reporte.add(chart); } } reporteT = "Estadsticas de registros."; } if (tr == 1) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png"); writer.setPageEvent(event); reporte.open(); reporte.add(linea_div); Paragraph creador = new Paragraph("Instituto Tecnolgico de Toluca\n" + "\n" + "Centro de Cmputo\n" + "\n" + "Coordinacin de Desarrollo de Sistemas", FontFactory.getFont("arial", 10)); reporte.add(creador); reporte.add(linea_div); intro = new Paragraph("Sin alta en CENEVAL " + cal.get(Calendar.YEAR), FontFactory.getFont("arial", 18)); intro.setAlignment(Element.ALIGN_CENTER); reporte.add(intro); reporte.add(vacio); reporte.add(vacio); reporte.add(noaltaCen(usuario, contra)); reporteT = "Sin alta en CENEVAL."; } if (tr == 2) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png"); writer.setPageEvent(event); reporte.open(); reporte.add(linea_div); Paragraph creador = new Paragraph("Instituto Tecnolgico de Toluca\n" + "\n" + "Centro de Cmputo\n" + "\n" + "Coordinacin de Desarrollo de Sistemas", FontFactory.getFont("arial", 10)); reporte.add(creador); reporte.add(linea_div); intro = new Paragraph("Estatus Prefichas " + cal.get(Calendar.YEAR), FontFactory.getFont("arial", 18)); intro.setAlignment(Element.ALIGN_CENTER); reporte.add(intro); reporte.add(vacio); reporte.add(vacio); reporte.add(statusfichas(usuario, contra)); reporteT = "Estatus prefichas"; } if (tr == 3) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png"); writer.setPageEvent(event); reporte.open(); reporte.add(linea_div); Paragraph creador = new Paragraph("Instituto Tecnolgico de Toluca\n" + "\n" + "Centro de Cmputo\n" + "\n" + "Coordinacin de Desarrollo de Sistemas", FontFactory.getFont("arial", 10)); reporte.add(creador); reporte.add(linea_div); intro = new Paragraph("Pre proceso concluido " + cal.get(Calendar.YEAR), FontFactory.getFont("arial", 18)); intro.setAlignment(Element.ALIGN_CENTER); reporte.add(intro); reporte.add(vacio); reporte.add(vacio); reporte.add(procesoCon(usuario, contra)); reporteT = "Pre proceso concluido"; } if (tr == 4) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); ArrayList<PdfPTable> tables = firmasAspAula(usuario, contra, horario, opc); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent2 event = new HeaderFooterPageEvent2("ficha-pdf.png"); writer.setPageEvent(event); reporte.open(); if (tables.size() != 1) { PdfPTable tableH = tables.get(tables.size() - 1); tableH.writeSelectedRows(0, -1, 10, 720, writer.getDirectContent()); } else { reporte.add(tables.get(0)); } reporte.add(vacio); reporte.add(vacio); reporte.add(vacio); for (int i = 0; i < tables.size(); i++) { if (i + 1 != tables.size()) { reporte.add(tables.get(i)); if (i + 2 != tables.size()) { reporte.newPage(); } } } reporteT = "Firmas Aspirantes_" + horario; } if (tr == 5) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); ArrayList<PdfPTable> tables = tablaAspAula(usuario, contra, horario, opc); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent2 event = new HeaderFooterPageEvent2("ficha-pdf.png"); writer.setPageEvent(event); reporte.open(); if (tables.size() != 1) { PdfPTable tableH = tables.get(tables.size() - 1); tableH.writeSelectedRows(0, -1, 10, 720, writer.getDirectContent()); } else { reporte.add(tables.get(0)); } reporte.add(vacio); reporte.add(vacio); reporte.add(vacio); for (int i = 0; i < tables.size(); i++) { if (i + 1 != tables.size()) { reporte.add(tables.get(i)); if (i + 2 != tables.size()) { reporte.newPage(); } } } reporteT = "Aspirantes por aula horario_" + horario; } reporte.addTitle("Reportes_" + reporteT); reporte.addSubject("Instituto Tecnolgico de Toluca"); reporte.addKeywords("Instituto Tecnolgico de Toluca"); reporte.addAuthor("Coordinacion de desarrollo de sistemas"); reporte.addCreator("Centro de Cmputo ITT"); //Asignamos el manejador de eventos al escritor. reporte.close(); } catch (DocumentException | IOException ex) { Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:pdf.SplitPDF.java
public static void splitPDF(InputStream inputStream, OutputStream outputStream, int fromPage, int toPage) { Document document = new Document(); try {/* www .ja v a 2 s . c o m*/ PdfReader inputPDF = new PdfReader(inputStream); int totalPages = inputPDF.getNumberOfPages(); //make fromPage equals to toPage if it is greater if (fromPage > toPage) { fromPage = toPage; } if (toPage > totalPages) { toPage = totalPages; } // Create a writer for the outputstream PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); PdfContentByte cb = writer.getDirectContent(); // Holds the PDF data PdfImportedPage page; while (fromPage <= toPage) { document.newPage(); page = writer.getImportedPage(inputPDF, fromPage); cb.addTemplate(page, 0, 0); fromPage++; } outputStream.flush(); document.close(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (document.isOpen()) { document.close(); } try { if (outputStream != null) { outputStream.close(); } } catch (IOException ioe) { ioe.printStackTrace(); } } }
From source file:pdfcreator.Main.java
private static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);// w w w. j a va 2s . co m // Lets write a big header preface.add(new Paragraph("Title of the document", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes something which is very important ", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph( "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:pdfcreator.PDFCreator.java
License:Open Source License
@SuppressWarnings("static-access") protected void createPdf(String filename, String[] images) throws Exception { Document doc = new Document(); PdfWriter writer;//from w w w .j a v a2s . c o m if (pdfxConformance.equals("PDFA1A")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_1A); } else if (pdfxConformance.equals("PDFA1B")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_1B); } else if (pdfxConformance.equals("PDFA2A")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_2A); } else if (pdfxConformance.equals("PDFA2B")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_2B); } else if (pdfxConformance.equals("PDFA3A")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_3A); } else if (pdfxConformance.equals("PDFA3B")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_3B); } else { writer = PdfWriter.getInstance(doc, new FileOutputStream(filename)); } if (pdfVersion.equals("1.4")) { writer.setPdfVersion(PdfWriter.VERSION_1_4); } else if (pdfVersion.equals("1.5")) { writer.setPdfVersion(PdfWriter.VERSION_1_5); } else if (pdfVersion.equals("1.6")) { writer.setPdfVersion(PdfWriter.VERSION_1_6); } else if (pdfVersion.equals("1.7")) { writer.setPdfVersion(PdfWriter.VERSION_1_7); } else { writer.setPdfVersion(PdfWriter.VERSION_1_4); } verbose(filename + ": open"); doc.addCreationDate(); doc.addCreator(creator); if (title != null) { doc.addTitle(title); } for (int i = 0; i < images.length; i++) { verbose(" +" + images[i]); Image img = Image.getInstance(images[i]); doc.setPageSize(new Rectangle(img.getWidth(), img.getHeight())); doc.setMargins(0, 0, 0, 0); if (doc.isOpen()) { doc.newPage(); } else { doc.open(); } doc.add(img); doc.newPage(); } ICC_Profile icc = getImageColorProfile(images[0]); if (icc == null) { System.err.println("warning: no color profile available in " + images[0] + " using " + profileName); icc = getDefaultColorProfile(); } writer.setOutputIntents("Custom", "", null, null, icc); writer.createXmpMetadata(); doc.close(); verbose(filename + ": close"); }
From source file:pdfgen.pdf_generation_try5.java
public void AddParagraph(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line // Lets write a big header //addEmptyLine(preface, 27); String SomeDataWhichIsDerived = rep1; // preface.add(new Paragraph("Generated Path of file"+OUTPUTFILE, catFont)); //The new paragraph allows us to set the font of our choice //addEmptyLine(preface, 5); // Will create: Report generated by: _name, _date // preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3smallBold)); // addEmptyLine(preface, 20); preface.add(new Paragraph(SomeDataWhichIsDerived, smallBold)); // addEmptyLine(preface, 25); // preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",redFont)); document.add(preface);/*from w w w . j av a2 s .co m*/ // Start a new page document.newPage(); }