List of usage examples for com.itextpdf.text Image getInstance
public static Image getInstance(final Image image)
From source file:Outras.GerarPdf.java
public GerarPdf(Os os) { //Criar um documento vazio Document documentoPDF = new Document(); try {/*from ww w . j a va 2s .c o m*/ //cria uma instancia do documento e da o nome dele na saida informada PdfWriter.getInstance(documentoPDF, new FileOutputStream("C:\\OrdensDeServico\\OS_" + os.getId())); //abertura do documento documentoPDF.open(); //especificar o layout da pagina; j cria a primeria pagina documentoPDF.setPageSize(PageSize.A4); ////adicionando pargrafos na primeira folha //adicionando titulo documentoPDF.addTitle("Ordem de Servio"); //adicionando imagens da OS e redimensionando Image imagem = Image.getInstance( "C:\\Users\\aluno\\Documents\\NetBeansProjects\\e-commerce\\src\\material\\imagemOs.png"); imagem.scaleToFit(200, 200); documentoPDF.add(imagem); //adicionando o primeiro paragrafo documentoPDF.add(new Paragraph("ORDEM DE SERVIO EMITIDA PELO CARRINHO DO USUARIO: " + os.getEntrega().getEndereco().getUsuario().getNome())); documentoPDF .add(new Paragraph("Endereo de entrega: " + os.getEntrega().getEndereco().getLogradouro())); documentoPDF.add(new Paragraph("Entregador: " + os.getEntrega().getFuncionario().getNome())); documentoPDF.add(new Paragraph("Produtos: ")); for (Produto p : os.getCarrinho().getProdutos()) { documentoPDF.add(new LineSeparator()); documentoPDF.add(new Paragraph(p.getNome())); } documentoPDF.add(new LineSeparator()); } catch (DocumentException de) { JOptionPane.showMessageDialog(null, "Erro ao gerar o pdf" + de.getMessage()); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Erro ao gerar o pdf" + ioe.getMessage()); } finally { documentoPDF.close(); } }
From source file:PDF.CrearPDF_Ficha.java
public void generarPDF(ServletOutputStream sops, DatosPDF datos, String url) { try {/* ww w .ja va 2 s.c o m*/ Document documento = new Document(); // ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(documento, sops); documento.open(); Image itt_logo; try { itt_logo = Image.getInstance(url); Image Logo_itt = Image.getInstance(itt_logo); Logo_itt.setAbsolutePosition(50f, 698f); Logo_itt.scaleAbsolute(90, 100); documento.add(Logo_itt); } catch (BadElementException | IOException ex) { Logger.getLogger(CrearPDF_Ficha.class.getName()).log(Level.SEVERE, null, ex); } PdfContentByte rectangulo_info = writer.getDirectContentUnder(); drawRectangle(rectangulo_info, 430, 648, 90, 100); Paragraph leyendaFoto = new Paragraph("\nFOTO:\n", FontFactory.getFont("arial", 14, Font.BOLD)); leyendaFoto.setIndentationLeft(200f); Paragraph titulo = new Paragraph("INSTITUTO TECNOLGICO DE TOLUCA", FontFactory.getFont("arial", 14)); titulo.setAlignment(Element.ALIGN_CENTER); Paragraph asunto = new Paragraph("FICHA DE EXAMEN", FontFactory.getFont("arial", 12)); asunto.setAlignment(Element.ALIGN_CENTER); Chunk folio1 = new Chunk("FICHA PARA EL EXAMEN DE ADMISIN: ", FontFactory.getFont("arial", 10)); Chunk folio2 = new Chunk(datos.getFicha(), FontFactory.getFont("arial", 10, Font.BOLD)); Phrase fol = new Phrase(); fol.add(folio1); fol.add(folio2); Paragraph noFicha = new Paragraph(fol); noFicha.setAlignment(Element.ALIGN_LEFT); Chunk nombre1 = new Chunk("NOMBRE DEL SOLICITANTE: ", FontFactory.getFont("arial", 10)); Chunk nombre2 = new Chunk(datos.getNombre(), FontFactory.getFont("arial", 10, Font.BOLD)); Phrase nom = new Phrase(); nom.add(nombre1); nom.add(nombre2); Paragraph nombre = new Paragraph(nom); nombre.setAlignment(Element.ALIGN_LEFT); Chunk in1 = new Chunk("PROCESO PARA EL REGISTRO DE ASPIRANTES EN EL PERIODO: ", FontFactory.getFont("arial", 10)); Chunk in2 = new Chunk(datos.getPeriodoConcursa().toUpperCase(), FontFactory.getFont("arial", 10, Font.BOLD)); Phrase in = new Phrase(); in.add(in1); in.add(in2); Paragraph instrucciones = new Paragraph(in); instrucciones.setAlignment(Element.ALIGN_LEFT); Chunk folCen1 = new Chunk("1.- NMERO DE FOLIO CENEVAL: ", FontFactory.getFont("arial", 10)); Chunk folCen2 = new Chunk(datos.getFolioCENEVAL(), FontFactory.getFont("arial", 10, Font.BOLD)); Phrase folC = new Phrase(); folC.add(folCen1); folC.add(folCen2); Paragraph folioCENEVAL = new Paragraph(folC); folioCENEVAL.setAlignment(Element.ALIGN_LEFT); Chunk fechas1 = new Chunk("2.- LOS EX?MENES DE ADMISIN SE APLICAR?N LOS D?AS: ", FontFactory.getFont("arial", 10)); Chunk fechas2 = new Chunk(datos.getFechaExamenCeneval() + " (" + datos.getLugarExamenCeneval() + ")", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk fechas3 = new Chunk(" Y ", FontFactory.getFont("arial", 10)); Chunk fechas4 = new Chunk(datos.getFechaExamenMate() + " (" + datos.getLugarExamenMate() + ")", FontFactory.getFont("arial", 10, Font.BOLD)); Phrase fechas = new Phrase(); fechas.add(fechas1); fechas.add(fechas2); fechas.add(fechas3); fechas.add(fechas4); Paragraph fechaExamenes = new Paragraph(fechas); fechaExamenes.setAlignment(Element.ALIGN_LEFT); Phrase lugar = new Phrase(); Paragraph lugarYhora = new Paragraph(lugar); lugarYhora.setAlignment(Element.ALIGN_LEFT); Chunk paginaPub1 = new Chunk( "3.- LA PUBLICACIN DE LOS RESULTADOS SER? NICAMENTE EN LA P?GINA WEB: ", FontFactory.getFont("arial", 10)); Anchor url_itt = new Anchor(datos.getPagResultados()); url_itt.setReference(datos.getPagResultados()); Phrase pag = new Phrase(); pag.add(paginaPub1); pag.add(url_itt); Paragraph pagWeb = new Paragraph(pag); Chunk diaPub1 = new Chunk("EL D?A: ", FontFactory.getFont("arial", 10)); Chunk diaPub2 = new Chunk(convertir(datos.getDiaPublicacion() + "-"), FontFactory.getFont("arial", 10, Font.BOLD)); Phrase dia = new Phrase(); dia.add(diaPub1); dia.add(diaPub2); Paragraph diaResultados = new Paragraph(dia); diaResultados.setAlignment(Element.ALIGN_LEFT); Chunk notas = new Chunk("\nNOTAS:\n", FontFactory.getFont("arial", 14, Font.BOLD)); Chunk uno = new Chunk("1.- ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk guias = new Chunk("Guas de estudio:\n - (CENEVAL) \n", FontFactory.getFont("arial", 10)); Anchor url_guia_cen = new Anchor(" " + datos.getEstudioCeneval()); // url_guia_cen.setReference(datos.getEstudioCeneval()); Chunk ceneval_inter = new Chunk("\n - (CENEVAL INTERACTIVA) \n", FontFactory.getFont("arial", 10)); Anchor url_guia_cen_inter = new Anchor(" " + datos.getEstudioCenevalInt()); url_guia_cen_inter.setReference(datos.getEstudioCenevalInt()); Chunk tem_mate_itt = new Chunk("\n - Temario de Matemticas (TECNOLGICO DE TOLUCA)\n\n", FontFactory.getFont("arial", 10)); Chunk dos = new Chunk("2.- ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk veri = new Chunk("Verifique que el nmero de folio de Ceneval de esta ficha, coincida con el", FontFactory.getFont("arial", 10)); Chunk fol_ceneval = new Chunk(" FOLIO CENEVAL ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk capturado = new Chunk("capturado en la informacin proporcionada por el Tecnlogico.\n\n", FontFactory.getFont("arial", 10)); Chunk tres = new Chunk("3.- ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk dia_exam = new Chunk( "El da del examen deber presentarse con el presente documento, pase de ingreso al examen(Ceneval), una identificacin con fotografa reciente(credencial escolar, IMSS, ISSSTE, ISSEMYM, licencia, pasaporte), lpiz del nmero 2 y goma.\n\n", FontFactory.getFont("arial", 10)); Chunk cuatro = new Chunk("4.- ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk curso = new Chunk( "Si curs sus estudios de secundaria o bachillerato en el extranjero deber presentar revalidacin de estudios correspondientes al momento de la inscripcin.\n", FontFactory.getFont("arial", 10)); Chunk cinco = new Chunk("\n5.- ", FontFactory.getFont("arial", 10, Font.BOLD)); Chunk examenes = new Chunk( "Los exmenes que se evaluarn son: 1) ADMISIN Y DIAGNSTICO. 2) MATEM?TICAS.", FontFactory.getFont("arial", 10)); Phrase ulti = new Phrase(); ulti.add(notas); ulti.add(uno); ulti.add(guias); ulti.add(url_guia_cen); ulti.add(ceneval_inter); ulti.add(url_guia_cen_inter); ulti.add(tem_mate_itt); ulti.add(dos); ulti.add(veri); ulti.add(fol_ceneval); ulti.add(capturado); ulti.add(tres); ulti.add(dia_exam); ulti.add(cuatro); ulti.add(curso); ulti.add(cinco); ulti.add(examenes); Paragraph ultimo = new Paragraph(ulti); ultimo.setAlignment(Element.ALIGN_LEFT); documento.addTitle("Ficha de Examen"); documento.addSubject("Instituto Tecnolgico de Toluca"); documento.addKeywords("Instituto Tecnolgico de Toluca"); documento.addAuthor("Departamento de Servicios escolares"); documento.addCreator("Departamento de Servicios escolares"); documento.add(titulo); documento.add(asunto); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(noFicha); documento.add(nombre); documento.add(new Paragraph(" ")); documento.add(instrucciones); documento.add(new Paragraph(" ")); documento.add(folioCENEVAL); documento.add(fechaExamenes); documento.add(lugarYhora); documento.add(pagWeb); documento.add(diaResultados); documento.add(new Paragraph(" ")); documento.add(ultimo); documento.close(); } catch (DocumentException ex) { Logger.getLogger(CrearPDF_Ficha.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:pdf.FooterHeader.java
License:Open Source License
@Override public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(3); try {/*w w w . j a va2 s . c o m*/ if (document.getPageNumber() > 1) { table.setWidths(new int[] { 24, 24, 2 }); table.setTotalWidth(527); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.addCell(header); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(String.format("Seite %d von", writer.getPageNumber())); PdfPCell cell = new PdfPCell(Image.getInstance(total)); cell.setBorder(Rectangle.BOTTOM); table.addCell(cell); table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent()); } } catch (DocumentException de) { throw new ExceptionConverter(de); } PdfContentByte cb = writer.getDirectContent(); if (document.getPageNumber() > 1) { footer = new Phrase(document.getPageNumber() - 2); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer, (document.right() - document.left() - 30) / 2 + document.leftMargin(), document.bottom() + 10, 0); } }
From source file:PDF.PDFTrackGenerator.java
License:Open Source License
/** * Metda generateTrackPDFA4 sli na samotn vygenerovanie PDF dokumentu trasy na formt A4. * @param lineWeight - hrbka ?iary trasy na mape * @param color - farba ?iary trasy na mape * @param width - rka mapy/*from w w w. j a v a2 s . c o m*/ * @param height - vka mapy * @param scale - klovacia kontanta mapy (n x rozlenie mapy) * @param startDate - dtum a ?as prvho bodu trasy * @param endDate - dtum a ?as poslednho bodu trasy * @param activity - aktivita trasy * @param user - pouvate (majite) trasy */ public void generateTrackPDFA4(int lineWeight, String color, int width, int height, int scale, String startDate, String endDate, String activity, String user) { try { Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(path + fileName + ".pdf")); doc.open(); Font nadpisFont = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD); Font detailyFont = new Font(Font.FontFamily.HELVETICA, 9, Font.NORMAL); Paragraph nadpisPar = new Paragraph(); nadpisPar.setAlignment(Element.ALIGN_CENTER); Phrase nadpis = new Phrase(fileName, nadpisFont); nadpisPar.add(nadpis); nadpisPar.add(""); doc.add(nadpisPar); doc.add(Chunk.NEWLINE); PdfPTable tabulka = new PdfPTable(2); tabulka.setWidthPercentage(100); float[] columnWidth = { 6f, 4f }; tabulka.setWidths(columnWidth); StaticMapResolver res = new StaticMapResolver(loader); String mapUrl = res.getStaticMapTrackURLWithMultimedia(lineWeight, color, width, height, scale); Image img = Image.getInstance(new URL(mapUrl)); //img.scalePercent(50); PdfPCell riadokSObr = new PdfPCell(img, true); riadokSObr.setBorder(Rectangle.NO_BORDER); riadokSObr.setPaddingBottom(10f); PdfPCell riadokSText = new PdfPCell(new Phrase("Description: " + loader.getTrackDescription() + "\n\n\nTrack activity: " + activity.substring(4) + "\n\n\nStart place: " + loader.getStartAddress() + "\n\n\nEnd Place: " + loader.getEndAddress() + "\n\n\nTrack length: " + loader.getLength() + " km\n\n\nMin elevation: " + loader.getMinElevation() + " m\n\n\nMax elevation: " + loader.getMaxElevation() + " m\n\n\nHeight difference: " + loader.getHeightDiff() + " m\n\n\nStart: " + startDate + "\n\n\nEnd: " + endDate + "\n\n\nDuration: " + loader.getDuration(), detailyFont)); riadokSText.setBorder(Rectangle.NO_BORDER); riadokSText.setPaddingLeft(20f); riadokSText.setPaddingTop(5f); riadokSText.setPaddingBottom(10f); tabulka.addCell(riadokSObr); tabulka.addCell(riadokSText); doc.add(tabulka); //doc.add(new Phrase("\n", detailyFont)); PdfPTable obrTabulka = new PdfPTable(3); obrTabulka.setWidthPercentage(100); ArrayList<String> goodFiles = new ArrayList<String>(); for (int i = 0; i < loader.getMultimediaFiles().size(); i++) { if (!loader.getMultimediaFiles().get(i).getPath().startsWith("YTB")) { String extension = loader.getMultimediaFiles().get(i).getPath().substring( loader.getMultimediaFiles().get(i).getPath().lastIndexOf("."), loader.getMultimediaFiles().get(i).getPath().length()); String newPath = loader.getMultimediaFiles().get(i).getPath().substring(0, loader.getMultimediaFiles().get(i).getPath().lastIndexOf(".")) + "_THUMB" + extension; goodFiles.add(newPath); } } if (!goodFiles.isEmpty()) { int freeCount = 9; if (goodFiles.size() <= 9) { for (int i = 0; i < goodFiles.size(); i++) { Image tempImg = Image.getInstance(goodFiles.get(i)); tempImg.scalePercent(10f); PdfPCell tempCell = new PdfPCell(tempImg, true); tempCell.setPadding(3f); //tempCell.setPaddingTop(5f); tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); tempCell.setHorizontalAlignment(Element.ALIGN_CENTER); tempCell.setFixedHeight(130f); tempCell.setBackgroundColor(BaseColor.BLACK); tempCell.setBorderColor(BaseColor.WHITE); tempCell.setBorderWidth(4f); //tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } for (int i = 0; i < 9 - goodFiles.size(); i++) { PdfPCell tempCell = new PdfPCell(); tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } } else if (goodFiles.size() <= 18) { for (int i = 0; i < 9; i++) { Image tempImg = Image.getInstance(goodFiles.get(i)); tempImg.scalePercent(10f); PdfPCell tempCell = new PdfPCell(tempImg, true); tempCell.setPadding(3f); //tempCell.setPaddingTop(5f); tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); tempCell.setHorizontalAlignment(Element.ALIGN_CENTER); tempCell.setFixedHeight(130f); tempCell.setBackgroundColor(BaseColor.BLACK); tempCell.setBorderColor(BaseColor.WHITE); tempCell.setBorderWidth(4f); //tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } } else { for (int i = 0; i < (goodFiles.size() % 9); i++) { goodFiles.remove(goodFiles.size() - 1 - i); } int counting = (goodFiles.size() / 9); for (int i = 0; i < goodFiles.size(); i = i + counting) { Image tempImg = Image.getInstance(goodFiles.get(i)); tempImg.scalePercent(10f); PdfPCell tempCell = new PdfPCell(tempImg, true); tempCell.setPadding(3f); //tempCell.setPaddingTop(5f); tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); tempCell.setHorizontalAlignment(Element.ALIGN_CENTER); tempCell.setFixedHeight(130f); tempCell.setBackgroundColor(BaseColor.BLACK); tempCell.setBorderColor(BaseColor.WHITE); tempCell.setBorderWidth(4f); //tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); freeCount--; } for (int i = 0; i < freeCount; i++) { PdfPCell tempCell = new PdfPCell(); tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } } } doc.add(obrTabulka); Font lastFont = new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC); Phrase lastText = new Phrase("This PDF document was generated by gTrax app for user " + user, lastFont); doc.add(lastText); doc.close(); } catch (Exception ex) { FileLogger.getInstance() .createNewLog("ERROR: Cannot CREATE PDF for track " + fileName + " for user " + user + " !!!"); System.out.println("pruser"); } }
From source file:PDF.Reportes.java
public void reportesPDF(HttpServletResponse response, int tr, ServletContext d, String usuario, String contra, String horario, int opc) { String reporteT = ""; try {/*from w w w .j a v a2 s. c o m*/ Document reporte = new Document(); Calendar cal = Calendar.getInstance(); Paragraph intro = new Paragraph(); intro.setAlignment(Element.ALIGN_CENTER); String linea = "/Imagenes/rallita.png"; String absolute_url_linea = d.getRealPath(linea); Image linea_div = Image.getInstance(absolute_url_linea); Paragraph vacio = new Paragraph(" ", FontFactory.getFont("arial", 10)); vacio.setAlignment(Element.ALIGN_CENTER); if (tr == 0) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png"); writer.setPageEvent(event); reporte.open(); reporte.add(vacio); reporte.add(vacio); ArrayList<JFreeChart> graf = grafica(usuario, contra); if (graf == null) { intro = new Paragraph( "Lo sentimos, por el momento an no existe informacin para este reporte.", FontFactory.getFont("arial", 18)); reporte.add(intro); } else { for (int i = 0; i < graf.size(); i++) { BufferedImage bufferedImage = graf.get(i).createBufferedImage(500, 300); Image chart = Image.getInstance(writer, bufferedImage, 1.0f); reporte.add(vacio); reporte.add(chart); } } reporteT = "Estadsticas de registros."; } if (tr == 1) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png"); writer.setPageEvent(event); reporte.open(); reporte.add(linea_div); Paragraph creador = new Paragraph("Instituto Tecnolgico de Toluca\n" + "\n" + "Centro de Cmputo\n" + "\n" + "Coordinacin de Desarrollo de Sistemas", FontFactory.getFont("arial", 10)); reporte.add(creador); reporte.add(linea_div); intro = new Paragraph("Sin alta en CENEVAL " + cal.get(Calendar.YEAR), FontFactory.getFont("arial", 18)); intro.setAlignment(Element.ALIGN_CENTER); reporte.add(intro); reporte.add(vacio); reporte.add(vacio); reporte.add(noaltaCen(usuario, contra)); reporteT = "Sin alta en CENEVAL."; } if (tr == 2) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png"); writer.setPageEvent(event); reporte.open(); reporte.add(linea_div); Paragraph creador = new Paragraph("Instituto Tecnolgico de Toluca\n" + "\n" + "Centro de Cmputo\n" + "\n" + "Coordinacin de Desarrollo de Sistemas", FontFactory.getFont("arial", 10)); reporte.add(creador); reporte.add(linea_div); intro = new Paragraph("Estatus Prefichas " + cal.get(Calendar.YEAR), FontFactory.getFont("arial", 18)); intro.setAlignment(Element.ALIGN_CENTER); reporte.add(intro); reporte.add(vacio); reporte.add(vacio); reporte.add(statusfichas(usuario, contra)); reporteT = "Estatus prefichas"; } if (tr == 3) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent("header_pdf.png"); writer.setPageEvent(event); reporte.open(); reporte.add(linea_div); Paragraph creador = new Paragraph("Instituto Tecnolgico de Toluca\n" + "\n" + "Centro de Cmputo\n" + "\n" + "Coordinacin de Desarrollo de Sistemas", FontFactory.getFont("arial", 10)); reporte.add(creador); reporte.add(linea_div); intro = new Paragraph("Pre proceso concluido " + cal.get(Calendar.YEAR), FontFactory.getFont("arial", 18)); intro.setAlignment(Element.ALIGN_CENTER); reporte.add(intro); reporte.add(vacio); reporte.add(vacio); reporte.add(procesoCon(usuario, contra)); reporteT = "Pre proceso concluido"; } if (tr == 4) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); ArrayList<PdfPTable> tables = firmasAspAula(usuario, contra, horario, opc); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent2 event = new HeaderFooterPageEvent2("ficha-pdf.png"); writer.setPageEvent(event); reporte.open(); if (tables.size() != 1) { PdfPTable tableH = tables.get(tables.size() - 1); tableH.writeSelectedRows(0, -1, 10, 720, writer.getDirectContent()); } else { reporte.add(tables.get(0)); } reporte.add(vacio); reporte.add(vacio); reporte.add(vacio); for (int i = 0; i < tables.size(); i++) { if (i + 1 != tables.size()) { reporte.add(tables.get(i)); if (i + 2 != tables.size()) { reporte.newPage(); } } } reporteT = "Firmas Aspirantes_" + horario; } if (tr == 5) { PdfWriter writer = PdfWriter.getInstance(reporte, response.getOutputStream()); ArrayList<PdfPTable> tables = tablaAspAula(usuario, contra, horario, opc); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent2 event = new HeaderFooterPageEvent2("ficha-pdf.png"); writer.setPageEvent(event); reporte.open(); if (tables.size() != 1) { PdfPTable tableH = tables.get(tables.size() - 1); tableH.writeSelectedRows(0, -1, 10, 720, writer.getDirectContent()); } else { reporte.add(tables.get(0)); } reporte.add(vacio); reporte.add(vacio); reporte.add(vacio); for (int i = 0; i < tables.size(); i++) { if (i + 1 != tables.size()) { reporte.add(tables.get(i)); if (i + 2 != tables.size()) { reporte.newPage(); } } } reporteT = "Aspirantes por aula horario_" + horario; } reporte.addTitle("Reportes_" + reporteT); reporte.addSubject("Instituto Tecnolgico de Toluca"); reporte.addKeywords("Instituto Tecnolgico de Toluca"); reporte.addAuthor("Coordinacion de desarrollo de sistemas"); reporte.addCreator("Centro de Cmputo ITT"); //Asignamos el manejador de eventos al escritor. reporte.close(); } catch (DocumentException | IOException ex) { Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:pdf.watermark.java
License:Open Source License
public watermark() { try {/*from ww w . j a v a 2 s . co m*/ PdfReader Read_PDF_To_Watermark = new PdfReader( "D:\\Dropbox\\Studium\\Bachelor Thesis\\Resourcen\\pdfexport\\xmltopdf\\test.pdf"); int number_of_pages = Read_PDF_To_Watermark.getNumberOfPages(); PdfStamper stamp = new PdfStamper(Read_PDF_To_Watermark, new FileOutputStream( "D:\\Dropbox\\Studium\\Bachelor Thesis\\Resourcen\\pdfexport\\xmltopdf\\New_PDF_With_Watermark_Image.pdf")); int i = 0; Image watermark_image = Image .getInstance("D:\\Dropbox\\Studium\\Bachelor Thesis\\Resourcen\\pdfexport\\xmltopdf\\desy.png"); watermark_image.setAbsolutePosition(50, 150); watermark_image.scaleToFit(500, 500); PdfContentByte add_watermark; while (i < number_of_pages) { i++; add_watermark = stamp.getUnderContent(i); add_watermark.addImage(watermark_image); } stamp.close(); } catch (IOException | DocumentException i1) { i1.printStackTrace(); } }
From source file:pdfcompressor.PDFCompressor.java
public void outputPDF(String pathToOutput) throws FileNotFoundException, DocumentException, BadElementException, IOException { com.itextpdf.text.Image itextImg; Document outDocument = new Document(); outDocument.setMargins(0f, 0f, 0f, 0f); PdfWriter writer = PdfWriter.getInstance(outDocument, new FileOutputStream(pathToOutput)); writer.setFullCompression();/* w w w .j av a 2 s .c o m*/ writer.open(); outDocument.open(); int progress = 0; for (java.awt.Image img : getBuffedImg()) { itextImg = Image.getInstance(getImageByteArray(img, compressRate)); itextImg.scaleToFit(595f, 842f); outDocument.add(itextImg); for (ProgressListener listener : saveListener) { listener.haveProgress(++progress, numOfPages); } } outDocument.close(); writer.close(); for (ProgressListener listener : saveListener) { listener.finished(); } }
From source file:pdfcompressor.PDFCompressor.java
public void getFileSize() throws DocumentException, IOException { com.itextpdf.text.Image itextImg; Document outDocument = new Document(); outDocument.setMargins(0f, 0f, 0f, 0f); ByteArrayOutputStream memoryOutput = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(outDocument, memoryOutput); writer.setFullCompression();// ww w .j av a2 s .c o m writer.open(); outDocument.open(); for (java.awt.Image img : getBuffedImg()) { itextImg = Image.getInstance(getImageByteArray(img, compressRate)); itextImg.scaleToFit(595f, 842f); outDocument.add(itextImg); } outDocument.close(); writer.close(); for (ProgressListener listener : sizeEstimateListener) { listener.finished(memoryOutput.toByteArray().length); } }
From source file:pdfcreator.PDFCreator.java
License:Open Source License
@SuppressWarnings("static-access") protected void createPdf(String filename, String[] images) throws Exception { Document doc = new Document(); PdfWriter writer;/*from w w w . j a v a 2 s . co m*/ if (pdfxConformance.equals("PDFA1A")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_1A); } else if (pdfxConformance.equals("PDFA1B")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_1B); } else if (pdfxConformance.equals("PDFA2A")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_2A); } else if (pdfxConformance.equals("PDFA2B")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_2B); } else if (pdfxConformance.equals("PDFA3A")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_3A); } else if (pdfxConformance.equals("PDFA3B")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_3B); } else { writer = PdfWriter.getInstance(doc, new FileOutputStream(filename)); } if (pdfVersion.equals("1.4")) { writer.setPdfVersion(PdfWriter.VERSION_1_4); } else if (pdfVersion.equals("1.5")) { writer.setPdfVersion(PdfWriter.VERSION_1_5); } else if (pdfVersion.equals("1.6")) { writer.setPdfVersion(PdfWriter.VERSION_1_6); } else if (pdfVersion.equals("1.7")) { writer.setPdfVersion(PdfWriter.VERSION_1_7); } else { writer.setPdfVersion(PdfWriter.VERSION_1_4); } verbose(filename + ": open"); doc.addCreationDate(); doc.addCreator(creator); if (title != null) { doc.addTitle(title); } for (int i = 0; i < images.length; i++) { verbose(" +" + images[i]); Image img = Image.getInstance(images[i]); doc.setPageSize(new Rectangle(img.getWidth(), img.getHeight())); doc.setMargins(0, 0, 0, 0); if (doc.isOpen()) { doc.newPage(); } else { doc.open(); } doc.add(img); doc.newPage(); } ICC_Profile icc = getImageColorProfile(images[0]); if (icc == null) { System.err.println("warning: no color profile available in " + images[0] + " using " + profileName); icc = getDefaultColorProfile(); } writer.setOutputIntents("Custom", "", null, null, icc); writer.createXmpMetadata(); doc.close(); verbose(filename + ": close"); }
From source file:pdfcreator.PDFCreator.java
License:Open Source License
protected ICC_Profile getImageColorProfile(String filename) { try {/*from w w w . j ava2 s.c o m*/ Image img = Image.getInstance(filename); ICC_Profile icc = img.getICCProfile(); return icc; } catch (BadElementException ex) { Logger.getLogger(PDFCreator.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(PDFCreator.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PDFCreator.class.getName()).log(Level.SEVERE, null, ex); } return null; }