Java Code Examples for com.lowagie.text.pdf.PdfWriter#setPageEvent()
The following examples show how to use
com.lowagie.text.pdf.PdfWriter#setPageEvent() .
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: PageNumbersWatermarkTest.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Generates a document with a header containing Page x of y and with a Watermark on every page. */ @Test public void main() throws Exception { // step 1: creating the document Document doc = new Document(PageSize.A4, 50, 50, 100, 72); // step 2: creating the writer PdfWriter writer = PdfWriter.getInstance(doc, PdfTestBase.getOutputStream( "pageNumbersWatermark.pdf")); // step 3: initialisations + opening the document writer.setPageEvent(new PageNumbersWatermarkTest()); doc.open(); // step 4: adding content String text = "some padding text "; for (int k = 0; k < 10; ++k) { text += text; } Paragraph p = new Paragraph(text); p.setAlignment(Element.ALIGN_JUSTIFIED); doc.add(p); // step 5: closing the document doc.close(); }
Example 2
Source File: EndPageTest.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Demonstrates the use of PageEvents. */ @Test public void main() throws Exception { Document document = new Document(PageSize.A4, 50, 50, 70, 70); PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("endpage.pdf")); writer.setPageEvent(new EndPageTest()); document.open(); String text = "Lots of text. "; for (int k = 0; k < 10; ++k) text += text; document.add(new Paragraph(text)); document.close(); }
Example 3
Source File: PdfExportHelper.java From mdw with Apache License 2.0 | 6 votes |
public void exportProcess(Process process, OutputStream out) throws IOException { new ActivityNodeSequencer(process).assignNodeSequenceIds(); Document document = new Document(); try { PdfWriter writer = PdfWriter.getInstance(document, out); writer.setPageEvent(paragraphBorder); document.open(); Rectangle pageSize = document.getPageSize(); Chapter chapter = printProcess(writer, 1, process, pageSize); document.add(chapter); document.close(); } catch (Exception ex) { if (ex instanceof IOException) throw (IOException) ex; else throw new IOException(ex); } }
Example 4
Source File: PdfDocumentFactory.java From javamelody with Apache License 2.0 | 6 votes |
private void createWriter(Document document, String title) throws DocumentException, IOException { final PdfWriter writer = PdfWriter.getInstance(document, output); //writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft); // title final HeaderFooter header = new HeaderFooter(new Phrase(title), false); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); // simple page numbers : x //HeaderFooter footer = new HeaderFooter(new Phrase(), true); //footer.setAlignment(Element.ALIGN_RIGHT); //footer.setBorder(Rectangle.TOP); //document.setFooter(footer); // add the event handler for advanced page numbers : x/y writer.setPageEvent(new PdfAdvancedPageNumberEvents()); }
Example 5
Source File: MPdfWriter.java From javamelody with Apache License 2.0 | 6 votes |
/** * We create a writer that listens to the document and directs a PDF-stream to out * * @param table * MBasicTable * @param document * Document * @param out * OutputStream * @return DocWriter * @throws DocumentException * e */ protected DocWriter createWriter(final MBasicTable table, final Document document, final OutputStream out) throws DocumentException { final PdfWriter writer = PdfWriter.getInstance(document, out); // writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft); // title if (table.getName() != null) { final HeaderFooter header = new HeaderFooter(new Phrase(table.getName()), false); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(table.getName()); } // simple page numbers : x // HeaderFooter footer = new HeaderFooter(new Phrase(), true); // footer.setAlignment(Element.ALIGN_RIGHT); // footer.setBorder(Rectangle.TOP); // document.setFooter(footer); // add the event handler for advanced page numbers : x/y writer.setPageEvent(new AdvancedPageNumberEvents()); return writer; }
Example 6
Source File: PDFPrinter.java From unitime with Apache License 2.0 | 6 votes |
@Override public void close() throws IOException { try { float width = 0; float[] w = new float[iMaxWidth.length - iHiddenColumns.size()]; int wi = 0; for (int i = 0; i < iMaxWidth.length; i++) if (!iHiddenColumns.contains(i)) { width += 15f + iMaxWidth[i]; w[wi++] = iMaxWidth[i]; } Document document = new Document(new Rectangle(60f + width, 60f + width * 0.75f), 30f, 30f, 30f, 30f); PdfWriter writer = PdfWriter.getInstance(document, iOutput); writer.setPageEvent(new PdfEventHandler()); document.open(); iTable.setWidths(w); document.add(iTable); document.close(); } catch (DocumentException e) { throw new IOException(e.getMessage(), e); } }
Example 7
Source File: BookmarksTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates a document with outlines. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A6); // step 2: PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("bookmarks.pdf")); // step 3: writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); document.open(); // step 4: we grab the ContentByte and do some stuff with it writer.setPageEvent(new BookmarksTest()); document.add(new Paragraph( "GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt. Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix. Is M. Messala, [et P.] M. Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent: perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri. Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur: una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit. His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur. Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare. Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant. Ad eas res conficiendas Orgetorix deligitur. Is sibi legationem ad civitates suscipit. In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat. Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset: non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat. Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "Ea res est Helvetiis per indicium enuntiata. Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur. Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit. Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.", new Font(Font.HELVETICA, 12))); // step 5: we close the document document.close(); }
Example 8
Source File: EventsTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Converts a play in XML into PDF. */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A4, 80, 50, 30, 65); // step 2: // we create a writer that listens to the document // and directs a XML-stream to a file PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("RomeoJuliet.pdf")); // create add the event handler MyPageEvents events = new EventsTest().getPageEvents(); writer.setPageEvent(events); // step 3: we create a parser and set the document handler SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); // step 4: we parse the document parser.parse(PdfTestBase.RESOURCES_DIR + "playRomeoJuliet.xml", new EventsTest().getXmlHandler(document)); document.newPage(); Speaker speaker; for (Iterator i = events.getSpeakers().iterator(); i.hasNext();) { speaker = (Speaker) i.next(); document.add(new Paragraph(speaker.getName() + ": " + speaker.getOccurrence() + " speech blocks")); } document.close(); }
Example 9
Source File: BookmarksTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates a document with outlines. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A6); // step 2: PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Bookmarks.pdf")); // step 3: writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); document.open(); // step 4: we grab the ContentByte and do some stuff with it writer.setPageEvent(new BookmarksTest()); document.add(new Paragraph( "GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt. Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix. Is M. Messala, [et P.] M. Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent: perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri. Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur: una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit. His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur. Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare. Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant. Ad eas res conficiendas Orgetorix deligitur. Is sibi legationem ad civitates suscipit. In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat. Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset: non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat. Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "Ea res est Helvetiis per indicium enuntiata. Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur. Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit. Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.", new Font(Font.HELVETICA, 12))); // step 5: we close the document document.close(); }
Example 10
Source File: PdfEventHandler.java From unitime with Apache License 2.0 | 5 votes |
/** * Initialize Pdf footer * @param document * @param outputStream * @return PdfWriter */ public static PdfWriter initFooter(Document document, OutputStream outputStream) throws DocumentException, IOException { PdfWriter iWriter = PdfWriter.getInstance(document, outputStream); iWriter.setPageEvent(new PdfEventHandler()); return iWriter; }
Example 11
Source File: TransactionReport.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Generates transaction report * * @param errorSortedList list of error'd transactions * @param reportErrors map containing transactions and the errors associated with each transaction * @param reportSummary list of summary objects * @param runDate date report is run * @param title title of report * @param fileprefix file prefix of report file * @param destinationDirectory destination of where report file will reside */ public void generateReport(List<Transaction> errorSortedList, Map<Transaction, List<Message>> reportErrors, List<Summary> reportSummary, Date runDate, String title, String fileprefix, String destinationDirectory) { LOG.debug("generateReport() started"); Font headerFont = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD); Font textFont = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL); Document document = new Document(PageSize.A4.rotate()); PageHelper helper = new PageHelper(); helper.runDate = runDate; helper.headerFont = headerFont; helper.title = title; try { DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class); String filename = destinationDirectory + "/" + fileprefix + "_"; filename = filename + dateTimeService.toDateTimeStringForFilename(runDate); filename = filename + ".pdf"; PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); writer.setPageEvent(helper); document.open(); appendReport(document, headerFont, textFont, errorSortedList, reportErrors, reportSummary, runDate); } catch (DocumentException de) { LOG.error("generateReport() Error creating PDF report", de); throw new RuntimeException("Report Generation Failed: " + de.getMessage()); } catch (FileNotFoundException fnfe) { LOG.error("generateReport() Error writing PDF report", fnfe); throw new RuntimeException("Report Generation Failed: Error writing to file " + fnfe.getMessage()); } finally { if ((document != null) && document.isOpen()) { document.close(); } } }
Example 12
Source File: GlossaryTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Generic page event. * */ @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 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Glossary.pdf")); GlossaryTest generic = new GlossaryTest(); writer.setPageEvent(generic); // step 3: we open the document document.open(); // step 4: String[] f = new String[14]; f[0] = "Courier"; f[1] = "Courier Bold"; f[2] = "Courier Italic"; f[3] = "Courier Bold Italic"; f[4] = "Helvetica"; f[5] = "Helvetica bold"; f[6] = "Helvetica italic"; f[7] = "Helvetica bold italic"; f[8] = "Times New Roman"; f[9] = "Times New Roman bold"; f[10] = "Times New Roman italic"; f[11] = "Times New Roman bold italic"; f[12] = "Symbol"; f[13] = "Zapfdingbats"; Font[] fonts = new Font[14]; fonts[0] = FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL); fonts[1] = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD); fonts[2] = FontFactory.getFont(FontFactory.COURIER, 12, Font.ITALIC); fonts[3] = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD | Font.ITALIC); fonts[4] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); fonts[5] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); fonts[6] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC); fonts[7] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD | Font.ITALIC); fonts[8] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL); fonts[9] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD); fonts[10] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.ITALIC); fonts[11] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD | Font.ITALIC); fonts[12] = FontFactory.getFont(FontFactory.SYMBOL, 12, Font.NORMAL); fonts[13] = FontFactory.getFont(FontFactory.ZAPFDINGBATS, 12, Font.NORMAL); for (int i = 0; i < 14; i++) { Chunk chunk = new Chunk("This is font ", fonts[i]); Paragraph p = new Paragraph(chunk); p.add(new Phrase(new Chunk(f[i], fonts[i]).setGenericTag(f[i]))); document.add(p); if (i % 4 == 3) { document.newPage(); } } // we add the glossary document.newPage(); for (Iterator<String> i = generic.glossary.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); int page = ((Integer) generic.glossary.get(key)).intValue(); Paragraph g = new Paragraph(key); g.add(" : page "); g.add(String.valueOf(page)); document.add(g); } // step 5: we close the document document.close(); }
Example 13
Source File: ExamDistributionPrefsTableBuilder.java From unitime with Apache License 2.0 | 4 votes |
public void toPdfTable(OutputStream out, HttpServletRequest request, SessionContext context, Collection distPrefs, Long examTypeId) throws Exception { WebTable.setOrder(context,"examDistPrefsTable.ord",request.getParameter("order"),4); PdfWebTable tbl = new PdfWebTable(4, ExamTypeDAO.getInstance().get(examTypeId).getLabel()+" Examination Distribution Preferences", null, new String[] {" Preference ", " Type ", " Exam ", " Class/Course " }, new String[] { "left", "left", "left", "left"}, new boolean[] { true, true, true, true} ); int nrPrefs = 0; for (Iterator i1=distPrefs.iterator();i1.hasNext();) { DistributionPref dp = (DistributionPref)i1.next(); if (!context.hasPermission(dp, Right.ExaminationDistributionPreferenceDetail)) continue; nrPrefs++; String examStr = ""; String objStr = ""; for (Iterator i2=dp.getOrderedSetOfDistributionObjects().iterator();i2.hasNext();) { DistributionObject dO = (DistributionObject)i2.next(); Exam exam = (Exam)dO.getPrefGroup(); examStr += dO.preferenceText(); for (Iterator i3=exam.getOwners().iterator();i3.hasNext();) { ExamOwner owner = (ExamOwner)i3.next(); objStr += owner.getLabel(); if (i3.hasNext()) { examStr += "\n"; objStr += "\n"; } } if (i2.hasNext()) { examStr += "\n"; objStr += "\n"; } } String distType = dp.getDistributionType().getLabel(); String prefLevel = dp.getPrefLevel().getPrefName(); tbl.addLine( null, new String[] { prefLevel, distType, examStr, objStr }, new Comparable[] { null, distType, examStr, objStr }); } if (nrPrefs==0) tbl.addLine(null, new String[] { "No preferences found", "", "", "" }, null); int ord = WebTable.getOrder(context,"examDistPrefsTable.ord"); ord = (ord>0?1:-1)*(1+Math.abs(ord)); PdfPTable table = tbl.printPdfTable(ord); float width = tbl.getWidth(); Document doc = new Document(new Rectangle(60f + width, 60f + 1.30f * width),30,30,30,30); PdfWriter iWriter = PdfWriter.getInstance(doc, out); iWriter.setPageEvent(new PdfEventHandler()); doc.open(); if (tbl.getName()!=null) doc.add(new Paragraph(tbl.getName(), PdfFont.getBigFont(true))); doc.add(table); doc.close(); }
Example 14
Source File: PdfWebTable.java From unitime with Apache License 2.0 | 4 votes |
public void exportPdf(OutputStream out, int ordCol) throws Exception { PdfPTable table = printPdfTable(ordCol); float width = getWidth(); Document doc = new Document(new Rectangle(60f + width, 60f + 0.75f * width),30,30,30,30); PdfWriter iWriter = PdfWriter.getInstance(doc, out); iWriter.setPageEvent(new PdfEventHandler()); doc.open(); if (iName!=null) doc.add(new Paragraph(iName, PdfFont.getBigFont(true))); doc.add(table); doc.close(); }
Example 15
Source File: BulkReceivingPdf.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
/** * Generates the pdf document based on the data in the given BulkReceivingDocument * * @param blkRecDoc The BulkReceivingDocument to be used to generate the pdf. * @param byteStream The ByteArrayOutputStream where the pdf document will be written to. */ public void generatePdf(BulkReceivingDocument blkRecDoc, ByteArrayOutputStream byteStream, String logoImage, String environment) { if (LOG.isDebugEnabled()) { LOG.debug("generatePdf() started for bulk receiving - " + blkRecDoc.getDocumentNumber()); } Document document = null; try { document = this.getDocument(9, 9, 70, 36); PdfWriter writer = PdfWriter.getInstance(document, byteStream); //These have to be set because they are used by the onOpenDocument() and onStartPage() methods. this.logoImage = logoImage; this.blkRecDoc = blkRecDoc; this.environment = environment; // This turns on the page events that handle the header and page numbers. BulkReceivingPdf events = new BulkReceivingPdf().getPageEvents(); writer.setPageEvent(this); document.open(); document.add(createVendorAndDeliveryDetailsTable()); document.add(new Paragraph("\nAdditional Details\n ", ver_8_bold)); document.add(createAdditionalDetailsTable()); document.close(); }catch (Exception de) { throw new RuntimeException("Document Exception when trying to save a Bulk Receiving PDF", de); }finally{ if (document != null && document.isOpen()){ document.close(); } } if (LOG.isDebugEnabled()) { LOG.debug("generatePdf() completed for bulk receiving - " + blkRecDoc.getDocumentNumber()); } }