List of usage examples for com.itextpdf.text Image setAbsolutePosition
public void setAbsolutePosition(final float absoluteX, final float absoluteY)
Image
. From source file:com.github.albfernandez.joinpdf.JoinPdf.java
License:Open Source License
private void addImage(final Image image, final Document document, final PdfWriter writer) throws Exception { if (image.getWidth() > image.getHeight()) { document.setPageSize(new Rectangle(PageSize.A4.getHeight(), PageSize.A4.getWidth())); } else {//from w w w . j a v a 2 s . c om document.setPageSize(new Rectangle(PageSize.A4.getWidth(), PageSize.A4.getHeight())); } image.scaleToFit(document.getPageSize().getWidth() - this.margin * 2f, document.getPageSize().getHeight() - this.margin * 2f); float px = (document.getPageSize().getWidth() - image.getScaledWidth()) / 2f; float py = (document.getPageSize().getHeight() - image.getScaledHeight()) / 2f; image.setAbsolutePosition(px, py); document.newPage(); document.add(image); writePageNumber(writer); }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public Boolean createFrontCoverPage(Document document, String coverTitle, Bitmap photo) throws DocumentException, MalformedURLException, IOException { if (photo != null) { int imageMaxWidth; int imageMaxHeight; int imagePosX; int imagePosY; if (photo.getWidth() < photo.getHeight()) { imageMaxWidth = 900;/*from w w w . j ava2 s.com*/ imageMaxHeight = 1200; imagePosX = 198; imagePosY = 379; } else { imageMaxWidth = 1200; imageMaxHeight = 900; imagePosX = 162; imagePosY = 379; } OutputStream stream = new ByteArrayOutputStream(); ImageUtilities.scaleCenterCrop(photo, imageMaxWidth, imageMaxHeight).compress(CompressFormat.JPEG, 50, stream); Image coverImage = Image.getInstance(stream.toByteArray()); coverImage.setAbsolutePosition(0.0f, 0.0f); PdfTemplate t = this.writer.getDirectContent().createTemplate((float) imageMaxWidth, (float) imageMaxHeight); t.newPath(); t.moveTo(0.0f, (float) imageMaxHeight); t.lineTo(0.0f, 71.0f); t.lineTo(17.0f, 71.0f); t.lineTo(17.0f, 0.0f); t.lineTo(72.0f, 71.0f); t.lineTo((float) imageMaxWidth, 71.0f); t.lineTo((float) imageMaxWidth, (float) imageMaxHeight); t.lineTo(0.0f, (float) imageMaxHeight); t.closePath(); t.clip(); t.newPath(); t.addImage(coverImage); t.setColorStroke(new BaseColor(0, 0, 0)); t.setLineWidth(BUBBLE_TEXT_INDENT_ALTERNATE); t.newPath(); t.moveTo(0.0f, (float) imageMaxHeight); t.lineTo(0.0f, 71.0f); t.lineTo(17.0f, 71.0f); t.lineTo(17.0f, 0.0f); t.lineTo(72.0f, 71.0f); t.lineTo((float) imageMaxWidth, 71.0f); t.lineTo((float) imageMaxWidth, (float) imageMaxHeight); t.lineTo(0.0f, (float) imageMaxHeight); t.closePathStroke(); Image clipped = Image.getInstance(t); clipped.scalePercent(24.0f); clipped.setAbsolutePosition((float) imagePosX, (float) imagePosY); clipped.setCompressionLevel(this.settings.compressionLevel); clipped.setAlignment(5); document.add(clipped); } if (coverTitle != null && coverTitle.length() > 0) { PdfContentByte canvas = this.writer.getDirectContent(); Paragraph coverTitleEl = new Paragraph(coverTitle, this.serifFont24); coverTitleEl.setAlignment(1); PdfPTable table = new PdfPTable(1); table.setTotalWidth(311.0f); PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.addElement(coverTitleEl); cell.setPadding(0.0f); cell.setIndent(0.0f); table.addCell(cell); table.completeRow(); table.writeSelectedRows(0, -1, 147.0f, 390.0f, canvas); } return Boolean.valueOf(true); }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public Boolean createBackCoverPage(Document document, String backCoverNote) throws DocumentException, MalformedURLException, IOException { document.newPage();/* w ww . j a v a 2s . c om*/ Image backCoverImageFrame = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/txtbook_backpage_300.png")); backCoverImageFrame.scalePercent(24.0f); backCoverImageFrame.setAbsolutePosition(87.0f, 78.0f); backCoverImageFrame.setCompressionLevel(this.settings.compressionLevel); document.add(backCoverImageFrame); PdfContentByte canvas = this.writer.getDirectContent(); PdfPTable table = new PdfPTable(1); table.setTotalWidth(215.0f); if (backCoverNote != null && backCoverNote.length() > 0) { Paragraph backCoverEl = new Paragraph(backCoverNote, this.serifFont14); PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.addElement(backCoverEl); cell.setPadding(13.0f); cell.setIndent(0.0f); cell.setFixedHeight(310.0f); table.addCell(cell); table.completeRow(); } Element backUrl = new Anchor("txt-book.com", this.sansFont11Gray); backUrl.setName("txt-book.com"); backUrl.setReference("http://www.txt-book.com"); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(2); paragraph.add(backUrl); PdfPCell cell2 = new PdfPCell(); cell2.setBorder(0); cell2.setHorizontalAlignment(2); cell2.addElement(paragraph); cell2.setPadding(0.0f); cell2.setPaddingTop(0.0f); cell2.setIndent(0.0f); table.addCell(cell2); table.completeRow(); table.writeSelectedRows(0, -1, 306.0f, 400.0f, canvas); return Boolean.valueOf(true); }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public void addConversationBackground(Document document, ColumnText ct, int column, float top, float messageWidth, float messageHeight, Boolean isMe) throws DocumentException, MalformedURLException, IOException { float[][] COLUMNS; if (messageWidth < MAX_COLUMN_CONTENT_WIDTH) { messageWidth += 8.0f;//from w w w . j ava 2s . c om } messageHeight -= 35.0f; top -= BaseField.BORDER_WIDTH_THICK; if (COLUMNS_REG[0][0] == Txtbook.leftMargin(this.writer, document, this.settings.addFrontCover)) { COLUMNS = COLUMNS_REG; } else { COLUMNS = COLUMNS_ALT; } float left = COLUMNS[column][0]; PdfContentByte under = this.writer.getDirectContentUnder(); PdfTemplate bg = this.writer.getDirectContentUnder().createTemplate( (BUBBLE_L_WIDTH + messageWidth) + BUBBLE_R_WIDTH, (BUBBLE_T_HEIGHT + messageHeight) + BUBBLE_L_WIDTH); String num = isMe.booleanValue() ? "1" : "2"; Image bgTL = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/bubble_" + num + "_tl.png")); bgTL.scaleAbsoluteWidth(BUBBLE_L_WIDTH); bgTL.scaleAbsoluteHeight(BUBBLE_T_HEIGHT); bgTL.setAbsolutePosition(0.0f, BUBBLE_L_WIDTH + messageHeight); bg.addImage(bgTL); Image bgT = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/bubble_" + num + "_t.png")); bgT.scaleAbsoluteWidth(messageWidth); bgT.scaleAbsoluteHeight(BUBBLE_T_HEIGHT); bgT.setAbsolutePosition(BUBBLE_L_WIDTH, BUBBLE_L_WIDTH + messageHeight); bg.addImage(bgT); Image bgTR = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/bubble_" + num + "_tr.png")); bgTR.scaleAbsoluteWidth(BUBBLE_R_WIDTH); bgTR.scaleAbsoluteHeight(BUBBLE_T_HEIGHT); bgTR.setAbsolutePosition(BUBBLE_L_WIDTH + messageWidth, BUBBLE_L_WIDTH + messageHeight); bg.addImage(bgTR); Image bgL = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/bubble_" + num + "_l.png")); bgL.scaleAbsoluteWidth(BUBBLE_L_WIDTH); bgL.scaleAbsoluteHeight(messageHeight); bgL.setAbsolutePosition(0.0f, BUBBLE_L_WIDTH); bg.addImage(bgL); bg.saveState(); if (isMe.booleanValue()) { bg.setRGBColorFill(241, 241, 241); } else { bg.setRGBColorFill(208, 231, 196); } bg.rectangle(BUBBLE_L_WIDTH, BUBBLE_L_WIDTH, messageWidth, messageHeight); bg.fill(); bg.restoreState(); Image bgR = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/bubble_" + num + "_r.png")); bgR.scaleAbsoluteWidth(BUBBLE_R_WIDTH); bgR.scaleAbsoluteHeight(messageHeight); bgR.setAbsolutePosition(BUBBLE_L_WIDTH + messageWidth, BUBBLE_L_WIDTH); bg.addImage(bgR); Image bgBL = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/bubble_" + num + "_bl.png")); bgBL.scaleAbsoluteWidth(BUBBLE_L_WIDTH); bgBL.scaleAbsoluteHeight(BUBBLE_L_WIDTH); bgBL.setAbsolutePosition(0.0f, 0.0f); bg.addImage(bgBL); Image bgB = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/bubble_" + num + "_b.png")); bgB.scaleAbsoluteWidth(messageWidth); bgB.scaleAbsoluteHeight(BUBBLE_L_WIDTH); bgB.setAbsolutePosition(BUBBLE_L_WIDTH, 0.0f); bg.addImage(bgB); Image bgBR = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/bubble_" + num + "_br.png")); bgBR.scaleAbsoluteWidth(BUBBLE_R_WIDTH); bgBR.scaleAbsoluteHeight(BUBBLE_L_WIDTH); bgBR.setAbsolutePosition(BUBBLE_L_WIDTH + messageWidth, 0.0f); bg.addImage(bgBR); if (!isMe.booleanValue()) { bg.setMatrix(BUBBLE_TEXT_INDENT_MAIN, 0.0f, 0.0f, BaseField.BORDER_WIDTH_THIN, 0.0f, 0.0f); left += COLUMN_WIDTH; } under.addTemplate(bg, left, (top - messageHeight) - 20.0f); }
From source file:com.javaPdf.app.GeneradorContrato.java
public static void writePDF() { // Document document = new Document() ; Document document = new Document(PageSize.LETTER, 65, 65, 60, 60); try {// w w w . j av a2 s. c om /*Font que usaran las palabras destacadas con NEGRITA*/ Font font_negrita = FontFactory.getFont("Times New Roman"); font_negrita.setSize(11); font_negrita.setStyle(Font.BOLD); font_negrita.setFamily(Font.FontFamily.TIMES_ROMAN.toString()); Scanner sc = new Scanner(System.in); Calendar calendarioGragoriano = new GregorianCalendar(12, Calendar.MONTH, 2017); /*Inicializar un objeto de tipo Calendar con un metodo de clase (Static) el cual obtiene una onstancia de la clase puede ser mas sencillo*/ Calendar calendario = Calendar.getInstance(); System.out.println(Calendar.DAY_OF_MONTH); System.out.println(calendario.getTime()); /*Datos ingresados por teclado*/ System.out.println("Ingrese el NOMBRE DEL EMPLEADOR: "); Chunk nombreEmpleador = new Chunk("[EMPLEADOR]", font_negrita); System.out.println("Ingrese el RUT DEL EMPLEADOR: "); Chunk rutEmpleador = new Chunk("xx.xxx.xxx-x", font_negrita); System.out.println("Ingrese el NOMBRE DEL TRABAJADOR: "); // Chunk nombreTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita); Chunk nombreTrabajador = new Chunk(sc.nextLine(), font_negrita); System.out.println("Ingrese el RUT DEL TRABAJADOR: "); // Chunk rutTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita); Chunk rutTrabajador = new Chunk(sc.nextLine(), font_negrita); System.out.println("Ingrese la DIRECCIN DEL TRABAJADOR: "); // Chunk direccionTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita); Chunk direccionTrabajador = new Chunk(sc.nextLine(), font_negrita); System.out.println("Ingrese la COMUNA DEL TRABAJADOR: "); // Chunk comunaTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita); Chunk comunaTrabajador = new Chunk(sc.nextLine(), font_negrita); System.out.println("Ingrese la FECHA DE NACIMIENTO DEL TRABAJADOR: "); // Chunk fechaNacimientoTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita); Chunk fechaNacimientoTrabajador = new Chunk(sc.nextLine(), font_negrita); System.out.println("Ingrese el SUELDO QUE TENDRA EL TRABAJADOR: "); // Chunk sueldoTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita); Chunk sueldoTrabajador = new Chunk(sc.nextLine(), font_negrita); System.out.println("Ingrese la FUNCION QUE TENDRA EL TRABAJADOR: "); // Chunk funcionTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita); Chunk funcionTrabajador = new Chunk(sc.nextLine().toUpperCase(), font_negrita); System.out.println("Ingrese la FECHA DE INICIO DE CONTRATO DEL TRABAJADOR: "); // Chunk fechaInicioContrato = new Chunk ("DATO DE PRUEBA", font_negrita); Chunk fechaInicioContrato = new Chunk(sc.nextLine(), font_negrita); System.out.println("Ingrese la FECHA DE TERMINO DE CONTRATO DEL TRABAJADOR: "); // Chunk fechaTerminoContrato = new Chunk ("DATO DE PRUEBA", font_negrita); Chunk fechaTerminoContrato = new Chunk(sc.nextLine(), font_negrita); /*Clausulas*/ Chunk primero = new Chunk(TEXTOPRIMERO, font_negrita); Chunk segundo = new Chunk(TEXTOSEGUNDO, font_negrita); Chunk tercero = new Chunk(TEXTOTERCERO, font_negrita); Chunk cuarto = new Chunk(TEXTOCUARTO, font_negrita); Chunk quinto = new Chunk(TEXTOQUINTO, font_negrita); Chunk sexto = new Chunk(TEXTOSEXTO, font_negrita); Chunk septimo = new Chunk(TEXTOSEPTIMO, font_negrita); Chunk octavo = new Chunk(TEXTOOCTAVO, font_negrita); Chunk noveno = new Chunk(TEXTONOVENO, font_negrita); // Chunk afp = new Chunk (TEXTONOVENO2, font_negrita); // Chunk salud = new Chunk (TEXTONOVENO4, font_negrita); // Chunk cesantia = new Chunk (TEXTONOVENO6, font_negrita); Chunk decimo = new Chunk(TEXTODECIMO, font_negrita); Chunk undecimo = new Chunk(TEXTOUNDECIMO, font_negrita); // Calendar calendario = Calendar.getInstance(); SimpleDateFormat formateador = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", new Locale("es")); Date fechaDate = new Date(); Chunk fecha = new Chunk(formateador.format(fechaDate), font_negrita); String path = new File(".").getCanonicalPath(); String FILE_NAME = path + "/CONTRATO " + nombreTrabajador + " RUT " + rutTrabajador + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(new File(FILE_NAME))); // Image firmaEmpleador = Image.getInstance(path + "/img/firmaEmpleador.png"); // firmaEmpleador.scaleAbsoluteWidth(150f); // firmaEmpleador.scaleAbsoluteHeight(70f); // firmaEmpleador.setAbsolutePosition(70f, 200f); // Image timbreGerencia = Image.getInstance(path + "/img/timbreGerencia.png"); timbreGerencia.scaleAbsoluteWidth(90f); timbreGerencia.scaleAbsoluteHeight(75f); timbreGerencia.setAbsolutePosition(230, 200f); // Image firmaTrabajador = Image.getInstance(path + "/img/firmaTrabajador.png"); firmaTrabajador.scaleAbsoluteWidth(160f); firmaTrabajador.scaleAbsoluteHeight(70f); firmaTrabajador.setAbsolutePosition(350, 175f); // // Image todoEnUno = Image.getInstance(path + "/img/todoEnUno.png"); // todoEnUno.scaleAbsoluteWidth(550); // todoEnUno.scaleAbsoluteHeight(150); // todoEnUno.setAbsolutePosition(15, 120f); document.open(); FontFactory.registerDirectories(); /*Parrafo de Titulo*/ String tituloContrato_texto = "CONTRATO DE TRABAJO:\n"; Font font_titulo = FontFactory.getFont("Times New Roman"); font_titulo.setSize(14); font_titulo.setStyle(Font.BOLD | Font.UNDERLINE); font_titulo.setFamily(Font.FontFamily.TIMES_ROMAN.toString()); Paragraph parrafoTitulo = new Paragraph(tituloContrato_texto, font_titulo); parrafoTitulo.setAlignment(Element.ALIGN_CENTER); document.add(parrafoTitulo); Font font_primer_parrafo = FontFactory.getFont("Times New Roman"); font_primer_parrafo.setSize(11); // font_primer_parrafo.setStyle(Font.BOLD | Font.UNDERLINE); font_primer_parrafo.setFamily(Font.FontFamily.TIMES_ROMAN.toString()); Paragraph primer_parrafo = new Paragraph(); /*Agregar CHunks a el parrafo*/ /*PRIMER PARRAFO*/ primer_parrafo.setAlignment(Element.ALIGN_JUSTIFIED); primer_parrafo.setLeading(15); primer_parrafo.setFont(font_primer_parrafo); primer_parrafo.add(TEXTO1); primer_parrafo.add(fecha); primer_parrafo.add(TEXTO2); primer_parrafo.add(nombreEmpleador); primer_parrafo.add(TEXTO3); primer_parrafo.add(rutEmpleador); primer_parrafo.add(TEXTO4); primer_parrafo.add(nombreTrabajador); primer_parrafo.add(TEXTO5); primer_parrafo.add(rutTrabajador); primer_parrafo.add(TEXTO6); primer_parrafo.add(direccionTrabajador); primer_parrafo.add(TEXTO7); primer_parrafo.add(comunaTrabajador); primer_parrafo.add(TEXTO8); primer_parrafo.add(fechaNacimientoTrabajador); primer_parrafo.add(TEXTO9); /*PRIMERA CLAUSULA*/ primer_parrafo.add(primero); primer_parrafo.add(TEXTOPRIMERO1); primer_parrafo.add(funcionTrabajador); primer_parrafo.add(TEXTOPRIMERO2); /*SEGUNDA CLAUSULA*/ primer_parrafo.add(segundo); // primer_parrafo.add(TEXTOSEGUNDO1); /*TERCERA CLAUSULA*/ primer_parrafo.add(tercero); primer_parrafo.add(TEXTOTERCERO1); primer_parrafo.add(Chunk.TABBING); primer_parrafo.add(TEXTOTERCERO2A); primer_parrafo.add(sueldoTrabajador); primer_parrafo.add(TEXTOTERCERO3A); primer_parrafo.add(Chunk.TABBING); primer_parrafo.add(TEXTOTERCERO4B); /*CUARTA CLAUSULA*/ primer_parrafo.add(cuarto); // primer_parrafo.add(TEXTOCUARTO1); /*QUINTA CLAUSULA*/ primer_parrafo.add(quinto); // primer_parrafo.add(TEXTOQUINTO1); /*SEXTA CLAUSULA*/ primer_parrafo.add(sexto); // primer_parrafo.add(TEXTOSEXTO1); /*SEPTIMA CLAUSULA*/ primer_parrafo.add(septimo); // primer_parrafo.add(TEXTOSEPTIMO1); primer_parrafo.add(Chunk.TABBING); // primer_parrafo.add(TEXTOSEPTIMO2A); primer_parrafo.add(Chunk.TABBING); // primer_parrafo.add(TEXTOSEPTIMO3B); primer_parrafo.add(Chunk.TABBING); // primer_parrafo.add(TEXTOSEPTIMO4C); primer_parrafo.add(Chunk.TABBING); // primer_parrafo.add(TEXTOSEPTIMO5D); primer_parrafo.add(Chunk.TABBING); // primer_parrafo.add(TEXTOSEPTIMO6E); primer_parrafo.add(Chunk.TABBING); // primer_parrafo.add(TEXTOSEPTIMO7F); primer_parrafo.add(Chunk.TABBING); // primer_parrafo.add(TEXTOSEPTIMO8G); primer_parrafo.add(Chunk.TABBING); // primer_parrafo.add(TEXTOSEPTIMO9H); /*OCTAVA CLAUSULA*/ primer_parrafo.add(octavo); // primer_parrafo.add(TEXTOOCTAVO1); /*NOVENA CLAUSULA*/ primer_parrafo.add(noveno); // primer_parrafo.add(TEXTONOVENO1); // primer_parrafo.add(afp); // primer_parrafo.add(TEXTONOVENO3); // primer_parrafo.add(salud); // primer_parrafo.add(TEXTONOVENO5); // primer_parrafo.add(cesantia); /*public static final String TEXTONOVENO2 = " PROVIDA"; public static final String TEXTONOVENO3 = " Salud:"; public static final String TEXTONOVENO4 = "FONASA"; public static final String TEXTONOVENO5 = ", y las de cesanta en:"; public static final String TEXTONOVENO6 = " AFC. \n\n";*/ /*DCIMA CLAUSULA*/ primer_parrafo.add(decimo); primer_parrafo.add(TEXTODECIMO1); primer_parrafo.add(fechaInicioContrato); primer_parrafo.add(TEXTODECIMO2); primer_parrafo.add(fechaTerminoContrato); primer_parrafo.add(TEXTODECIMO3); /*UNDECIMA CLAUSULA*/ primer_parrafo.add(undecimo); // primer_parrafo.add(TEXTOUNDECIMO1); document.add(primer_parrafo); // document.add(todoEnUno); document.add(timbreGerencia); document.add(firmaTrabajador); document.addAuthor("IGVI"); document.addTitle("CONTRATO DE TRABAJO IGVI"); document.close(); } catch (DocumentException e) { e.getMessage(); } catch (IOException e) { e.getMessage(); } }
From source file:com.kohmiho.mpsr.export.PDFGenerator.java
protected void addPageByImage(PdfWriter writer, PdfImportedPage page) throws BadElementException, DocumentException { Image image = Image.getInstance(page); image.setAbsolutePosition(36, 36); image.scalePercent(90);//from ww w . ja va2 s. c om writer.getDirectContentUnder().addImage(image); writer.setPageEmpty(false); }
From source file:com.kohmiho.mpsr.export.PDFGenerator.java
private void generatePageHeader(Document document, PdfContentByte directContentUnder, Image image, Phrase[] headerTexts) {// w w w . ja v a2s . co m float left = document.getPageSize().getLeft(36); float top = document.getPageSize().getTop(36); float right = document.getPageSize().getRight(36); try { image.setAbsolutePosition(right - 150, top - 20); // image.setAlignment(Element.ALIGN_RIGHT); image.scalePercent(25); directContentUnder.addImage(image); } catch (DocumentException e) { } int i = 0; for (Phrase headerText : headerTexts) { ColumnText.showTextAligned(directContentUnder, Element.ALIGN_LEFT, headerText, left + 36, top - 10 * (i++), 0); } }
From source file:com.mui.certificate.core.HalalCertification.java
License:Apache License
@Override public void exportCertificate(Certificate cert, File outputPdf) throws Exception { ByteMatrix matrix = generateQRCode(cert.getCertificateURL().toString()); int scale = sMagicNumber / matrix.getWidth(); BufferedImage buffImage = convertToImage(matrix, scale); File tempOutput = new File("tmp-qrcode.png"); ImageIO.write(buffImage, "png", tempOutput); Image itImage = Image.getInstance(tempOutput.getCanonicalPath()); PdfReader reader = new PdfReader("doc/template_certificate_halal.pdf"); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputPdf)); int centerY = 715; int centerX = 135; itImage.setAbsolutePosition(centerX - (itImage.getWidth() / 2), centerY - (itImage.getHeight() / 2)); stamper.getOverContent(1).addImage(itImage); AcroFields form1 = stamper.getAcroFields(); String nameHeader = "topmostSubform[0].Page1[0]."; form1.setField(nameHeader + "no_certificate[0]", cert.getCertificateNumber().toString()); form1.setField(nameHeader + "name_product[0]", cert.getProductName()); form1.setField(nameHeader + "type_product[0]", cert.getProductType()); form1.setField(nameHeader + "name_company[0]", cert.getCompanyName()); form1.setField(nameHeader + "company_address[0]", cert.getCompanyAddress()); Calendar cal = Calendar.getInstance(new Locale("id")); Locale idLocale = new Locale("id"); cal.setTime(cert.getIssuedDate());// w w w. j a va2s . c o m form1.setField(nameHeader + "issued_date[0]", String.format(idLocale, "%1$tA, %1$te %1$tB %1$tY", cal)); cal.setTime(cert.getValidDate()); form1.setField(nameHeader + "expired_date[0]", String.format(idLocale, "%1$tA, %1$te %1$tB %1$tY", cal)); stamper.setFormFlattening(true); stamper.close(); tempOutput.delete(); }
From source file:com.mycompany.mavenproject1.Createpdf.java
private void generateLayout(Document doc, PdfContentByte cb) { try {/*from ww w . ja v a 2 s. com*/ cb.setLineWidth(1f); // Invoice Header box layout cb.rectangle(420, 700, 150, 60); cb.moveTo(420, 720); cb.lineTo(570, 720); cb.moveTo(420, 740); cb.lineTo(570, 740); cb.moveTo(480, 700); cb.lineTo(480, 760); cb.stroke(); // Invoice Header box Text Headings createHeadings(cb, 422, 743, "Account No."); createHeadings(cb, 422, 723, "Invoice No."); createHeadings(cb, 422, 703, "Invoice Date"); // Invoice Detail box layout cb.rectangle(20, 50, 550, 600); cb.moveTo(20, 630); cb.lineTo(570, 630); cb.moveTo(50, 50); cb.lineTo(50, 650); cb.moveTo(150, 50); cb.lineTo(150, 650); cb.moveTo(430, 50); cb.lineTo(430, 650); cb.moveTo(500, 50); cb.lineTo(500, 650); cb.stroke(); // Invoice Detail box Text Headings createHeadings(cb, 22, 633, "Qty"); createHeadings(cb, 52, 633, "Item Number"); createHeadings(cb, 152, 633, "Item Description"); createHeadings(cb, 432, 633, "Price"); createHeadings(cb, 502, 633, "Ext Price"); //add the images Image companyLogo = Image.getInstance("images/olympics_logo.gif"); companyLogo.setAbsolutePosition(25, 700); companyLogo.scalePercent(25); doc.add(companyLogo); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.norbsoft.pdfconverter.helpers.PDFHelper.java
License:Open Source License
public int generate(String saveUrl, SerializableBitmap sign, Form form, ArrayList<String> photos, ArrayList<String> workers) { try {/*from www .j a v a 2 s . co m*/ Document document = new Document(); url = saveUrl; PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(url)); document.setMargins(20, 20, 20, 20); document.open(); Bitmap inputLogo = BitmapFactory.decodeStream(context.getAssets().open("logo.jpg")); ByteArrayOutputStream outstream = new ByteArrayOutputStream(); inputLogo.compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image logo = Image.getInstance(outstream.toByteArray()); Bitmap inputQR = BitmapFactory.decodeStream(context.getAssets().open("qr.jpg")); outstream = new ByteArrayOutputStream(); inputQR.compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image qr = Image.getInstance(outstream.toByteArray()); outstream = new ByteArrayOutputStream(); sign.getImage().compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image sgn = Image.getInstance(outstream.toByteArray()); qr.scaleAbsolute(90f, 90f); qr.setAbsolutePosition(340f, 705f); logo.scaleAbsolute(150f, 50f); logo.setAbsolutePosition(50f, 750f); sgn.scaleAbsolute(130f, 30f); sgn.setAbsolutePosition(25f, 75f); Paragraph p = new Paragraph("\r\n\r\n\r\nMPWiK S.A.\r\n50-421 Wrocaw\r\nul.Na Grobli 14-16", normal); p.setIndentationLeft(420f); document.add(p); p = new Paragraph("RAPORT WYMIANY WODOMIERZA", bold); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingBefore(60f); document.add(p); document.add(table(form)); p = new Paragraph(form.getInformations(), normal); p.setAlignment(Element.ALIGN_LEFT); p.setIndentationLeft(50f); p.setSpacingBefore(20f); document.add(p); document.add(signTable(form, sgn, workers)); document.add(logo); document.add(qr); if (photos != null && photos.size() > 0) { document.newPage(); for (int i = 0; i < photos.size(); i++) { try { if (photos.get(i) != null && !photos.get(i).equals("")) { Log.d(TAG, photos.get(i)); Bitmap temp = PictureHelper.bitmapFromUrl(photos.get(i)); outstream = new ByteArrayOutputStream(); temp.compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image photo = Image.getInstance(outstream.toByteArray()); photo.scaleToFit(document.getPageSize().getWidth() - 50, document.getPageSize().getHeight()); document.add(photo); } } catch (Exception e) { } } } document.close(); writer.close(); return 1; } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); return 0; } catch (DocumentException e) { Log.e(TAG, e.getMessage()); return 0; } catch (IOException e) { Log.e(TAG, e.getMessage()); return 0; } catch (Exception e) { Log.e(TAG, e.getMessage()); return 0; } }