List of usage examples for com.lowagie.text Image scalePercent
public void scalePercent(float percent)
From source file:questions.importpages.HelloWorldImportedPages.java
public static void main(String[] args) { // we create a PDF file createPdf(SOURCE);//from w w w . ja v a 2 s . co m // step 1 Document document = new Document(PageSize.A4); try { // we create a PdfReader object PdfReader reader = new PdfReader(SOURCE); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 PdfImportedPage page; for (int i = 1; i <= reader.getNumberOfPages(); i++) { page = writer.getImportedPage(reader, i); Image image = Image.getInstance(page); image.scalePercent(15f); image.setBorder(Rectangle.BOX); image.setBorderWidth(3f); image.setBorderColor(new GrayColor(0.5f)); image.setRotationDegrees(-reader.getPageRotation(i)); document.add(image); document.add(new Paragraph("This is page: " + i)); } } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } // step 5 document.close(); }
From source file:s2s.luna.reports.Report_REP_SOP.java
License:GNU General Public License
@Override public void doReport() throws DocumentException, IOException, BadElementException, Exception { SecurityWrapper Security = SecurityWrapper.getInstance(); ISopraluogoHome home1 = (ISopraluogoHome) PseudoContext.lookup("SopraluogoBean"); ISopraluogo bean = home1.findByPrimaryKey(new Long(new Long(request.getParameter("ID")))); IAnagrProcedimentoHome home_pro = (IAnagrProcedimentoHome) PseudoContext.lookup("AnagrProcedimentoBean"); IAnagrProcedimento bean_pro = home_pro.findByPrimaryKey(new Long(bean.getCOD_PRO())); IDipendenteHome home_dpd = (IDipendenteHome) PseudoContext.lookup("DipendenteBean"); ICantiereHome home_can = (ICantiereHome) PseudoContext.lookup("CantiereBean"); ICantiere bean_can = home_can.findByPrimaryKey(new Long(bean.getCOD_CAN())); IAnagrOpereHome home_ope = (IAnagrOpereHome) PseudoContext.lookup("AnagrOpereBean"); IAnagrOpere bean_ope = null;/*www .j av a2 s .c o m*/ long COD_OPE = bean.getCOD_OPE(); if (COD_OPE != 0) { bean_ope = home_ope.findByPrimaryKey(COD_OPE); } lCOD_AZL = Security.getAziendaR(); IAziendaHome home_az = (IAziendaHome) PseudoContext.lookup("AziendaBean"); IAzienda bean_az = home_az.findByPrimaryKey(new Long(lCOD_AZL)); initDocument("the doc", // Intestazione - Cella a sinistra bean_pro.getstrDES(), // Intestazione - Cella centrale bean_can.getNOM_CAN() + " - " + bean.getNUM_SOP(), // Pi di pagina Cella a sinistra bean_az.getRAG_SCL_AZL(), // Pi di pagina Cella a destra formatPlain(bean.getDAT_SOP())); m_handler.bShowDate = false; // LOGO E TITOLO { CenterMiddleTable tbl = new CenterMiddleTable(2); tbl.setDefaultCellBorder(0); int width[] = { 15, 75 }; tbl.setWidths(width); if (IncludeLogo) { Image png = loadImage("LOGO"); png.scalePercent(50); png.setAlignment(Image.ALIGN_LEFT); Cell cImage = new Cell(png); tbl.addCell(cImage); } else { tbl.addCell(""); } CenterMiddleTable tbl2 = new CenterMiddleTable(1); tbl2.setDefaultCellBorder(0); tbl2.addCellBU(ApplicationConfigurator.CUSTOMER_NAME.toUpperCase(), 15); tbl2.addCellBU(ApplicationConfigurator.LanguageManager.getString("Coordinamento.sicurezza.cantieri") .toUpperCase(), 15); Cell cText = new Cell(tbl2); tbl.addCell(cText); m_document.add(tbl); } writeIndent(); { CenterMiddleTable tbl = new CenterMiddleTable(1); if (bStandAlone) { } m_document.add(tbl); } // DATI DEL SOPRALLUOGO { CenterMiddleTable tbl = new CenterMiddleTable(4); tbl.toLeft(); int width[] = { 30, 20, 25, 25 }; tbl.setWidths(width); tbl.addCell( ApplicationConfigurator.LanguageManager.getString("Sopralluogo.N") + " " + bean.getNUM_SOP(), defaultFontSize); tbl.addCell(ApplicationConfigurator.LanguageManager.getString("del") + " " + formatPlain(bean.getDAT_SOP()), defaultFontSize); tbl.addCell( ApplicationConfigurator.LanguageManager.getString("Inizio.h") + (bean.getORA_INI() != null ? bean.getORA_INI().toString().substring(0, 5) : ""), defaultFontSize); tbl.addCell( ApplicationConfigurator.LanguageManager.getString("Fine.h") + (bean.getORA_FIN() != null ? bean.getORA_FIN().toString().substring(0, 5) : ""), defaultFontSize); m_document.add(tbl); } { CenterMiddleTable tbl = new CenterMiddleTable(3); tbl.toLeft(); int width[] = { 34, 33, 33 }; tbl.setWidths(width); tbl.addCell(ApplicationConfigurator.LanguageManager.getString("Linea") + ": " + bean_pro.getstrDES(), defaultFontSize); tbl.addCell( ApplicationConfigurator.LanguageManager.getString("Stazione") + ": " + bean_can.getNOM_CAN(), defaultFontSize); tbl.addCell(ApplicationConfigurator.LanguageManager.getString("Opera") + ": " + (bean_ope != null ? bean_ope.getstrNOM_OPE() : ""), defaultFontSize); m_document.add(tbl); } // PRESENTI AZIENDA { CenterMiddleTable tbl = new CenterMiddleTable(2); tbl.toLeft(); int width[] = { 25, 70 }; tbl.setWidths(width); tbl.border(); java.util.Collection col = home_dpd.getDipendentiBySOP_View(lCOD_SOP); tbl.addCell(ApplicationConfigurator.LanguageManager.getString("Presenti.RM"), defaultFontSize); java.util.Iterator it = col.iterator(); String presentiRM = ""; while (it.hasNext()) { DipendentiBySOP_View obj = (DipendentiBySOP_View) it.next(); presentiRM += (StringManager.isEmpty(presentiRM) ? "" : ", ") + obj.COG_DPD + " " + obj.NOM_DPD; } tbl.addCell(presentiRM, defaultFontSize); m_document.add(tbl); } // PRESENTI IMPRESA { CenterMiddleTable tbl = new CenterMiddleTable(2); tbl.toLeft(); tbl.setPadding(1 / 2); int width[] = { 25, 70 }; tbl.setWidths(width); tbl.border(); java.util.Collection col = home_dpd.getDipendentiEstBySOP_View(lCOD_SOP); java.util.Iterator it = col.iterator(); tbl.addCell(ApplicationConfigurator.LanguageManager.getString("Presenti.impresa"), defaultFontSize); String presentiIMP = ""; while (it.hasNext()) { DipendentiBySOP_View obj = (DipendentiBySOP_View) it.next(); presentiIMP += (StringManager.isEmpty(presentiIMP) ? "" : ", ") + obj.COG_DPD + " " + obj.NOM_DPD + " (" + obj.IMPRESA + ")"; } tbl.addCell(presentiIMP, defaultFontSize); m_document.add(tbl); } writeLine(); // CONSTATAZIONI { CenterMiddleTable tbl = new CenterMiddleTable(1); tbl.toLeft(); int width[] = { 100 }; tbl.setWidths(width); tbl.addHeaderCellB2(ApplicationConfigurator.LanguageManager.getString("CONSTATAZIONI"), 1, false, 11); m_document.add(tbl); } { CenterMiddleTable tbl = new CenterMiddleTable(2); tbl.toLeft(); int width[] = { 5, 85 }; tbl.setWidths(width); java.util.Collection col = home1.getConstatazioniSop(lCOD_SOP); java.util.Iterator it = col.iterator(); tbl.setWidths(width); String constElementSeparator = " - "; Alphabet c = new Alphabet(); String REV1 = c.getNextElement("1"); while (it.hasNext()) { jbConstatazione obj = (jbConstatazione) it.next(); // Numerazione alfabetica Cell cell = new Cell(new Phrase(Formatter.format(REV1), REPORT_SETTINGS.ftText9B)); cell.setVerticalAlignment(Element.ALIGN_TOP); tbl.addCell(cell); // Constatazione tbl.addCell(Formatter.format( (StringManager.isNotEmpty(obj.sRAG_SCL_DTE) ? obj.sRAG_SCL_DTE + constElementSeparator : "") + (StringManager.isNotEmpty(obj.sNOM_ATT) ? obj.sNOM_ATT + constElementSeparator : "") + (StringManager.isNotEmpty(obj.sDES_LIB) ? obj.sDES_LIB + constElementSeparator : "") + obj.sDESC), defaultFontSize); REV1 = c.getNextElement(REV1); } m_document.add(tbl); } writeLine(); // DISPOSIZIONI { CenterMiddleTable tbl = new CenterMiddleTable(1); tbl.toLeft(); int width[] = { 85 }; tbl.setWidths(width); tbl.addHeaderCellB2(ApplicationConfigurator.LanguageManager.getString("DISPOSIZIONI"), 1, false, 11); m_document.add(tbl); } { CenterMiddleTable tbl = new CenterMiddleTable(2); tbl.toLeft(); int width[] = { 5, 85 }; java.util.Collection col = home1.getConstatazioniSop(lCOD_SOP); java.util.Iterator it = col.iterator(); tbl.setWidths(width); Alphabet c = new Alphabet(); String REV2 = c.getNextElement("1"); while (it.hasNext()) { jbConstatazione obj = (jbConstatazione) it.next(); // Numerazione alfabetica Cell cell = new Cell(new Phrase(Formatter.format(REV2), REPORT_SETTINGS.ftText9B)); cell.setVerticalAlignment(Element.ALIGN_TOP); tbl.addCell(cell); // Disposizione generata tbl.addCell(Formatter.format(obj.sDIS_GEN), defaultFontSize); REV2 = c.getNextElement(REV2); } m_document.add(tbl); } // FIRME // Spazio per le firme for (int i = 1; i <= 5; i++) { writeLine(); } { CenterMiddleTable tbl = new CenterMiddleTable(2); int width[] = { 50, 50 }; tbl.setWidths(width); tbl.setDefaultCellBorder(0); // Firme del personale dell'azienda Cell cell = new Cell( new Phrase(ApplicationConfigurator.CUSTOMER_NAME.toUpperCase(), REPORT_SETTINGS.ftText9)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); tbl.addCell(cell); // Firme del personale delle imprese Cell cell2 = new Cell( new Phrase(ApplicationConfigurator.LanguageManager.getString("Impresa").toUpperCase(), REPORT_SETTINGS.ftText9)); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); tbl.addCell(cell2); m_document.add(tbl); } // FOTO { Collection<jbMedia> listaFoto = home1.getMediaSOP(lCOD_SOP); if (listaFoto != null && listaFoto.size() > 0) { // STAMPA L'INDICE DELLE FOTO. boolean firstFoto = true; int fotoIndex = 0; for (jbMedia foto : listaFoto) { try { // Verifica che l'immagine sia in un formato supportato. Image.getInstance(foto.mediaData); fotoIndex++; if (firstFoto) { writePage(); writeTitle(ApplicationConfigurator.LanguageManager.getString("Indice.foto.allegate")); firstFoto = false; } writeLine(); // Stampo il progessivo della foto, nel formato "Foto n". writeText2Bold(ApplicationConfigurator.LanguageManager.getString("Foto") + " " + fotoIndex); // Stampo il "nome" o se questo assente, "il nome file". writeText2(StringManager.isNotEmpty(foto.sNOM_MED) ? Formatter.format(foto.sNOM_MED) : Formatter.format(foto.sFile)); // Stampo, se presente, la "descrizione". writeText2(StringManager.isNotEmpty(foto.sDES_MED) ? Formatter.format(foto.sDES_MED) : ""); } catch (Exception ex) { // Eccezione silenziosa. // Gestisce il caso in cui l'allegato non sia un immagine } } // STAMPA LE FOTO. firstFoto = true; fotoIndex = 0; byte SPACE_FOR_TITLE = 20; byte SPACE_FOR_BOTTOM_MARGIN = 20; boolean strictImageSequence = m_writer.isStrictImageSequence(); m_writer.setStrictImageSequence(true); for (jbMedia foto : listaFoto) { Element image = prepareImage(m_document, foto.mediaData); if (image != null) { fotoIndex++; if (firstFoto) { writePage(); firstFoto = false; } if (m_document.getPageSize().getHeight() - m_document.topMargin() + 20 < getAvailablePageSpace(m_document, m_writer)) { writeLine(); } if (getAvailablePageSpace(m_document, m_writer) - (SPACE_FOR_TITLE + SPACE_FOR_BOTTOM_MARGIN) < ((Image) image).getScaledHeight()) { writePage(); } // Stampo il progessivo della foto, nel formato "Foto n". writeText2(ApplicationConfigurator.LanguageManager.getString("Foto") + " " + fotoIndex); // Stampo l'immagine. m_document.add(image); } } m_writer.setStrictImageSequence(strictImageSequence); } } // DOCUMENTI ALLEGATI Collection<DocumentiAssociati_Sopralluogo_View> listadocumenti = home1 .getDocumentiCantiereSOP_STAMPA(lCOD_SOP); if (listadocumenti != null && listadocumenti.size() > 0) { // STAMPA L'INDICE DEI DOCUMENTI ALLEGATI // i documenti allegati sono quei documenti la cui tipologia risulta avere attivo //il flag di stampa in sopralluogo. boolean firstdocument = true; int documentIndex = 0; for (DocumentiAssociati_Sopralluogo_View documento : listadocumenti) { try { // Verifica che l'immagine sia in un formato supportato. documentIndex++; if (firstdocument) { writePage(); writeTitle(ApplicationConfigurator.LanguageManager.getString("Indice.documenti.allegati")); firstdocument = false; } writeLine(); // Stampo il "titolo" del documento. writeText3Bold(documentIndex + ")" + (StringManager.isNotEmpty(documento.TIT_DOC) ? Formatter.format(documento.TIT_DOC) : Formatter.format(documento.NOM_TPL_DOC))); // Stampo, se presente, la "descrizione". if (!(documento.DES).equals("")) { writeLine(); } writeText3_3(StringManager.isNotEmpty(documento.DES) ? Formatter.format(documento.DES) : ""); IAnagrDocumentoHome doc_home = (IAnagrDocumentoHome) PseudoContext.lookup("AnagrDocumentoBean"); AnagDocumentoFileInfo fileInfo = null; AnagDocumentoFileInfo fileInfoLink = null; fileInfo = doc_home.getFileInfoU("", documento.lCOD_DOC); fileInfoLink = doc_home.getFileInfoULink("", documento.lCOD_DOC); // se esiste stampo il file allegato if (fileInfo != null) { writeLine(); writeText3_3(Formatter.format(" " + "File Allegato: " + fileInfo.strName)); } else { writeLine(); writeText3_3(Formatter.format(" " + "File Allegato: ")); } // se esiste stampo il file link allegato if (fileInfoLink != null) { writeText3_3(Formatter.format(" " + "File Link Allegato: " + fileInfoLink.strName)); } else { writeText3_3(Formatter.format(" " + "File Link Allegato: ")); } writeLine(); } catch (Exception ex) { // Eccezione silenziosa. // Gestisce il caso in cui l'allegato non sia un immagine } } writePage(); // Stampa documenti allegati boolean endWithNewPage = false; endWithNewPage = StampaDocumenti(home1, bean.getCOD_SOP(), m_document, m_writer); } closeDocument(); }
From source file:s2s.report.Report.java
License:GNU General Public License
public Element prepareImage(Document doc, byte[] fileContent, boolean marginConsider, float distanceFromBottomMargin) { try {//from w ww. j a v a 2 s .c o m Image img = Image.getInstance(fileContent); // Detemino le dimensioni della pagina, margini esclusi. float pageWidth = doc.getPageSize().getWidth() - (marginConsider ? doc.leftMargin() + doc.topMargin() : 0); float pageHeight = doc.getPageSize().getHeight() - (marginConsider ? doc.topMargin() + doc.bottomMargin() : 0) - (distanceFromBottomMargin > 0 ? distanceFromBottomMargin : 0); // Se l'immagine pi larga e/o pi alta della pagina, // esclusi i margini... if (img.getWidth() > pageWidth || img.getHeight() > pageHeight) { // Determino le percentuali di riduzione di entrambi le grandezze // dell'immagine (larghezza ed altezza). float reducePrecentWidth = (img.getWidth() - pageWidth) > 0 ? (pageWidth * 100) / img.getWidth() : 100; float reducePrecentHeight = (img.getHeight() - pageHeight) > 0 ? (pageHeight * 100) / img.getHeight() : 100; // Determino la percentuale di riduzione float ReducePrecent = reducePrecentWidth; ReducePrecent = reducePrecentHeight < ReducePrecent ? reducePrecentHeight : ReducePrecent; img.scalePercent(ReducePrecent); } return img; } catch (Exception ex) { // Eccezione silenziosa. // Gestisce il caso in cui l'allegato non sia un immagine ex.printStackTrace(); return null; } }
From source file:s2s.report.Report.java
License:GNU General Public License
public void AddScaledImage(float percentScale) throws Exception { if (ApplicationConfigurator.VIEW_REPORT_IMAGE == true) { //carica immagine logo writeTitle("\n"); Image png = loadImage("LOGO"); png.scalePercent(percentScale); png.setAlignment(Image.MIDDLE); m_document.add(png);/*from www. j a v a 2s .co m*/ writeTitle("\n"); } }
From source file:test.itext.html.AimsPdf.java
License:Open Source License
public static void addTitle(Document doc, String text) throws IOException, BadElementException, DocumentException { float[] widths = { 62f, 164f, 62f }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100);// www. j a v a2 s .c o m table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setSpacingAfter(10); Image image = Image.getInstance("app_title.gif"); image.scalePercent(70); PdfPCell cell = new PdfPCell(image); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); Paragraph title = new Paragraph(text, FontFactory.getFont("arial", 12, Font.BOLD)); cell = new PdfPCell(title); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); image = Image.getInstance("title_shot.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); doc.add(table); table = new PdfPTable(1); table.setWidthPercentage(100); cell = new PdfPCell(); cell.setBackgroundColor(Color.BLACK); cell.setFixedHeight(1); table.addCell(cell); doc.add(table); }
From source file:test.itext.html.AimsPdf.java
License:Open Source License
public static void addScreenShorts(Document doc, String text) throws BadElementException, IOException, DocumentException { Paragraph heading = new Paragraph("Screenshots", FontFactory.getFont("arial", 10, Font.UNDERLINE | Font.BOLDITALIC)); heading.setSpacingAfter(12f);//from w ww . j a v a 2s . c om doc.add(heading); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(80); table.setHorizontalAlignment(Element.ALIGN_CENTER); Image image = Image.getInstance("screen_shoot1.gif"); image.scalePercent(70); PdfPCell cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); image = Image.getInstance("screen_shoot2.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); image = Image.getInstance("screen_shoot3.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); image = Image.getInstance("screen_shoot4.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); image = Image.getInstance("screen_shoot5.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); image = Image.getInstance("screen_shoot6.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); // doc.add(new Paragraph("\n")); doc.add(table); }
From source file:tk.diginspect.main.SoOFSignatories.java
private void Checked(PdfPTable table, int align, int checkmark) { try {//from ww w .ja va 2s .c o m ByteArrayOutputStream streamChecked = new ByteArrayOutputStream(); Bitmap Checked = BitmapFactory.decodeResource(getBaseContext().getResources(), checkmark); Checked.compress(Bitmap.CompressFormat.JPEG, 100, streamChecked); Image ImgChecked = null; ImgChecked = Image.getInstance(streamChecked.toByteArray()); ImgChecked.scalePercent(25f); PdfPCell cell = new PdfPCell(ImgChecked, false); cell.setHorizontalAlignment(align); cell.setPadding(5); cell.setBorder(0); table.addCell(cell); } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:tk.diginspect.main.SoOFSignatories.java
private void sig(PdfPTable table, String image) { try {/*from www.j a va 2 s.c o m*/ FileInputStream fis = openFileInput(image); ByteArrayOutputStream stream = new ByteArrayOutputStream(); Bitmap bitmap = BitmapFactory.decodeStream(fis); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); Image Img = null; Img = Image.getInstance(stream.toByteArray()); Img.scalePercent(10f); PdfPCell cell = new PdfPCell(Img, false); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthBottom(0); table.addCell(cell); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:tk.diginspect.main.SoOFSignatories.java
private void FDALetterhead() { try {/*w ww .j ava 2 s . c o m*/ ByteArrayOutputStream stream = new ByteArrayOutputStream(); Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.fda_letterhead); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); Image Img = Image.getInstance(stream.toByteArray()); Img.setAlignment(Image.MIDDLE); Img.scalePercent(40f); doc.add(Img); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }