List of usage examples for com.itextpdf.text Rectangle Rectangle
public Rectangle(final float llx, final float lly, final float urx, final float ury)
Rectangle
-object. From source file:es.tlc.pdf.writer.PDFWriter.java
public static void main(String[] args) { try {// ww w .j a va2 s.c om Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE)); Rectangle rct = new Rectangle(36, 54, 559, 788); //Definimos un nombre y un tamao para el PageBox los nombres posibles son: crop?, trim?, art? and bleed?. writer.setBoxSize("art", rct); Header event = new Header(); writer.setPageEvent(event); document.open(); addMetaData(document); addTitlePage(document); addContent(document); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.PdfGenerator.java
License:Open Source License
private int createPdf(OutputStream os, int indexSize, IProgressMonitor monitor) throws DocumentException, IOException { Document document = new Document(PageSize.A4, MARGIN_LEFT, MARGIN_RIGHT, MARGIN_UP, MARGIN_DOWN); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setStrictImageSequence(true); writer.setLinearPageMode();// used to reorder page; // writer.setPdfVersion(PdfWriter.PDF_VERSION_1_6); ChapterSectionTOC event = new ChapterSectionTOC(); writer.setPageEvent(event);//from w ww .ja v a2 s. c om event.pagenumber = rcf.startingPageNumber(); writer.setBoxSize("art", new Rectangle(MARGIN_LEFT, 0, PageSize.A4.getWidth() - MARGIN_RIGHT, FOOTER_HEIGHT)); monitor.beginTask("Generating Report", 100); document.open(); rcf.buildContent(writer, document, new SubProgressMonitor(monitor, 85)); if (rcf.buildIndex()) { document.newPage(); event.setIndex(true); int toc = writer.getPageNumber(); buildIndex(writer, document); document.newPage(); monitor.worked(10); int total = writer.reorderPages(null); int tocLenght = total - toc + 1; int[] order = new int[total]; order[0] = 1; for (int i = 0; i < tocLenght; i++) { order[i + 1] = toc + i; } for (int i = 2; i < toc; i++) { order[i + tocLenght - 1] = i; } writer.reorderPages(order); document.close(); monitor.worked(5); return tocLenght; } return -1; }
From source file:fc.extensions.itext.Writer.java
License:MIT License
public void setPage(Page page) throws Exception { if (pdfWriter.getCurrentPageNumber() > 1) { throw new Exception("ITextClient: Cannot do setPageObject() after first page !!!"); }//from w ww . j av a 2 s . c o m this.pageObject = page; float width = baseFont.getWidthPoint(CONTENT_OF_PAGE_COUNT, page.getHeader().getFontSize()); float height = page.getHeader().getPosition().getHeight(); pageHeadTemplate = pdfWriter.getDirectContent().createTemplate(width, height); pageHeadTemplate.setBoundingBox(new Rectangle(0F, 0F, width, height)); }
From source file:fc.extensions.itext.Writer.java
License:MIT License
/** * write PDF annotation for debugging./*from w ww . j a v a2 s .c o m*/ */ public void writeAnnotation(String title, String content, float leftX, float bottomY, float rightX, float topY) throws Exception { try { pdfWriterCB.saveState(); pdfWriterCB.setRGBColorStroke(255, 255, 0); pdfWriterCB.setLineWidth(1F); pdfWriterCB.rectangle(leftX, bottomY, rightX - leftX, topY - bottomY); pdfWriterCB.stroke(); PdfFormField field = PdfFormField.createTextField(pdfWriter, false, false, 0); field.setWidget(new Rectangle(leftX, bottomY, rightX, topY), PdfAnnotation.HIGHLIGHT_INVERT); field.setFlags(PdfAnnotation.FLAGS_PRINT); field.setFieldName(title); field.setPage(); field.setValueAsString(content); field.setBorderStyle(new PdfBorderDictionary(0.5F, PdfBorderDictionary.STYLE_DASHED)); pdfWriter.addAnnotation(field); } finally { pdfWriterCB.restoreState(); } }
From source file:fc.extensions.itext.Writer.java
License:MIT License
public void drawRectangleWithVariableBorder(Position position, float lineWidth, int borderType) { try {/*from w w w .j av a 2 s. c om*/ pdfWriterCB.saveState(); pdfWriterCB.setRGBColorStroke(0, 0, 0); Rectangle rectangle = new Rectangle(position.getLeft(), position.getBottom(), position.getRight(), position.getTop()); rectangle.setBorderWidth(lineWidth); rectangle.setBorder(borderType); rectangle.setUseVariableBorders(true); pdfWriterCB.rectangle(position.getLeft(), position.getBottom(), position.getWidth(), position.getHeight()); pdfWriterCB.stroke(); } finally { pdfWriterCB.restoreState(); } }
From source file:fenix.planner.pdf.PDFGenerator.java
License:Open Source License
public void generate(OutputStream output) { final Rectangle pageSize = PageSize.A4; final ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream(); document = new Document(pageSize, LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN); try {/*ww w . j a v a 2 s. c om*/ final PdfWriter writer = PdfWriter.getInstance(document, outputBuffer); writer.setBoxSize("art", new Rectangle(ART_BOX_LEFT_MARGIN, ART_BOX_BOTTOM_MARGIN, pageSize.getRight() - ART_BOX_RIGHT_MARGIN, pageSize.getTop() - ART_BOX_TOP_MARGIN)); writer.setPageEvent(new HeaderFooter()); document.open(); createAndAddForeword(); createAndAddEventTable(); createAndAddAfterword(); createAndAddOrganizerTable(); document.close(); writer.close(); // Loop through the document again to add the missing page numbers document = new Document(); final PdfCopy copy = new PdfCopy(document, output); document.open(); final PdfReader reader = new PdfReader(outputBuffer.toByteArray()); addPageNumbers(reader, copy); document.close(); reader.close(); } catch (DocumentException | IOException ex) { throw new PDFGenerationException("Error generating PDF", ex); } }
From source file:fll.util.SimpleFooterHandler.java
License:Open Source License
@Override public void onOpenDocument(final PdfWriter writer, final Document document) { _headerFooterFont = TIMES_12PT_NORMAL.getBaseFont(); // initialization of the footer template _tpl = writer.getDirectContent().createTemplate(100, 100); _tpl.setBoundingBox(new Rectangle(-20, -20, 100, 100)); }
From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java
License:Open Source License
private void addSignatureField() throws DocumentException { PdfFormField field = PdfFormField.createSignature(writer); Rectangle signatureFieldRectangle = new Rectangle(SIGNATURE_FIELD_LOWER_LEFT_X, SIGNATURE_FIELD_LOWER_LEFT_Y, SIGNATURE_FIELD_UPPER_RIGHT_X, SIGNATURE_FIELD_UPPER_RIGHT_Y); field.setWidget(signatureFieldRectangle, PdfAnnotation.HIGHLIGHT_INVERT); field.setFieldName("signature"); field.setFlags(PdfAnnotation.FLAGS_PRINT); field.setPage();//from w w w .ja v a 2 s . c om field.setMKBorderColor(BaseColor.BLACK); field.setMKBackgroundColor(BaseColor.WHITE); PdfAppearance appearance = PdfAppearance.createAppearance(writer, SIGNATURE_FIELD_WIDTH, SIGNATURE_FIELD_HEIGHT); appearance.rectangle(SIGNATURE_FIELD_APPEARANCE_X, SIGNATURE_FIELD_APPEARANCE_Y, SIGNATURE_FIELD_APPEARANCE_WIDTH, SIGNATURE_FIELD_APPEARANCE_HEIGHT); appearance.stroke(); field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, appearance); writer.addAnnotation(field); }
From source file:GUI_Apoteker.Panel_Detil_PO.java
private void createPdf(List<detil_pesan_obat> a) { try {/*from ww w. j a v a 2 s .c o m*/ JFileChooser saveFile = new JFileChooser(); String namaFile = "D:/kampus/si-klinik-PO" + po.getId_Pemesanan_obat() + ".pdf"; saveFile.setSelectedFile(new File(namaFile)); String result = null; if (saveFile.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { result = saveFile.getSelectedFile().toString(); } else { System.out.println("No Selection "); } // TODO add your handling code here: Document document = new Document(); PdfWriter writer = null; try { writer = PdfWriter.getInstance(document, new FileOutputStream(result)); } catch (FileNotFoundException ex) { Logger.getLogger(Panel_Detil_PO.class.getName()).log(Level.SEVERE, null, ex); } document.open(); PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(50, 800, 550, 700); rect.setBorder(Rectangle.BOX); rect.setBorderWidth(5); rect.setBorderColor(BaseColor.BLACK); canvas.rectangle(rect); Paragraph preface; preface = getPreface("Bulanan"); document.add(preface); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(createTableBulanan(a)); document.close(); open(result); } catch (DocumentException ex) { Logger.getLogger(Panel_Detil_PO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:GUI_StafKlinik.Panel_Laporan_Keuangan.java
private void createPdf(List<Laporan_Keuangan> list) { JFileChooser saveFile = new JFileChooser(); saveFile.setSelectedFile(new File("D:/document/Laporan Keuangan.pdf")); String result = null;// w w w . j av a 2s. com if (saveFile.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { result = saveFile.getSelectedFile().toString(); } else { System.out.println("No Selection "); } try { // TODO add your handling code here: Document document = new Document(); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(result)); document.open(); PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(50, 800, 550, 700); rect.setBorder(Rectangle.BOX); rect.setBorderWidth(0); rect.setBorderColor(BaseColor.BLACK); canvas.rectangle(rect); Paragraph preface; preface = getPreface("Laporan Keuangan"); document.add(preface); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(createTableLaporan(list)); document.close(); open(result); } catch (DocumentException ex) { Logger.getLogger(Panel_Laporan_Keuangan.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(Panel_Laporan_Keuangan.class.getName()).log(Level.SEVERE, null, ex); } }