List of usage examples for com.itextpdf.text Rectangle Rectangle
public Rectangle(final float urx, final float ury)
Rectangle
-object starting from the origin (0, 0). From source file:ro.nextreports.engine.exporter.PdfExporter.java
License:Apache License
protected void initExport() throws QueryException { Padding margins = bean.getReportLayout().getPagePadding(); if (!bean.isSubreport()) { float footerHeight = computeFooterHeight(); Rectangle rectangle;//from w w w.j a v a 2 s .com if (ReportLayout.CUSTOM.equals(bean.getReportLayout().getPageFormat())) { PaperSize customSize = bean.getReportLayout().getPaperSize(); rectangle = new Rectangle(customSize.getWidthPoints(), customSize.getHeightPoints()); } else { rectangle = PageSize.getRectangle(bean.getReportLayout().getPageFormat()); } document = new Document(rectangle, getPoints(margins.getLeft()), getPoints(margins.getRight()), getPoints(margins.getTop()), getPoints(margins.getBottom()) + footerHeight); if (bean.getReportLayout().getOrientation() == LANDSCAPE) { document.setPageSize(rectangle.rotate()); } } PdfWriter wr = null; try { if (!bean.isSubreport()) { wr = PdfWriter.getInstance(document, getOut()); wr.setPageEvent(new PdfPageEvent()); addMetaData(); document.open(); } table = buildPdfTable(PRINT_DOCUMENT); } catch (DocumentException e) { e.printStackTrace(); throw new QueryException(e); } }
From source file:se.billes.pdf.renderer.request.factory.SizeFactory.java
License:Open Source License
/** * // w ww .j av a 2 s. c om * @param request * @return {@link Rectangle} with cutmark if that is used transformed to postscript points */ public Rectangle getSizeAsRectangle(PdfDocument request) { float bothSidesOfCutmark = 0; if (request.getCutmarks() != null) { bothSidesOfCutmark = CUT_MARK * 2; } return new Rectangle(millimetersToPostscriptPoints(request.getSize()[0] + bothSidesOfCutmark), millimetersToPostscriptPoints(request.getSize()[1] + bothSidesOfCutmark)); }
From source file:shared.SVGtoPDF.java
License:Open Source License
/** * Creates a PDF document./*from w ww . j a va2 s . c o m*/ * @param path * @param filename the path to the new PDF document * @throws DocumentException * @throws IOException * @throws SQLException */ public void createPdf(String svgDocument, Point size, String path) throws IOException, DocumentException { svgDocument = convertSVG(svgDocument); Document document = new Document(new Rectangle(size.x, size.y)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path)); //writer.setRgbTransparencyBlending(false); writer.setDefaultColorspace(PdfName.DEFAULTCMYK, PdfName.DEFAULTCMYK); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate template = cb.createTemplate(size.x, size.y); drawSvg(svgDocument, template, size); cb.addTemplate(template, 0, 0); // step 5 document.close(); }
From source file:tn.esprit.twin1.brogrammers.eventify.Eventify.util.TicketGenerator.java
public static void GenerateTicket(Ticket ticket) { Document document = new Document(); try {//from w ww.j a va2s . com PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE)); Rectangle pagesize = new Rectangle(700, 300); document.open(); Paragraph emptyline = new Paragraph(); emptyline.add(new Paragraph(" ")); document.setPageSize(pagesize); document.newPage(); //PIC PdfContentByte canvas = writer.getDirectContentUnder(); Image image = Image.getInstance(IMAGE); //image.scaleAbsolute(pagesize.rotate()); image.setAbsolutePosition(0, 0); canvas.addImage(image); //PIC document.addTitle("Your Access To" + ticket.getEvent().getTitle()); document.addSubject(ticket.getEvent().getTheme()); document.addKeywords(ticket.getEvent().getTitle() + "Ticket"); document.addAuthor("Mohamed Firas Ouertani"); document.addCreator("Mohamed Firas Ouertani"); Paragraph prefacetitle = new Paragraph(); prefacetitle.add(new Paragraph("Your Ticket For " + ticket.getEvent().getTitle(), bigFont)); document.add(prefacetitle); document.add(emptyline); Paragraph prefacetime = new Paragraph(); prefacetime.add(new Paragraph(ticket.getEvent().getStartTime().toString(), greyFont)); document.add(prefacetime); document.add(emptyline); document.add(emptyline); Paragraph prefacetype = new Paragraph(); prefacetype.add(new Paragraph("You Reserved For: " + ticket.getTypeTicket(), catFont)); document.add(prefacetype); //QR BarcodeQRCode qrcode = new BarcodeQRCode( "REF:#" + ticket.getEvent().getId() + "" + ticket.getEvent().getTitle().trim(), 1, 1, null); Image qrcodeImage = qrcode.getImage(); qrcodeImage.setAbsolutePosition(520, 70); qrcodeImage.scalePercent(400); document.add(qrcodeImage); //QR //Bar PdfContentByte cb = writer.getDirectContent(); Barcode128 code128 = new Barcode128(); BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCode("REF:#" + ticket.getEvent().getId() + "" + ticket.getEvent().getTitle().trim()); codeEAN.setCodeType(BarcodeEAN.EAN13); Image codeEANImage = code128.createImageWithBarcode(cb, null, null); codeEANImage.setAbsolutePosition(10, 10); codeEANImage.scalePercent(125); document.add(codeEANImage); //Bar document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:tourma.views.report.HTMLtoPDF.java
public static void exportToPDF_Landscape(FileOutputStream output, String source, String title) { com.itextpdf.text.Rectangle A4H = new Rectangle(PageSize.A4.getHeight(), PageSize.A4.getWidth()); exportToPDF(output, source, title, A4H); }
From source file:uy.gub.imm.sae.web.mbean.reserva.PasoFinalMBean.java
License:Open Source License
public String imprimirTicket() { try {/* w w w . j a va2 s .c om*/ BaseColor colorBlack = new BaseColor(0, 0, 0); BaseFont times = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); BaseFont helveticaBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); BaseFont symbol = BaseFont.createFont(BaseFont.SYMBOL, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); SimpleDateFormat sdfHr = new SimpleDateFormat("HH:mm"); SimpleDateFormat sdfFecha = new SimpleDateFormat("dd/MM/yyyy"); Rectangle pageSize = new Rectangle(210, 210); Document document = new Document(pageSize); document.addTitle(getI18N().getText("etiqueta.reserva.title")); ByteArrayOutputStream os = new ByteArrayOutputStream(); PdfWriter pdfWriter = PdfWriter.getInstance(document, os); document.open(); PdfContentByte pdfContent = pdfWriter.getDirectContent(); InputStream is = PasoFinalMBean.class.getResourceAsStream(SAEProfile.getInstance().getProperties() .getProperty(SAEProfile.PROFILE_UI_TEMPLATES_IMAGES_LOGO_TICKET_KEY)); byte[] arrImage = new byte[4096]; is.read(arrImage); Image img = Image.getInstance(arrImage); img.scaleAbsolute(100, 30); img.setAbsolutePosition(55, 170); document.add(img); //Dibujo primer lnea LineSeparator line = new LineSeparator(); line.setAlignment(LineSeparator.ALIGN_CENTER); line.setLineColor(colorBlack); line.setLineWidth(0.5f); line.drawLine(pdfContent, 10, 200, 170); //Etiqueta RESERVA pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 15); pdfContent.setTextMatrix(45, 150); pdfContent.showText(getI18N().getText("etiqueta.reserva.showText")); pdfContent.endText(); //Fecha de la reserva String fecha_reserva = sdfFecha.format(sesionMBean.getDisponibilidad().getHoraInicio()); pdfContent.beginText(); pdfContent.setFontAndSize(symbol, 16); pdfContent.setTextMatrix(130, 150); pdfContent.showText(fecha_reserva); pdfContent.endText(); //Dibujo segunda lnea line.drawLine(pdfWriter.getDirectContent(), 10, 200, 140); int etiqHoraTamanio = 25; int etiqHoraX = 15; int etiqHoraY = 85; int valorHoraTamanio = 40; int valorHoraX = 105; int valorHoraY = 80; String serie = sesionMBean.getRecurso().getSerie(); boolean conSerie = (serie != null) && (serie.length() >= 1); if (sesionMBean.getRecurso().getMostrarNumeroEnTicket()) { if (!conSerie) { //Ajusto valor y etiqueta hora etiqHoraTamanio = 20; etiqHoraX = 15; etiqHoraY = 110; valorHoraTamanio = 30; valorHoraX = 120; valorHoraY = 107; //Etiqueta NUMERO pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 20); pdfContent.setTextMatrix(15, 65); pdfContent.showText(getI18N().getText("etiqueta.numero.numero")); pdfContent.endText(); //Numero de la reserva String nro = sesionMBean.getReservaConfirmada().getNumero().toString(); int nro_pos = 135; if (nro.length() == 1) { nro_pos = 135; } else if (nro.length() == 2) { nro_pos = 125; } else { nro_pos = 105; } pdfContent.beginText(); pdfContent.setFontAndSize(symbol, 60); pdfContent.setTextMatrix(nro_pos, 55); pdfContent.showText(nro); pdfContent.endText(); } else { //<<<<<< Agregado >>>>>> //Ajusto valor y etiqueta hora etiqHoraTamanio = 20; etiqHoraX = 15; etiqHoraY = 123; valorHoraTamanio = 20; valorHoraX = 120; valorHoraY = 122; //Etiqueta SERIE pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 20); pdfContent.setTextMatrix(15, 87); pdfContent.showText(getI18N().getText("etiqueta.numero.serie")); pdfContent.endText(); pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 20); pdfContent.setTextMatrix(120, 87); pdfContent.showText(serie); pdfContent.endText(); //Etiqueta NUMERO pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 20); pdfContent.setTextMatrix(15, 50); pdfContent.showText(getI18N().getText("etiqueta.numero.numero")); pdfContent.endText(); //Numero de la reserva String nro = sesionMBean.getReservaConfirmada().getNumero().toString(); int nro_pos = 135; if (nro.length() == 1) { nro_pos = 135; } else if (nro.length() == 2) { nro_pos = 125; } else { nro_pos = 105; } pdfContent.beginText(); pdfContent.setFontAndSize(symbol, 40); pdfContent.setTextMatrix(nro_pos, 47); pdfContent.showText(nro); pdfContent.endText(); } } //Etiqueta HORA pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, etiqHoraTamanio); pdfContent.setTextMatrix(etiqHoraX, etiqHoraY); pdfContent.showText(getI18N().getText("etiqueta.hora.hora")); pdfContent.endText(); //Hora de la reserva pdfContent.beginText(); pdfContent.setFontAndSize(symbol, valorHoraTamanio); pdfContent.setTextMatrix(valorHoraX, valorHoraY); pdfContent.showText(sdfHr.format(sesionMBean.getDisponibilidad().getHoraInicio())); pdfContent.endText(); //Dibujo tercer lnea line.drawLine(pdfWriter.getDirectContent(), 10, 200, 45); String ticketEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaUno(); String ticketEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaDos(); int largoEtiqUno = 0; int largoEtiqDos = 0; int xValores = 0; if (ticketEtiqUno != null) { largoEtiqUno = ticketEtiqUno.length(); } if (ticketEtiqDos != null) { largoEtiqDos = ticketEtiqDos.length(); } if (largoEtiqUno > largoEtiqDos) { xValores = 8 * (largoEtiqUno + 1); } else { xValores = 8 * (largoEtiqDos + 1); } //Etiqueta uno if (ticketEtiqUno != null) { pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 10); pdfContent.setTextMatrix(10, 30); pdfContent.showText(ticketEtiqUno + ":"); pdfContent.endText(); } //Valor etiqueta uno String valorEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaUno(); if (valorEtiqUno != null) { pdfContent.beginText(); pdfContent.setFontAndSize(times, 10); pdfContent.setTextMatrix(xValores, 30); pdfContent.showText(valorEtiqUno); pdfContent.endText(); } //Etiqueta dos if (ticketEtiqDos != null) { pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 10); pdfContent.setTextMatrix(10, 15); pdfContent.showText(ticketEtiqDos + ":"); pdfContent.endText(); } //Valor etiqueta dos String valorEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaDos(); if (valorEtiqDos != null) { pdfContent.beginText(); pdfContent.setFontAndSize(times, 10); pdfContent.setTextMatrix(xValores, 15); pdfContent.showText(valorEtiqDos); pdfContent.endText(); } pdfWriter.addJavaScript("this.print({bUI: true, bSilent: true, bShrinkToFit: true});", false); pdfWriter.addJavaScript("this.closeDoc(true);"); document.close(); FacesContext facesContext = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); response.setContentType("application/pdf"); os.writeTo(response.getOutputStream()); response.getOutputStream().flush(); response.getOutputStream().close(); facesContext.responseComplete(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:uy.gub.imm.sae.web.mbean.reserva.PasoFinalMBean.java
License:Open Source License
public String guardarTicket() { try {//w ww . ja va2 s.c o m BaseColor colorBlack = new BaseColor(0, 0, 0); BaseFont times = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); BaseFont helveticaBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); BaseFont symbol = BaseFont.createFont(BaseFont.SYMBOL, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); SimpleDateFormat sdfHr = new SimpleDateFormat("HH:mm"); SimpleDateFormat sdfFecha = new SimpleDateFormat("dd/MM/yyyy"); Rectangle pageSize = new Rectangle(210, 210); Document document = new Document(pageSize); document.addTitle(getI18N().getText("etiqueta.reserva.title")); ByteArrayOutputStream os = new ByteArrayOutputStream(); PdfWriter pdfWriter = PdfWriter.getInstance(document, os); document.open(); PdfContentByte pdfContent = pdfWriter.getDirectContent(); InputStream is = PasoFinalMBean.class.getResourceAsStream(SAEProfile.getInstance().getProperties() .getProperty(SAEProfile.PROFILE_UI_TEMPLATES_IMAGES_LOGO_TICKET_KEY)); byte[] arrImage = new byte[4096]; is.read(arrImage); Image img = Image.getInstance(arrImage); img.scaleAbsolute(100, 30); img.setAbsolutePosition(55, 170); document.add(img); //Dibujo primer lnea LineSeparator line = new LineSeparator(); line.setAlignment(LineSeparator.ALIGN_CENTER); line.setLineColor(colorBlack); line.setLineWidth(0.5f); line.drawLine(pdfContent, 10, 200, 170); //Etiqueta RESERVA pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 15); pdfContent.setTextMatrix(45, 150); pdfContent.showText(getI18N().getText("etiqueta.reserva.showText")); pdfContent.endText(); //Fecha de la reserva String fecha_reserva = sdfFecha.format(sesionMBean.getDisponibilidad().getHoraInicio()); pdfContent.beginText(); pdfContent.setFontAndSize(symbol, 16); pdfContent.setTextMatrix(130, 150); pdfContent.showText(fecha_reserva); pdfContent.endText(); //Dibujo segunda lnea line.drawLine(pdfWriter.getDirectContent(), 10, 200, 140); int etiqHoraTamanio = 25; int etiqHoraX = 15; int etiqHoraY = 85; int valorHoraTamanio = 40; int valorHoraX = 105; int valorHoraY = 80; String serie = sesionMBean.getRecurso().getSerie(); boolean conSerie = (serie != null) && (serie.length() >= 1); if (sesionMBean.getRecurso().getMostrarNumeroEnTicket()) { if (!conSerie) { //Ajusto valor y etiqueta hora etiqHoraTamanio = 20; etiqHoraX = 15; etiqHoraY = 110; valorHoraTamanio = 30; valorHoraX = 120; valorHoraY = 107; //Etiqueta NUMERO pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 20); pdfContent.setTextMatrix(15, 65); pdfContent.showText(getI18N().getText("etiqueta.numero.numero")); pdfContent.endText(); //Numero de la reserva String nro = sesionMBean.getReservaConfirmada().getNumero().toString(); int nro_pos = 135; if (nro.length() == 1) { nro_pos = 135; } else if (nro.length() == 2) { nro_pos = 125; } else { nro_pos = 105; } pdfContent.beginText(); pdfContent.setFontAndSize(symbol, 60); pdfContent.setTextMatrix(nro_pos, 55); pdfContent.showText(nro); pdfContent.endText(); } else { //Ajusto valor y etiqueta hora etiqHoraTamanio = 20; etiqHoraX = 15; etiqHoraY = 123; valorHoraTamanio = 20; valorHoraX = 120; valorHoraY = 122; //Etiqueta SERIE pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 20); pdfContent.setTextMatrix(15, 87); pdfContent.showText(getI18N().getText("etiqueta.numero.serie")); pdfContent.endText(); pdfContent.beginText(); pdfContent.setFontAndSize(symbol, 20); pdfContent.setTextMatrix(120, 87); pdfContent.showText(serie); pdfContent.endText(); //Etiqueta NUMERO pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 20); pdfContent.setTextMatrix(15, 50); pdfContent.showText(getI18N().getText("etiqueta.numero.numero")); pdfContent.endText(); //Numero de la reserva String nro = sesionMBean.getReservaConfirmada().getNumero().toString(); int nro_pos = 135; if (nro.length() == 1) { nro_pos = 135; } else if (nro.length() == 2) { nro_pos = 125; } else { nro_pos = 105; } pdfContent.beginText(); pdfContent.setFontAndSize(symbol, 40); pdfContent.setTextMatrix(nro_pos, 47); pdfContent.showText(nro); pdfContent.endText(); } } //Etiqueta HORA pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, etiqHoraTamanio); pdfContent.setTextMatrix(etiqHoraX, etiqHoraY); pdfContent.showText(getI18N().getText("etiqueta.hora.hora")); pdfContent.endText(); //Hora de la reserva pdfContent.beginText(); pdfContent.setFontAndSize(symbol, valorHoraTamanio); pdfContent.setTextMatrix(valorHoraX, valorHoraY); pdfContent.showText(sdfHr.format(sesionMBean.getDisponibilidad().getHoraInicio())); pdfContent.endText(); //Dibujo tercer lnea line.drawLine(pdfWriter.getDirectContent(), 10, 200, 45); String ticketEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaUno(); String ticketEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getTicketEtiquetaDos(); int largoEtiqUno = 0; int largoEtiqDos = 0; int xValores = 0; if (ticketEtiqUno != null) { largoEtiqUno = ticketEtiqUno.length(); } if (ticketEtiqDos != null) { largoEtiqDos = ticketEtiqDos.length(); } if (largoEtiqUno > largoEtiqDos) { xValores = 8 * (largoEtiqUno + 1); } else { xValores = 8 * (largoEtiqDos + 1); } //Etiqueta uno if (ticketEtiqUno != null) { pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 10); pdfContent.setTextMatrix(10, 30); pdfContent.showText(ticketEtiqUno + ":"); pdfContent.endText(); } //Valor etiqueta uno String valorEtiqUno = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaUno(); if (valorEtiqUno != null) { pdfContent.beginText(); pdfContent.setFontAndSize(times, 10); pdfContent.setTextMatrix(xValores, 30); pdfContent.showText(valorEtiqUno); pdfContent.endText(); } //Etiqueta dos if (ticketEtiqDos != null) { pdfContent.beginText(); pdfContent.setFontAndSize(helveticaBold, 10); pdfContent.setTextMatrix(10, 15); pdfContent.showText(ticketEtiqDos + ":"); pdfContent.endText(); } //Valor etiqueta dos String valorEtiqDos = sesionMBean.getRecurso().getTextoRecurso().getValorEtiquetaDos(); if (valorEtiqDos != null) { pdfContent.beginText(); pdfContent.setFontAndSize(times, 10); pdfContent.setTextMatrix(xValores, 15); pdfContent.showText(valorEtiqDos); pdfContent.endText(); } document.close(); FacesContext facesContext = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "attachment; filename=" + "Ticket de confirmacin.pdf"); os.writeTo(response.getOutputStream()); response.getOutputStream().flush(); response.getOutputStream().close(); facesContext.responseComplete(); } catch (Exception e) { e.printStackTrace(); } return null; }