List of usage examples for com.lowagie.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.lowagie.text Element ALIGN_LEFT.
Click Source Link
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.FastPdfMapper.java
License:Open Source License
private StylableTable createPDFTable(CTTbl table, float[] colWidths, IITextContainer pdfParentContainer) throws DocumentException { // 2) Compute tableWith TableWidth tableWidth = stylesDocument.getTableWidth(table); StylableTable pdfPTable = pdfDocument.createTable(pdfParentContainer, colWidths.length); pdfPTable.setTotalWidth(colWidths);// ww w. ja va2 s . com if (tableWidth != null && tableWidth.width > 0) { if (tableWidth.percentUnit) { pdfPTable.setWidthPercentage(tableWidth.width); } else { pdfPTable.setTotalWidth(tableWidth.width); } } pdfPTable.setLockedWidth(true); // Table alignment ParagraphAlignment alignment = stylesDocument.getTableAlignment(table); if (alignment != null) { switch (alignment) { case LEFT: pdfPTable.setHorizontalAlignment(Element.ALIGN_LEFT); break; case RIGHT: pdfPTable.setHorizontalAlignment(Element.ALIGN_RIGHT); break; case CENTER: pdfPTable.setHorizontalAlignment(Element.ALIGN_CENTER); break; case BOTH: pdfPTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); break; default: break; } } // Table indentation Float indentation = stylesDocument.getTableIndentation(table); if (indentation != null) { pdfPTable.setPaddingLeft(indentation); } return pdfPTable; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java
License:Open Source License
@Override protected IITextContainer startVisitParagraph(XWPFParagraph docxParagraph, ListItemContext itemContext, IITextContainer pdfParentContainer) throws Exception { this.currentRunX = null; // create PDF paragraph StylableParagraph pdfParagraph = pdfDocument.createParagraph(pdfParentContainer); // indentation left Float indentationLeft = stylesDocument.getIndentationLeft(docxParagraph); if (indentationLeft != null) { pdfParagraph.setIndentationLeft(indentationLeft); }/* w w w. j a va 2 s . com*/ // indentation right Float indentationRight = stylesDocument.getIndentationRight(docxParagraph); if (indentationRight != null) { pdfParagraph.setIndentationRight(indentationRight); } // indentation first line Float indentationFirstLine = stylesDocument.getIndentationFirstLine(docxParagraph); if (indentationFirstLine != null) { pdfParagraph.setFirstLineIndent(indentationFirstLine); } // indentation hanging (remove first line) Float indentationHanging = stylesDocument.getIndentationHanging(docxParagraph); if (indentationHanging != null) { pdfParagraph.setFirstLineIndent(-indentationHanging); } // // spacing before Float spacingBefore = stylesDocument.getSpacingBefore(docxParagraph); if (spacingBefore != null) { pdfParagraph.setSpacingBefore(spacingBefore); } // spacing after Float spacingAfter = stylesDocument.getSpacingAfter(docxParagraph); if (spacingAfter != null) { pdfParagraph.setSpacingAfter(spacingAfter); } ParagraphLineSpacing lineSpacing = stylesDocument.getParagraphSpacing(docxParagraph); if (lineSpacing != null) { if (lineSpacing.getLeading() != null && lineSpacing.getMultipleLeading() != null) { pdfParagraph.setLeading(lineSpacing.getLeading(), lineSpacing.getMultipleLeading()); } else { if (lineSpacing.getLeading() != null) { pdfParagraph.setLeading(lineSpacing.getLeading()); } if (lineSpacing.getMultipleLeading() != null) { pdfParagraph.setMultipliedLeading(lineSpacing.getMultipleLeading()); } } } // text-align ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(docxParagraph); if (alignment != null) { switch (alignment) { case LEFT: pdfParagraph.setAlignment(Element.ALIGN_LEFT); break; case RIGHT: pdfParagraph.setAlignment(Element.ALIGN_RIGHT); break; case CENTER: pdfParagraph.setAlignment(Element.ALIGN_CENTER); break; case BOTH: pdfParagraph.setAlignment(Element.ALIGN_JUSTIFIED); break; default: break; } } // background-color Color backgroundColor = stylesDocument.getBackgroundColor(docxParagraph); if (backgroundColor != null) { pdfParagraph.setBackgroundColor(Converter.toAwtColor(backgroundColor)); } // border CTBorder borderTop = stylesDocument.getBorderTop(docxParagraph); pdfParagraph.setBorder(borderTop, Rectangle.TOP); CTBorder borderBottom = stylesDocument.getBorderBottom(docxParagraph); pdfParagraph.setBorder(borderBottom, Rectangle.BOTTOM); CTBorder borderLeft = stylesDocument.getBorderLeft(docxParagraph); pdfParagraph.setBorder(borderLeft, Rectangle.LEFT); CTBorder borderRight = stylesDocument.getBorderRight(docxParagraph); pdfParagraph.setBorder(borderRight, Rectangle.RIGHT); if (itemContext != null) { CTLvl lvl = itemContext.getLvl(); CTPPr lvlPPr = lvl.getPPr(); if (lvlPPr != null) { if (ParagraphIndentationLeftValueProvider.INSTANCE .getValue(docxParagraph.getCTP().getPPr()) == null) { // search the indentation from the level properties only if // paragraph has not override it // see // https://code.google.com/p/xdocreport/issues/detail?id=239 Float indLeft = ParagraphIndentationLeftValueProvider.INSTANCE.getValue(lvlPPr); if (indLeft != null) { pdfParagraph.setIndentationLeft(indLeft); } } if (ParagraphIndentationHangingValueProvider.INSTANCE .getValue(docxParagraph.getCTP().getPPr()) == null) { // search the hanging from the level properties only if // paragraph has not override it // see // https://code.google.com/p/xdocreport/issues/detail?id=239 Float hanging = stylesDocument.getIndentationHanging(lvlPPr); if (hanging != null) { pdfParagraph.setFirstLineIndent(-hanging); } } } CTRPr lvlRPr = lvl.getRPr(); if (lvlRPr != null) { // Font family String listItemFontFamily = stylesDocument.getFontFamilyAscii(lvlRPr); // Get font size Float listItemFontSize = stylesDocument.getFontSize(lvlRPr); // Get font style int listItemFontStyle = Font.NORMAL; Boolean bold = stylesDocument.getFontStyleBold(lvlRPr); if (bold != null && bold) { listItemFontStyle |= Font.BOLD; } Boolean italic = stylesDocument.getFontStyleItalic(lvlRPr); if (italic != null && italic) { listItemFontStyle |= Font.ITALIC; } Boolean strike = stylesDocument.getFontStyleStrike(lvlRPr); if (strike != null && strike) { listItemFontStyle |= Font.STRIKETHRU; } // Font color Color listItemFontColor = stylesDocument.getFontColor(lvlRPr); pdfParagraph.setListItemFontFamily(listItemFontFamily); pdfParagraph.setListItemFontSize(listItemFontSize); pdfParagraph.setListItemFontStyle(listItemFontStyle); pdfParagraph.setListItemFontColor(Converter.toAwtColor(listItemFontColor)); } pdfParagraph.setListItemText(itemContext.getText()); } return pdfParagraph; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java
License:Open Source License
private StylableTable createPDFTable(XWPFTable table, float[] colWidths, IITextContainer pdfParentContainer) throws DocumentException { // 2) Compute tableWith TableWidth tableWidth = stylesDocument.getTableWidth(table); StylableTable pdfPTable = pdfDocument.createTable(pdfParentContainer, colWidths.length); pdfPTable.setTotalWidth(colWidths);// ww w .j a v a2s . c om if (tableWidth != null && tableWidth.width > 0) { if (tableWidth.percentUnit) { pdfPTable.setWidthPercentage(tableWidth.width); } else { pdfPTable.setTotalWidth(tableWidth.width); } } pdfPTable.setLockedWidth(true); // Table alignment ParagraphAlignment alignment = stylesDocument.getTableAlignment(table); if (alignment != null) { switch (alignment) { case LEFT: pdfPTable.setHorizontalAlignment(Element.ALIGN_LEFT); break; case RIGHT: pdfPTable.setHorizontalAlignment(Element.ALIGN_RIGHT); break; case CENTER: pdfPTable.setHorizontalAlignment(Element.ALIGN_CENTER); break; case BOTH: pdfPTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); break; default: break; } } // Table indentation Float indentation = stylesDocument.getTableIndentation(table); if (indentation != null) { pdfPTable.setPaddingLeft(indentation); } return pdfPTable; }
From source file:fr.opensagres.xdocreport.itext.extension.ExtendedPdfPTable.java
License:Open Source License
public ExtendedPdfPTable(int numColumns) { super(numColumns); super.setSpacingBefore(0f); this.empty = true; super.setLockedWidth(true); super.setHorizontalAlignment(Element.ALIGN_LEFT); }
From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.utils.PDFUtils.java
License:Open Source License
/** * method to builder PDF with directory entry * @param document document pdf// w w w. j ava 2s.c o m * @param plugin plugin * @param nIdRecord id record * @param listEntry list of entry * @param listIdEntryConfig list of config id entry * @param locale the locale * @param bExtractNotFilledField if true, extract empty fields, false */ private static void builderPDFWithEntry(Document document, Plugin plugin, int nIdRecord, List<IEntry> listEntry, List<Integer> listIdEntryConfig, Locale locale, Boolean bExtractNotFilledField) { Map<String, List<RecordField>> mapIdEntryListRecordField = DirectoryUtils .getMapIdEntryListRecordField(listEntry, nIdRecord, plugin); for (IEntry entry : listEntry) { if (entry.getEntryType().getGroup() && (listIdEntryConfig.isEmpty() || listIdEntryConfig.contains(Integer.valueOf(entry.getIdEntry())))) { Font fontEntryTitleGroup = new Font( DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)), DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_ENTRY_GROUP)), DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_ENTRY_GROUP))); Paragraph paragraphTitleGroup = new Paragraph(new Phrase(entry.getTitle(), fontEntryTitleGroup)); paragraphTitleGroup.setAlignment(Element.ALIGN_LEFT); paragraphTitleGroup.setIndentationLeft(DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_MARGIN_LEFT_ENTRY_GROUP))); paragraphTitleGroup.setSpacingBefore(DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_SPACING_BEFORE_ENTRY_GROUP))); paragraphTitleGroup.setSpacingAfter(DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_SPACING_AFTER_ENTRY_GROUP))); try { document.add(paragraphTitleGroup); } catch (DocumentException e) { AppLogService.error(e); } if (entry.getChildren() != null) { for (IEntry child : entry.getChildren()) { if (listIdEntryConfig.isEmpty() || listIdEntryConfig.contains(Integer.valueOf(child.getIdEntry()))) { try { builFieldsInPDF(mapIdEntryListRecordField.get(Integer.toString(child.getIdEntry())), document, child, locale, bExtractNotFilledField); } catch (DocumentException e) { AppLogService.error(e); } } } } } else { if (listIdEntryConfig.isEmpty() || listIdEntryConfig.contains(Integer.valueOf(entry.getIdEntry()))) { try { builFieldsInPDF(mapIdEntryListRecordField.get(Integer.toString(entry.getIdEntry())), document, entry, locale, bExtractNotFilledField); } catch (DocumentException e) { AppLogService.error(e); } } } } }
From source file:fr.univlorraine.mondossierweb.controllers.InscriptionController.java
License:Apache License
/** * // w w w .ja va 2s. c om * @param document pdf */ public void creerPdfCertificatScolarite(final Document document, Etudiant etudiant, Inscription inscription) { //configuration des fonts Font normal = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL); Font normalBig = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); Font header = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD); //date Date d = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); String date = dateFormat.format(d); document.open(); try { Signataire signataire = multipleApogeeService .getSignataire(configController.getCertScolCodeSignataire()); // Ajout Bordeaux1 if (configController.isCertScolUtiliseLogo()) { //ajout image test if (configController.getLogoUniversitePdf() != null && !configController.getLogoUniversitePdf().equals("")) { Image imageLogo = Image.getInstance(configController.getLogoUniversitePdf()); float scaleRatio = 40 / imageLogo.getHeight(); float newWidth = scaleRatio * imageLogo.getWidth(); imageLogo.scaleAbsolute(newWidth, 40); imageLogo.setAbsolutePosition(100, 750); document.add(imageLogo); } else if (configController.getCertScolHeaderUniv() != null && !configController.getCertScolHeaderUniv().equals("")) { Image imageHeader = Image.getInstance(configController.getCertScolHeaderUniv()); float scaleHeader = 600 / imageHeader.getWidth(); float newHeigthHeader = scaleHeader * imageHeader.getHeight(); imageHeader.scaleAbsolute(600, newHeigthHeader); imageHeader.setAbsolutePosition(0, 765); document.add(imageHeader); } if (configController.getCertScolFooter() != null && !configController.getCertScolFooter().equals("")) { Image imageFooter = Image.getInstance(configController.getCertScolFooter()); float scaleFooter = 600 / imageFooter.getWidth(); float newHeigthFooter = scaleFooter * imageFooter.getHeight(); imageFooter.scaleAbsolute(600, newHeigthFooter); imageFooter.setAbsolutePosition(0, 0); document.add(imageFooter); } } Paragraph pTitre = new Paragraph("\n\n" + applicationContext .getMessage("pdf.certificat.title", null, Locale.getDefault()).toUpperCase(), header); pTitre.setAlignment(Element.ALIGN_CENTER); document.add(pTitre); Paragraph pCertifie = new Paragraph("\n\n\n\n" + signataire.getQua_sig() + " " + applicationContext.getMessage("pdf.certificat.certifie", null, Locale.getDefault()) + "\n\n", normal); pCertifie.setAlignment(Element.ALIGN_LEFT); document.add(pCertifie); if (etudiant.getNom() != null) { String civ = multipleApogeeService.getCodCivFromCodInd(etudiant.getCod_ind()); String civCertif = ""; if (civ != null) { if (civ.equals("1")) { civCertif = applicationContext.getMessage("pdf.certificat.civ1", null, Locale.getDefault()); } else if (civ.equals("2")) { civCertif = applicationContext.getMessage("pdf.certificat.civ2", null, Locale.getDefault()); } } Paragraph pNom = new Paragraph(civCertif + " " + etudiant.getNom(), normalBig); pNom.setIndentationLeft(15); document.add(pNom); } if (etudiant.getCod_nne() != null) { Paragraph pNNE = new Paragraph( "\n" + applicationContext.getMessage("pdf.certificat.id", null, Locale.getDefault()) + " : " + etudiant.getCod_nne().toLowerCase(), normal); pNNE.setAlignment(Element.ALIGN_LEFT); document.add(pNNE); } if (etudiant.getCod_etu() != null) { Paragraph p01 = new Paragraph( applicationContext.getMessage("pdf.certificat.numetudiant", null, Locale.getDefault()) + " : " + etudiant.getCod_etu(), normal); p01.setAlignment(Element.ALIGN_LEFT); document.add(p01); } if (etudiant.getDatenaissance() != null) { Paragraph pDateNaissance = new Paragraph( applicationContext.getMessage("pdf.certificat.naissance1", null, Locale.getDefault()) + " " + etudiant.getDatenaissance(), normal); pDateNaissance.setAlignment(Element.ALIGN_LEFT); document.add(pDateNaissance); } if ((etudiant.getLieunaissance() != null) && (etudiant.getDepartementnaissance() != null)) { Paragraph pLieuNaissance = new Paragraph( applicationContext.getMessage("pdf.certificat.naissance2", null, Locale.getDefault()) + " " + etudiant.getLieunaissance() + " (" + etudiant.getDepartementnaissance() + ")", normal); pLieuNaissance.setAlignment(Element.ALIGN_LEFT); document.add(pLieuNaissance); } String anneeEnCours = etudiantController.getAnneeUnivEnCoursToDisplay(MainUI.getCurrent()); String inscritCertif = ""; if (inscription.getCod_anu().equals(anneeEnCours)) { inscritCertif = applicationContext.getMessage("pdf.certificat.inscrit", null, Locale.getDefault()); } else { inscritCertif = applicationContext.getMessage("pdf.certificat.ete.inscrit", null, Locale.getDefault()); } Paragraph pEstInscrit = new Paragraph("\n" + inscritCertif + " " + inscription.getCod_anu() + "\n ", normal); pEstInscrit.setAlignment(Element.ALIGN_LEFT); document.add(pEstInscrit); float[] widths = { 1.5f, 7.5f }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100f); table.addCell(makeCell(applicationContext.getMessage("pdf.diplome", null, Locale.getDefault()) + " :", normal)); table.addCell(makeCell(inscription.getLib_dip(), normal)); table.addCell( makeCell(applicationContext.getMessage("pdf.year", null, Locale.getDefault()) + " :", normal)); table.addCell(makeCell(inscription.getLib_etp(), normal)); table.addCell(makeCell( applicationContext.getMessage("pdf.composante", null, Locale.getDefault()) + " :", normal)); table.addCell(makeCell(inscription.getLib_comp(), normal)); document.add(table); document.add(new Paragraph(" ")); float[] widthsSignataire = { 2f, 1.3f }; PdfPTable tableSignataire = new PdfPTable(widthsSignataire); tableSignataire.setWidthPercentage(100f); tableSignataire.addCell(makeCellSignataire("", normal)); tableSignataire .addCell(makeCellSignataire( applicationContext.getMessage("pdf.certificat.fait1", null, Locale.getDefault()) + " " + configController.getCertScolLieuEdition() + applicationContext.getMessage( "pdf.certificat.fait2", null, Locale.getDefault()) + " " + date, normal)); tableSignataire.addCell(makeCellSignataire("", normal)); tableSignataire.addCell(makeCellSignataire(signataire.getNom_sig(), normal)); //ajout signature if (signataire.getImg_sig_std() != null && signataire.getImg_sig_std().length > 0) { //MODIF 09/10/2012 tableSignataire.addCell(makeCellSignataire("", normal)); LOG.debug(signataire.getImg_sig_std().toString()); Image imageSignature = Image.getInstance(signataire.getImg_sig_std()); float scaleRatio = 100 / imageSignature.getHeight(); float newWidth = scaleRatio * imageSignature.getWidth(); imageSignature.scaleAbsolute(newWidth, 100); imageSignature.setAbsolutePosition(350, 225); document.add(imageSignature); } document.add(tableSignataire); // Ajout tampon if (configController.getCertScolTampon() != null && !configController.getCertScolTampon().equals("")) { Image imageTampon = Image.getInstance(configController.getCertScolTampon()); float scaleTampon = 100 / imageTampon.getWidth(); float newHeigthTampon = scaleTampon * imageTampon.getHeight(); imageTampon.scaleAbsolute(100, newHeigthTampon); imageTampon.setAbsolutePosition(415, 215); document.add(imageTampon); } } catch (BadElementException e) { LOG.error("Erreur la gnration du certificat : BadElementException ", e); } catch (MalformedURLException e) { LOG.error("Erreur la gnration du certificat : MalformedURLException ", e); } catch (IOException e) { LOG.error("Erreur la gnration du certificat : IOException ", e); } catch (DocumentException e) { LOG.error("Erreur la gnration du certificat : DocumentException ", e); } // step 6: fermeture du document. document.close(); }
From source file:geoportal.presentacion.beans.ReportesControlador.java
public void imprimirReporte() { //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL); try {/*from w w w . ja va 2s.c o m*/ //Generamos el archivo PDF String directorioArchivos; ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); directorioArchivos = ctx.getRealPath("/") + "reportes"; String name = directorioArchivos + "/document-reporte.pdf"; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(name)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(name)); //PdfWriter writer = PdfWriter.getInstance(document, //new FileOutputStream("C:")); Paragraph paragraph = new Paragraph(); Paragraph paragraph1 = new Paragraph(); Paragraph paragraph2 = new Paragraph(); //PdfPTable table = new PdfPTable(4); PdfPTable table1 = new PdfPTable(1); PdfPTable table2 = new PdfPTable(4); PdfPTable table3 = new PdfPTable(4); PdfPTable table5 = new PdfPTable(1); paragraph.add("\n\n\n\n\n\n\n"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph1.add("\n"); paragraph1.setAlignment(Paragraph.ALIGN_CENTER); paragraph2.add("Total Denuncias:" + totalDenuncias); paragraph2.setAlignment(Paragraph.ALIGN_LEFT); // Obtenemos una instancia de nuestro manejador de eventos MembreteHeaderiText header = new MembreteHeaderiText(); //Asignamos el manejador de eventos al escritor. writer.setPageEvent(header); document.open(); // Chunk titulo = new Chunk(CHUNK, FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK)); // // titulo = new Chunk(IMAGE, FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK)); // document.add(titulo); // Image foto = Image.getInstance(resources / ferrari.jpg?); //foto.scaleToFit(100, 100); foto.setAlignment(Chunk.ALIGN_MIDDLE); //primera linea PdfPCell cell5 = new PdfPCell(new Paragraph("VIOLENCIA INTRAFAMILIAR ")); //segunda linea PdfPCell cell12 = new PdfPCell(new Paragraph("AO")); PdfPCell cell6 = new PdfPCell(new Paragraph("2010")); PdfPCell cell7 = new PdfPCell(new Paragraph("2011")); PdfPCell cell8 = new PdfPCell(new Paragraph("2012")); //tercera fila PdfPCell cell13 = new PdfPCell(new Paragraph("# DENUNCIAS")); PdfPCell cell9 = new PdfPCell(new Paragraph("" + lstVif2010.size())); PdfPCell cell10 = new PdfPCell(new Paragraph("" + lstVif2011.size())); PdfPCell cell11 = new PdfPCell(new Paragraph("" + lstVif_2012.size())); PdfPCell cell15 = new PdfPCell(new Paragraph("TOTAL DENUNCIAS:" + totalDenuncias)); cell5.setHorizontalAlignment(Element.ALIGN_CENTER); cell6.setHorizontalAlignment(Element.ALIGN_CENTER); cell7.setHorizontalAlignment(Element.ALIGN_CENTER); cell8.setHorizontalAlignment(Element.ALIGN_CENTER); cell9.setHorizontalAlignment(Element.ALIGN_CENTER); cell10.setHorizontalAlignment(Element.ALIGN_CENTER); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); cell12.setHorizontalAlignment(Element.ALIGN_CENTER); cell13.setHorizontalAlignment(Element.ALIGN_CENTER); cell15.setHorizontalAlignment(Element.ALIGN_LEFT); cell12.setBackgroundColor(Color.cyan); cell13.setBackgroundColor(Color.cyan); cell5.setBorder(Rectangle.NO_BORDER); cell15.setBorder(Rectangle.NO_BORDER); table1.addCell(cell5); //aadir segunda fila table2.addCell(cell12); table2.addCell(cell6); table2.addCell(cell7); table2.addCell(cell8); //aadir tercera fila table3.addCell(cell13); table3.addCell(cell9); table3.addCell(cell10); table3.addCell(cell11); //aadir cuarta fila table5.addCell(cell15); document.add(paragraph); document.add(table1); document.add(paragraph1); document.add(table2); document.add(table3); document.add(table5); //document.add(paragraph2); //document.add(table); //document.setFooter(event); document.close(); //---------------------------- //Abrimos el archivo PDF FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "inline=filename=" + name); try { response.getOutputStream().write(Util.getBytesFromFile(new File(name))); response.getOutputStream().flush(); response.getOutputStream().close(); context.responseComplete(); } catch (IOException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:gov.anl.aps.cdb.portal.plugins.support.icmsLink.IcmsWatermarkUtility.java
License:Open Source License
/** * Adds a stamp of some metadata to ICMS documents. * * Function Credit: Thomas Fors/*from w w w.j av a 2 s . co m*/ * * @return byte array ologgerf the stamped PDF file * @throws DocumentException - Error loading pdfstamper or creating font * @throws IOException - Error performing IO operation * @throws Base64DecodingException - Error converting downloadContent string to byte[] */ private byte[] addWatermarkToPDFFile() throws Base64DecodingException, DocumentException, IOException { byte[] pdfBytes = Base64.decode(downloadContentBase64Encoded); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yy hh:mm:ss a"); LocalDateTime now = LocalDateTime.now(); String downloadTime = dtf.format(now); UserInfo user = (UserInfo) SessionUtility.getUser(); String username = null; if (user != null) { username = user.getUsername(); } else { username = "unknown user"; } String bottomMessage = "Downloaded via APS CDB by: " + username + " at " + downloadTime; controlledRev = updateOptionalValue(controlledRev); dnsCollectionId = updateOptionalValue(dnsCollectionId); dnsDocNumber = updateOptionalValue(dnsDocNumber); String watermarkContents = "Content ID: " + docName; watermarkContents += " Rev: " + controlledRev; watermarkContents += " Released: " + date; watermarkContents += " DNS Collection ID: " + dnsCollectionId; watermarkContents += " DNS Document ID: " + dnsDocNumber; PdfReader pdfReader = new PdfReader(pdfBytes); int n = pdfReader.getNumberOfPages(); ByteArrayOutputStream out = new ByteArrayOutputStream(); PdfStamper stamp = new PdfStamper(pdfReader, out); PdfContentByte over; BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); for (int i = 0; i < n; i++) { over = stamp.getOverContent(i + 1); over.beginText(); over.setTextMatrix(30, 30); over.setFontAndSize(bf, 10); over.setColorFill(new Color(0x80, 0x80, 0x80)); over.showTextAligned(Element.ALIGN_LEFT, watermarkContents, 25, 25, 90); over.showTextAligned(Element.ALIGN_LEFT, bottomMessage, 50, 10, 0); if (status.equals(ICMS_UNDER_REV_STATUS)) { over.setColorFill(new Color(0xFF, 0x00, 0x00)); } //over.showTextAligned(Element.ALIGN_LEFT, status, 25, 25 + bf.getWidthPoint(watermarkContents + " - ", 10), 90); over.endText(); } stamp.close(); return out.toByteArray(); }
From source file:gov.utah.health.uper.reports.Registration.java
private void buildPatient(Document document, PatientBean pt) throws DocumentException { Paragraph preface = new Paragraph(PATIENT, normalFontBold); preface.setAlignment(Element.ALIGN_LEFT); document.add(preface);/*from w w w . j a v a 2 s .c om*/ preface = new Paragraph("Name: ", normalFontBold); preface.add(pt.getFirstName() + " " + pt.getLastName()); preface.setAlignment(Element.ALIGN_LEFT); document.add(preface); preface = new Paragraph("Date of Birth: ", normalFontBold); preface.add(pt.getDob()); preface.setAlignment(Element.ALIGN_LEFT); document.add(preface); preface = new Paragraph("Address: ", normalFontBold); preface.setAlignment(Element.ALIGN_LEFT); StringBuilder sb = new StringBuilder(pt.getAddressCurrent()); sb.append(" "); sb.append(pt.getCityCurrent()); sb.append(", "); sb.append(pt.getStateCurrent()); sb.append(" "); sb.append(pt.getZipCurrent()); preface.add(sb.toString()); document.add(preface); addSpacing(document); }
From source file:gov.utah.health.uper.reports.Registration.java
private void buildParent(Document document, PatientBean pt) throws DocumentException { Paragraph preface = new Paragraph(PARENT, normalFontBold); preface.setAlignment(Element.ALIGN_LEFT); document.add(preface);/* w w w. j a va 2 s. c om*/ preface = new Paragraph("Name: ", normalFontBold); preface.add(pt.getParentFirstName() + " " + pt.getParentLastName()); preface.setAlignment(Element.ALIGN_LEFT); document.add(preface); preface = new Paragraph("Date of Birth: ", normalFontBold); preface.add(pt.getParentDob()); preface.setAlignment(Element.ALIGN_LEFT); document.add(preface); preface = new Paragraph("Address: ", normalFontBold); StringBuilder sb = new StringBuilder(pt.getParentAddressCurrent()); sb.append(" "); sb.append(pt.getParentCityCurrent()); sb.append(", "); sb.append(pt.getParentStateCurrent()); sb.append(" "); sb.append(pt.getParentZipCurrent()); preface.add(sb.toString()); preface.setAlignment(Element.ALIGN_LEFT); document.add(preface); addSpacing(document); }