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:contabilidad.Capital.java
public Capital() { jFrame = new JFrame("Capital"); jFrame.setDefaultCloseOperation(jFrame.DISPOSE_ON_CLOSE); jFrame.setSize(800, 600);/*from w ww . ja v a 2 s .c om*/ jFrame.setLocationRelativeTo(null); jFrame.setIconImage(new ImageIcon(getClass().getResource("../imagenes/rana.jpg")).getImage()); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); System.out.println("X:" + screenSize.width + " Y:" + screenSize.height); int x = (screenSize.width / 2) - (jFrame.getSize().width / 2); int y = (screenSize.height / 2) - (jFrame.getSize().height / 2); jFrame.setLocation(x, y); JPanel jPanel = new JPanel(); jPanel.setLayout(null); JLabel capitalC = new JLabel("Capital Social: "); capitalC.setBounds(50, 90, 90, 20); jPanel.add(capitalC); JLabel cs = new JLabel("5000"); cs.setBounds(140, 90, 90, 20); jPanel.add(cs); JLabel resultado = new JLabel("Resultado de ejercicio: "); resultado.setBounds(100, 130, 150, 20); jPanel.add(resultado); JLabel er = new JLabel("prueba"); er.setBounds(250, 130, 90, 20); jPanel.add(er); JLabel capitalCT = new JLabel("Total Capital: "); capitalCT.setBounds(170, 170, 90, 20); jPanel.add(capitalCT); JLabel toc = new JLabel("prueba"); toc.setBounds(270, 170, 90, 20); jPanel.add(toc); JMenuBar jMenuBar = new JMenuBar(); JMenu jMenu = new JMenu("Inicio"); JMenu jMenu2 = new JMenu("Reportes"); JMenu jMenu3 = new JMenu("Ayuda"); jMenuBar.add(jMenu); jMenuBar.add(jMenu2); jMenuBar.add(jMenu3); JMenuItem jMenuItem2 = new JMenuItem("Reporte PDF"); jMenuItem2.addActionListener(new MenuListener(jFrame)); jMenuItem2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selecto = new JFileChooser(); int op = selecto.showSaveDialog(null); if (op == JFileChooser.APPROVE_OPTION) { try { OutputStream archivo = new FileOutputStream(selecto.getSelectedFile() + ".pdf"); Document document = new Document(); document.addAuthor("Contabilidad"); document.addTitle("Capital"); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(selecto.getSelectedFile() + ".pdf")); writer.setInitialLeading(16); Rectangle rct = new Rectangle(80, 104, 500, 688); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); document.add(new Paragraph("Capital")); document.add(new Paragraph(" ")); Paragraph parrafo3 = new Paragraph("Fecha: 25/5/42"); parrafo3.setAlignment(2);//el 1 es para centrar document.add(parrafo3); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); Paragraph parrafo2 = new Paragraph("Capital Social : 5000 "); parrafo2.setAlignment(6);//el 1 es para centrar document.add(parrafo2); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); Paragraph parrafo5 = new Paragraph("Estado de resultados: "); parrafo5.setAlignment(6);//el 1 es para centrar document.add(parrafo5); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.close(); archivo.close(); Runtime.getRuntime().exec("cmd /c start " + selecto.getSelectedFile() + ".pdf"); } catch (FileNotFoundException ex) { Logger.getLogger(Capital.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Capital.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Capital.class.getName()).log(Level.SEVERE, null, ex); } } } }); JMenuItem jMenuItem3 = new JMenuItem("Salir"); jMenuItem3.addActionListener(new MenuListener(jFrame)); jMenuItem3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { VentanaGeneral es = new VentanaGeneral(); jFrame.dispose(); } }); JMenuItem jMenuItem7 = new JMenuItem("Acerca de"); jMenuItem7.addActionListener(new MenuListener(jFrame)); jMenu.add(jMenuItem3); jMenu2.add(jMenuItem2); jMenu3.add(jMenuItem7); jFrame.setJMenuBar(jMenuBar); JButton botonac = new JButton("Aceptar"); botonac.setBounds(300, 300, 150, 30); botonac.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Reportes es = new Reportes(); jFrame.dispose(); } }); jPanel.add(botonac); jFrame.add(jPanel); jFrame.setVisible(true); }
From source file:Controlador.EmailWithPdf.java
/** * Writes the content of a PDF file (using iText API) * to the {@link OutputStream}.//from w w w .j a va 2 s . co m * @param outputStream {@link OutputStream}. * @throws Exception */ public void writePdf(OutputStream outputStream) throws Exception { Document document = new Document(PageSize.LETTER, 50, 50, 50, 30); Font boldFontTitulo = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font boldFontTexto = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); Font FontTexto = new Font(Font.FontFamily.HELVETICA, 12); // document.setPageSize(null); PdfWriter writer = PdfWriter.getInstance(document, outputStream); Image imagen = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\BSeguroLogo.png"); Image imagen2 = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\mapfre.png"); DateFormat df = new SimpleDateFormat("dd/MM/YYYY"); Calendar cdos = Calendar.getInstance(); Date datediamas = new Date(); Date dateaniomas = new Date(); cdos.add(Calendar.DATE, 1); datediamas = cdos.getTime(); String fechadiamas = df.format(datediamas); cdos.add(Calendar.YEAR, 1); dateaniomas = cdos.getTime(); String fechavencimiento = df.format(dateaniomas); document.open(); PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = new Rectangle(36, 36, 579, 756); rect.setBorder(Rectangle.BOX); rect.setBorderWidth(2); canvas.rectangle(rect); // Rectangle rect= new Rectangle(36,108); // rect.setBorder(Rectangle.BOX); // //rect.setBorderColor(BaseColor.BLACK); //rect.setBorderWidth(2); //document.add(rect); document.addTitle("Cotizacion"); document.addSubject("Cotizacion"); document.addKeywords("Cotizacion, seguros"); document.addAuthor("BSeguro"); document.addCreator("Bseguro"); imagen.scaleAbsoluteHeight(30f); imagen.setAbsolutePosition(45f, 720f); imagen2.scaleAbsoluteHeight(30f); imagen2.setAbsolutePosition(450f, 720f); document.add(imagen); document.add(imagen2); Paragraph paragraph2 = new Paragraph("DATOS DE TU POLIZA" + fechadiamas + " hasta: " + fechavencimiento, boldFontTitulo); Paragraph paragraph3 = new Paragraph( "DhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhATOS DE TU POLIZA", boldFontTitulo); paragraph2.setAlignment(Element.ALIGN_CENTER); document.add(paragraph2); document.add(paragraph3); document.close(); }
From source file:dbedit.actions.ExportPdfAction.java
License:Open Source License
@Override protected void performThreaded(ActionEvent e) throws Exception { boolean selection = false; JTable table = ResultSetTable.getInstance(); if (table.getSelectedRowCount() > 0 && table.getSelectedRowCount() != table.getRowCount()) { Object option = Dialog.show("PDF", "Export", Dialog.QUESTION_MESSAGE, new Object[] { "Everything", "Selection" }, "Everything"); if (option == null || "-1".equals(option.toString())) { return; }/*from w w w . j a v a2 s .c o m*/ selection = "Selection".equals(option); } List list = ((DefaultTableModel) table.getModel()).getDataVector(); int columnCount = table.getColumnCount(); PdfPTable pdfPTable = new PdfPTable(columnCount); pdfPTable.setWidthPercentage(100); pdfPTable.getDefaultCell().setPaddingBottom(4); int[] widths = new int[columnCount]; // Row Header pdfPTable.getDefaultCell().setBorderWidth(2); for (int i = 0; i < columnCount; i++) { String columnName = table.getColumnName(i); pdfPTable.addCell(new Phrase(columnName, ROW_HEADER_FONT)); widths[i] = Math.min(50000, Math.max(widths[i], ROW_HEADER_BASE_FONT.getWidth(columnName + " "))); } pdfPTable.getDefaultCell().setBorderWidth(1); if (!list.isEmpty()) { pdfPTable.setHeaderRows(1); } // Body for (int i = 0; i < list.size(); i++) { if (!selection || table.isRowSelected(i)) { List record = (List) list.get(i); for (int j = 0; j < record.size(); j++) { Object o = record.get(j); if (o != null) { if (ResultSetTable.isLob(j)) { o = Context.getInstance().getColumnTypeNames()[j]; } } else { o = ""; } PdfPCell cell = new PdfPCell(new Phrase(o.toString())); cell.setPaddingBottom(4); if (o instanceof Number) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } pdfPTable.addCell(cell); widths[j] = Math.min(50000, Math.max(widths[j], BASE_FONT.getWidth(o.toString()))); } } } // Size pdfPTable.setWidths(widths); int totalWidth = 0; for (int width : widths) { totalWidth += width; } Rectangle pageSize = PageSize.A4.rotate(); pageSize.setRight(pageSize.getRight() * Math.max(1f, totalWidth / 53000f)); pageSize.setTop(pageSize.getTop() * Math.max(1f, totalWidth / 53000f)); // Document Document document = new Document(pageSize); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, byteArrayOutputStream); document.open(); pdfTemplate = writer.getDirectContent().createTemplate(100, 100); pdfTemplate.setBoundingBox(new Rectangle(-20, -20, 100, 100)); writer.setPageEvent(this); document.add(pdfPTable); document.close(); FileIO.saveAndOpenFile("export.pdf", byteArrayOutputStream.toByteArray()); }
From source file:de.domjos.schooltools.core.utils.fileUtils.PDFBuilder.java
License:Open Source License
public PDFBuilder(String path, Context context) throws Exception { this.document = new Document(); PdfWriter writer = PdfWriter.getInstance(this.document, new FileOutputStream(path)); writer.setBoxSize("art", new Rectangle(55, 25, 550, 788)); writer.setPageEvent(new Footer(context)); this.document.open(); this.fonts = new LinkedHashMap<>(); }
From source file:de.sign.SignMain.java
License:Open Source License
public void sign() throws DocumentException, IOException, GeneralSecurityException { PdfReader reader = new PdfReader(this.orgFile); OutputStream os = new FileOutputStream(this.orgFile.replace(".pdf", "SIGN.pdf")); PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0'); // Create appearance PdfSignatureAppearance appearance = stamper.getSignatureAppearance(); Rectangle cropBox = reader.getCropBox(1); float width = 50; float height = 50; Rectangle rectangle = new Rectangle(cropBox.getRight(width) - 20, cropBox.getTop(height) - 20, cropBox.getRight() - 20, cropBox.getTop() - 20); appearance.setVisibleSignature(rectangle, 1, "sig"); appearance.setLocation(getHostname()); appearance.setReason("Evidence of document integrity"); appearance.setCertificationLevel(1); // 1 = CERTIFIED_NO_CHANGES_ALLOWED appearance.setAcro6Layers(false);/*from w w w . j a v a 2s. c om*/ appearance.setLayer2Text(""); //Sign Security.addProvider(new BouncyCastleProvider()); TSAClient tsc = new TSAClientBouncyCastle(this.tsa_URL); ExternalDigest digest = new BouncyCastleDigest(); ExternalSignature signature = new PrivateKeySignature(getPrivateKey(), "SHA-1", "BC"); MakeSignature.signDetached(appearance, digest, signature, getCertificateChain(), null, null, tsc, 0, CryptoStandard.CMS); }
From source file:direccion.GeneradorFormato.java
public static void main(String[] args) { try {/*w ww . j a v a2s . c o m*/ Document document = new Document(PageSize.LETTER, 50, 50, 85, 50); document.addAuthor("Direccin"); document.addTitle("Reporte de algo"); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Reporte prueba.pdf")); writer.setInitialLeading(16); Rectangle rct = new Rectangle(80, 104, 500, 688); writer.setBoxSize("art", rct); GeneradorFormato event = new GeneradorFormato(); writer.setPageEvent(event); document.open(); Paragraph parrafo2 = new Paragraph( "De aqui en adelante el contenido, ya se pone en automatico el encabezado en cada pgina y el nmero", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED)); parrafo2.setAlignment(0); document.add(parrafo2); document.add(Chunk.NEWLINE); document.close(); } catch (FileNotFoundException | DocumentException ex) { System.out.println(ex.getMessage()); } }
From source file:ec.rubrica.pdf.FirmadorPdf.java
License:Open Source License
public byte[] firmar(PrivateKey pk, X509Certificate certificado, String razon, String ubicacion) throws IOException { try {/* www .jav a 2 s .c o m*/ // Creating the reader and the stamper PdfReader reader = new PdfReader(pdf); ByteArrayOutputStream signedPdf = new ByteArrayOutputStream(); PdfStamper stamper = PdfStamper.createSignature(reader, signedPdf, '\0'); // Creating the appearance PdfSignatureAppearance appearance = stamper.getSignatureAppearance(); appearance.setReason(razon); appearance.setLocation(ubicacion); Rectangle pageSize = reader.getPageSize(1); Rectangle position = new Rectangle(15, pageSize.getHeight() - 50, 250, pageSize.getHeight()); appearance.setVisibleSignature(position, 1, "sig"); // Creating the signature ExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA1, null); Certificate[] chain = new Certificate[] { certificado }; MakeSignature.signDetached(appearance, pks, chain, null, null, tsaClient, BouncyCastleProvider.PROVIDER_NAME, 0, MakeSignature.CMS); return signedPdf.toByteArray(); } catch (DocumentException e) { throw new RuntimeException(e); } catch (GeneralSecurityException e) { throw new RuntimeException(e); } }
From source file:ec.rubrica.pdf.FirmaPDF.java
License:Open Source License
public static byte[] firmar(byte[] pdf, PrivateKey pk, Certificate[] chain, TSAClient tsaClient) throws IOException { try {/*from ww w.j a v a 2 s .c o m*/ // Creating the reader and the stamper PdfReader reader = new PdfReader(pdf); ByteArrayOutputStream signedPdf = new ByteArrayOutputStream(); PdfStamper stamper = PdfStamper.createSignature(reader, signedPdf, '\0'); // Creating the appearance PdfSignatureAppearance appearance = stamper.getSignatureAppearance(); appearance.setReason("Testing"); appearance.setLocation("Quito"); appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig"); // Creating the signature PrivateKeySignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA1, null); OcspClient ocsp = new OcspClientBouncyCastle(); MakeSignature.signDetached(appearance, pks, chain, null, ocsp, tsaClient, BouncyCastleProvider.PROVIDER_NAME, 0, MakeSignature.CMS); return signedPdf.toByteArray(); } catch (DocumentException e) { throw new RuntimeException(e); } catch (GeneralSecurityException e) { throw new RuntimeException(e); } }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String insertSignature(String src, String dest, String Keystore, String name, String password, int masterHeight, int masterWidth, int pageNum) throws GeneralSecurityException, IOException, DocumentException { float[] scalar = scale(1, 1, 120, 32, masterHeight, masterWidth, pageNum); float[] trans = translate(1, 1, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight, masterWidth, pageNum);//from w ww. j ava 2s . c o m float[] f = commentTrans(1, 1, masterHeight, masterWidth, pageNum); float shift = 0; float pageChunk = r[pageNum - 1].getHeight() / 10; shift = r[pageNum - 1].getHeight() / 100; scalar[1] = (int) (pageChunk); scalar[0] = (int) (120 * pageChunk) / 32; trans[0] = (int) (0 + (pageChunk * widthScalar)); trans[1] = (int) (r[pageNum - 1].getHeight() - (pageChunk * heightScalar) - (shift * (heightScalar + 2))); heightScalar = heightScalar + 1; if (heightScalar == 8) { heightScalar = 0; widthScalar = widthScalar + 2; } /* Addition. ftorres - 7/22/2015 - Added to account for rotated pages * with the origin (0,0) not set to the bottom-left of the page. [1400] */ trans = translateRotation(trans[0], trans[1], pageNum); Rectangle cropBox = pds.getReader().getCropBox(1); Rectangle rectangle = new Rectangle(trans[0] + shift, trans[1] - scalar[1], trans[0] + shift + 120, trans[1] - scalar[1] + 32); BouncyCastleProvider provider = new BouncyCastleProvider(); Security.addProvider(provider); KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(new FileInputStream(Keystore), password.toCharArray()); String alias = (String) ks.aliases().nextElement(); PrivateKey pk = (PrivateKey) ks.getKey(alias, password.toCharArray()); Certificate[] chain = ks.getCertificateChain(alias); // Creating the reader and the stamper PdfReader reader = new PdfReader(src); FileOutputStream os = new FileOutputStream(dest); PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0'); // Creating the appearance PdfSignatureAppearance appearance = stamper.getSignatureAppearance(); appearance.setVisibleSignature(rectangle, 1, name); // Creating the signature ExternalSignature pks = new PrivateKeySignature(pk, "SHA-256", "BC"); ExternalDigest digest = new BouncyCastleDigest(); MakeSignature.signDetached(appearance, digest, pks, chain, null, null, null, 0, CryptoStandard.CMS); return ""; }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String insertComment(String sx, String sy, String id, String deptValue, String userInit, String comment, int pageNum, int masterHeight, int masterWidth, int pinned, int customFontSize) throws DocumentException, IOException { float ratio = getRatio(masterHeight, masterWidth, pageNum); float x = Float.parseFloat(sx); float y = Float.parseFloat(sy); float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum); PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(1);/*from ww w .ja va 2s .c o m*/ if (customFontSize > 0) fontSize = customFontSize; PdfContentByte fg = pds.getOverContent(pageNum); fg.setGState(gs1); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight, masterWidth, pageNum); // comment tag image (width=35pts, height=8pts) float[] scalar = scale(trans[0], trans[1], 35, 8, masterHeight, masterWidth, pageNum); /* Addition. ftorres - 7/21/2015 - Added to account for rotated pages * with the origin (0,0) not set to the bottom-left of the page. [1400] */ float coords[] = translateRotation(trans[0], trans[1], pageNum); coords = checkBounds(coords[0], coords[1], pageNum); /* Addition. ftorres - 10/20/2015 - If the comment was pinned in EPC, then * render the comment inside a comment box. */ if (pinned == 1) { insertPinnedComment(coords[0], coords[1], id + " - " + deptValue + " (" + userInit + ")", comment, pageNum, masterHeight, masterWidth); // Add the pinned comment text to page annotation -Jon Changkachith 11/24/2015 Rectangle rect = new Rectangle(0, 0, 0, 0); PdfAnnotation annotation = PdfAnnotation.createText(pds.getWriter(), rect, id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), true, id); pds.addAnnotation(annotation, pds.getWriter().getCurrentPageNumber()); } else { Image image = Image.getInstance(commentIMGPath); image.setAbsolutePosition(coords[0] + (scalar[0] * (id.length() / 5f)), coords[1]); /* * Commented out by Jon Changkachith 12/09/2015 because it was throwing * DocumentException with the message "The image must have absolute positioning." image.scaleAbsoluteHeight(1); image.scaleAbsoluteWidth(1); */ image.scalePercent(ratio); //Added to fix DocumentException "The image must have absolute positioning." Jon Changkachith 12/09/2015 image.setAnnotation(new Annotation(id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), 0, 0, 0, 0)); fg.addImage(image); } fg.setLineWidth(.5f * ratio); fg.setColorStroke(new BaseColor(Color.decode("0x6E2405").getRGB())); fg.setColorFill(new BaseColor(Color.decode("0x6E2405").getRGB())); float tHeight = scalar[1]; float tWidth = 0; if (id.length() > 3) { tWidth = (scalar[0] * (id.length() / 5f)); } else { tWidth = (scalar[0]); } fg.moveTo(coords[0], coords[1]); fg.lineTo(coords[0] + (10f * ratio), coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] + (tHeight / 2)); fg.lineTo(coords[0] + (10f * ratio), coords[1] + (tHeight / 2)); fg.lineTo(coords[0], coords[1]); fg.closePathFillStroke(); fg.fill(); // Comment number that goes on the comment tag image Phrase p = new Phrase(id); p.getFont().setColor(BaseColor.WHITE); p.getFont().setSize(8f * ratio); //comment number font size = 8f //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id)); float fs[] = translateRotation(f[0], f[1], pageNum); fs = checkBounds(fs[0], fs[1], pageNum); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, p, (float) (fs[0] + (9 * ratio)), (float) (fs[1] - (3 * ratio)), 0); return ""; }