List of usage examples for com.lowagie.text Document addTitle
public boolean addTitle(String title)
From source file:org.jboss.as.quickstarts.ejbinwar.ejb.GreeterEJB.java
License:Apache License
public ByteArrayOutputStream generatePDFDocumentBytes(String selectedTariff) throws DocumentException { java.util.Set<String> users = getRestUsers(selectedTariff); Document doc = new Document(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter docWriter = null;/* w ww .ja v a 2 s. c o m*/ try { docWriter = PdfWriter.getInstance(doc, baosPDF); doc.addAuthor(this.getClass().getName()); doc.addCreationDate(); doc.addProducer(); doc.addCreator(this.getClass().getName()); doc.addTitle(selectedTariff + " clients"); doc.addKeywords("pdf, itext, Java, ecare, http"); doc.setPageSize(PageSize.LETTER); HeaderFooter footer = new HeaderFooter(new Phrase("E-Care report"), false); doc.setFooter(footer); doc.open(); doc.add(new Paragraph(selectedTariff + " clients")); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); PdfPTable table = new PdfPTable(4); // 3 columns. PdfPCell cell1 = new PdfPCell(new Paragraph("Name")); PdfPCell cell2 = new PdfPCell(new Paragraph("Surname")); PdfPCell cell3 = new PdfPCell(new Paragraph("Address")); PdfPCell cell4 = new PdfPCell(new Paragraph("Email")); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); for (Iterator<String> it = users.iterator(); it.hasNext();) { String user = it.next(); table.addCell(new PdfPCell(new Paragraph(user.split(" ")[0]))); table.addCell(new PdfPCell(new Paragraph(user.split(" ")[1]))); table.addCell(new PdfPCell(new Paragraph(user.split(" ")[2]))); table.addCell(new PdfPCell(new Paragraph(user.split(" ")[3]))); } doc.add(table); } catch (DocumentException dex) { baosPDF.reset(); throw dex; } finally { if (doc != null) { doc.close(); } if (docWriter != null) { docWriter.close(); } } if (baosPDF.size() < 1) { throw new DocumentException("document has " + baosPDF.size() + " bytes"); } return baosPDF; }
From source file:org.jbpm.designer.web.server.TransformerServlet.java
License:Apache License
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); String formattedSvgEncoded = req.getParameter("fsvg"); String uuid = Utils.getUUID(req); String profileName = Utils.getDefaultProfileName(req.getParameter("profile")); String transformto = req.getParameter("transformto"); String jpdl = req.getParameter("jpdl"); String gpd = req.getParameter("gpd"); String bpmn2in = req.getParameter("bpmn2"); String jsonin = req.getParameter("json"); String preprocessingData = req.getParameter("pp"); String respaction = req.getParameter("respaction"); String pp = req.getParameter("pp"); String processid = req.getParameter("processid"); String sourceEnc = req.getParameter("enc"); String convertServiceTasks = req.getParameter("convertservicetasks"); String htmlSourceEnc = req.getParameter("htmlenc"); String formattedSvg = (formattedSvgEncoded == null ? "" : new String(Base64.decodeBase64(formattedSvgEncoded), "UTF-8")); String htmlSource = (htmlSourceEnc == null ? "" : new String(Base64.decodeBase64(htmlSourceEnc), "UTF-8")); if (sourceEnc != null && sourceEnc.equals("true")) { bpmn2in = new String(Base64.decodeBase64(bpmn2in), "UTF-8"); }/*w w w .ja v a2 s. c o m*/ if (profile == null) { profile = _profileService.findProfile(req, profileName); } DroolsFactoryImpl.init(); BpsimFactoryImpl.init(); Repository repository = profile.getRepository(); if (transformto != null && transformto.equals(TO_PDF)) { if (respaction != null && respaction.equals(RESPACTION_SHOWURL)) { try { ByteArrayOutputStream pdfBout = new ByteArrayOutputStream(); Document pdfDoc = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(pdfDoc, pdfBout); pdfDoc.open(); pdfDoc.addCreationDate(); PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen"); float widthHint = getFloatParam(req, SVG_WIDTH_PARAM, DEFAULT_PDF_WIDTH); float heightHint = getFloatParam(req, SVG_HEIGHT_PARAM, DEFAULT_PDF_HEIGHT); String objStyle = "style=\"width:" + widthHint + "px;height:" + heightHint + "px;\""; t.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, widthHint); t.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, heightHint); ByteArrayOutputStream imageBout = new ByteArrayOutputStream(); TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg)); TranscoderOutput output = new TranscoderOutput(imageBout); t.transcode(input, output); Image processImage = Image.getInstance(imageBout.toByteArray()); scalePDFImage(pdfDoc, processImage); pdfDoc.add(processImage); pdfDoc.close(); resp.setCharacterEncoding("UTF-8"); resp.setContentType("text/plain"); resp.getWriter() .write("<object type=\"application/pdf\" " + objStyle + " data=\"data:application/pdf;base64," + Base64.encodeBase64String(pdfBout.toByteArray()) + "\"></object>"); } catch (Exception e) { resp.sendError(500, e.getMessage()); } } else { storeInRepository(uuid, formattedSvg, transformto, processid, repository); try { resp.setCharacterEncoding("UTF-8"); resp.setContentType("application/pdf"); if (processid != null) { resp.setHeader("Content-Disposition", "attachment; filename=\"" + processid + ".pdf\""); } else { resp.setHeader("Content-Disposition", "attachment; filename=\"" + uuid + ".pdf\""); } ByteArrayOutputStream bout = new ByteArrayOutputStream(); Document pdfDoc = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(pdfDoc, resp.getOutputStream()); pdfDoc.open(); pdfDoc.addCreationDate(); PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen"); TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg)); TranscoderOutput output = new TranscoderOutput(bout); t.transcode(input, output); Image processImage = Image.getInstance(bout.toByteArray()); scalePDFImage(pdfDoc, processImage); pdfDoc.add(processImage); pdfDoc.close(); } catch (Exception e) { resp.sendError(500, e.getMessage()); } } } else if (transformto != null && transformto.equals(TO_PNG)) { try { if (respaction != null && respaction.equals(RESPACTION_SHOWURL)) { ByteArrayOutputStream bout = new ByteArrayOutputStream(); PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen"); TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg)); TranscoderOutput output = new TranscoderOutput(bout); t.transcode(input, output); resp.setCharacterEncoding("UTF-8"); resp.setContentType("text/plain"); if (req.getParameter(SVG_WIDTH_PARAM) != null && req.getParameter(SVG_HEIGHT_PARAM) != null) { int widthHint = (int) getFloatParam(req, SVG_WIDTH_PARAM, DEFAULT_PDF_WIDTH); int heightHint = (int) getFloatParam(req, SVG_HEIGHT_PARAM, DEFAULT_PDF_HEIGHT); resp.getWriter() .write("<img width=\"" + widthHint + "\" height=\"" + heightHint + "\" src=\"data:image/png;base64," + Base64.encodeBase64String(bout.toByteArray()) + "\">"); } else { resp.getWriter().write("<img src=\"data:image/png;base64," + Base64.encodeBase64String(bout.toByteArray()) + "\">"); } } else { storeInRepository(uuid, formattedSvg, transformto, processid, repository); resp.setContentType("image/png"); if (processid != null) { resp.setHeader("Content-Disposition", "attachment; filename=\"" + processid + ".png\""); } else { resp.setHeader("Content-Disposition", "attachment; filename=\"" + uuid + ".png\""); } PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen"); TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg)); TranscoderOutput output = new TranscoderOutput(resp.getOutputStream()); t.transcode(input, output); } } catch (TranscoderException e) { resp.sendError(500, e.getMessage()); } } else if (transformto != null && transformto.equals(TO_SVG)) { storeInRepository(uuid, formattedSvg, transformto, processid, repository); } else if (transformto != null && transformto.equals(BPMN2_TO_JSON)) { try { if (convertServiceTasks != null && convertServiceTasks.equals("true")) { bpmn2in = bpmn2in.replaceAll("drools:taskName=\".*?\"", "drools:taskName=\"ReadOnlyService\""); bpmn2in = bpmn2in.replaceAll("tns:taskName=\".*?\"", "tns:taskName=\"ReadOnlyService\""); } Definitions def = ((JbpmProfileImpl) profile).getDefinitions(bpmn2in); def.setTargetNamespace("http://www.omg.org/bpmn20"); if (convertServiceTasks != null && convertServiceTasks.equals("true")) { // fix the data input associations for converted tasks List<RootElement> rootElements = def.getRootElements(); for (RootElement root : rootElements) { if (root instanceof Process) { updateTaskDataInputs((Process) root, def); } } } // get the xml from Definitions ResourceSet rSet = new ResourceSetImpl(); rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl()); JBPMBpmn2ResourceImpl bpmn2resource = (JBPMBpmn2ResourceImpl) rSet .createResource(URI.createURI("virtual.bpmn2")); bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8"); bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_DEFER_IDREF_RESOLUTION, true); bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_DISABLE_NOTIFY, true); bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF_RECORD); bpmn2resource.setEncoding("UTF-8"); rSet.getResources().add(bpmn2resource); bpmn2resource.getContents().add(def); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bpmn2resource.save(outputStream, new HashMap<Object, Object>()); String revisedXmlModel = outputStream.toString(); String json = profile.createUnmarshaller().parseModel(revisedXmlModel, profile, pp); resp.setCharacterEncoding("UTF-8"); resp.setContentType("application/json"); resp.getWriter().print(json); } catch (Exception e) { e.printStackTrace(); _logger.error(e.getMessage()); resp.setContentType("application/json"); resp.getWriter().print("{}"); } } else if (transformto != null && transformto.equals(JSON_TO_BPMN2)) { try { DroolsFactoryImpl.init(); BpsimFactoryImpl.init(); if (preprocessingData == null) { preprocessingData = ""; } String processXML = profile.createMarshaller().parseModel(jsonin, preprocessingData); resp.setContentType("application/xml"); resp.getWriter().print(processXML); } catch (Exception e) { e.printStackTrace(); _logger.error(e.getMessage()); resp.setContentType("application/xml"); resp.getWriter().print(""); } } else if (transformto != null && transformto.equals(HTML_TO_PDF)) { try { resp.setContentType("application/pdf"); if (processid != null) { resp.setHeader("Content-Disposition", "attachment; filename=\"" + processid + ".pdf\""); } else { resp.setHeader("Content-Disposition", "attachment; filename=\"" + uuid + ".pdf\""); } Document pdfDoc = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(pdfDoc, resp.getOutputStream()); pdfDoc.open(); pdfDoc.addCreator("jBPM Designer"); pdfDoc.addSubject("Business Process Documentation"); pdfDoc.addCreationDate(); pdfDoc.addTitle("Process Documentation"); HTMLWorker htmlWorker = new HTMLWorker(pdfDoc); htmlWorker.parse(new StringReader(htmlSource)); pdfDoc.close(); } catch (DocumentException e) { resp.sendError(500, e.getMessage()); } } }
From source file:org.jplot2d.renderer.PdfExporter.java
License:Open Source License
@Override public void render(ComponentEx comp, List<CacheableBlock> cacheBlockList) { Dimension size = getDeviceBounds(comp).getSize(); Document document = new Document(new Rectangle(size.width, size.height), 0, 0, 0, 0); PdfWriter writer;/*from w w w. java2 s . c o m*/ try { writer = PdfWriter.getInstance(document, os); } catch (DocumentException e) { /* * should not happen but if it happens it should be notified to the integration instead of leaving it * half-done and tell nothing. */ throw new RuntimeException("Error creating PDF document", e); } document.open(); if (title != null) { document.addTitle(title); } PdfContentByte cb = writer.getDirectContent(); Graphics2D g = cb.createGraphics(size.width, size.height); for (CacheableBlock cblock : cacheBlockList) { List<ComponentEx> sublist = cblock.getSubcomps(); for (ComponentEx subcomp : sublist) { subcomp.draw(g); } } g.dispose(); document.close(); }
From source file:org.jrimum.bopepo.pdf.PDFs.java
License:Apache License
/** * Junta varios arquivos pdf em um s./*from w w w. ja va2 s. c om*/ * * @param pdfFiles * Coleo de array de bytes * @param info * Usa somente as informaes * (title,subject,keywords,author,creator) * * @return Arquivo PDF em forma de byte * * @since 0.2 */ public static byte[] mergeFiles(Collection<byte[]> pdfFiles, PdfDocInfo info) { try { ByteArrayOutputStream byteOS = new ByteArrayOutputStream(); Document document = new Document(); PdfCopy copy = new PdfCopy(document, byteOS); document.open(); for (byte[] f : pdfFiles) { PdfReader reader = new PdfReader(f); for (int page = 1; page <= reader.getNumberOfPages(); page++) { copy.addPage(copy.getImportedPage(reader, page)); } reader.close(); } document.addCreationDate(); if (info != null) { document.addAuthor(info.author()); document.addCreator(info.creator()); document.addTitle(info.title()); document.addSubject(info.subject()); document.addKeywords(info.keywords()); } copy.close(); document.close(); byteOS.close(); return byteOS.toByteArray(); } catch (Exception e) { return Exceptions.throwIllegalStateException(e); } }
From source file:org.kuali.kfs.module.endow.report.util.AssetStatementReportPrint.java
License:Educational Community License
/** * Generates all reports into one PDF file * /*from ww w. j a v a2s . c o m*/ * @param reportHeaderDataHolderForEndowment * @param reportHeaderDataHolderForNonEndowed * @param endowmentAssetStatementReportDataHolders * @param nonEndowedAssetStatementReportDataHolders * @param endowmentOption * @param reportOption * @param listKemidsOnHeader * @return */ public ByteArrayOutputStream printAssetStatementReport( EndowmentReportHeaderDataHolder reportHeaderDataHolderForEndowment, EndowmentReportHeaderDataHolder reportHeaderDataHolderForNonEndowed, List<AssetStatementReportDataHolder> endowmentAssetStatementReportDataHolders, List<AssetStatementReportDataHolder> nonEndowedAssetStatementReportDataHolders, String endowmentOption, String reportOption, String listKemidsInHeader) { // prepare iText document Document document = new Document(); document.addTitle("Endowment Asset Statement"); // this output stream will be returned to the user in PDF ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); try { PdfWriter.getInstance(document, pdfStream); document.open(); // generates a PDF based on the options and data if (KFSConstants.ParameterValues.YES.equalsIgnoreCase(endowmentOption) && EndowConstants.EndowmentReport.DETAIL.equalsIgnoreCase(reportOption)) { if (endowmentAssetStatementReportDataHolders != null && endowmentAssetStatementReportDataHolders.size() > 0) { // endowment detail generateEndowmentDetailReport(endowmentAssetStatementReportDataHolders, reportHeaderDataHolderForEndowment, document, listKemidsInHeader, false); } } else if (KFSConstants.ParameterValues.YES.equalsIgnoreCase(endowmentOption) && EndowConstants.EndowmentReport.TOTAL.equalsIgnoreCase(reportOption)) { if (endowmentAssetStatementReportDataHolders != null && endowmentAssetStatementReportDataHolders.size() > 0) { // endowment total generateEndowmentTotalReport(endowmentAssetStatementReportDataHolders, reportHeaderDataHolderForEndowment, document, listKemidsInHeader, true); } } else if (KFSConstants.ParameterValues.YES.equalsIgnoreCase(endowmentOption) && EndowConstants.EndowmentReport.BOTH.equalsIgnoreCase(reportOption)) { if (endowmentAssetStatementReportDataHolders != null && endowmentAssetStatementReportDataHolders.size() > 0) { // endowment detail generateEndowmentDetailReport(endowmentAssetStatementReportDataHolders, reportHeaderDataHolderForEndowment, document, listKemidsInHeader, false); // endowment total generateEndowmentTotalReport(endowmentAssetStatementReportDataHolders, reportHeaderDataHolderForEndowment, document, listKemidsInHeader, true); } } else if (KFSConstants.ParameterValues.NO.equalsIgnoreCase(endowmentOption) && EndowConstants.EndowmentReport.DETAIL.equalsIgnoreCase(reportOption)) { if (nonEndowedAssetStatementReportDataHolders != null && nonEndowedAssetStatementReportDataHolders.size() > 0) { // non-endowed detail generateNonEndowedDetailReport(nonEndowedAssetStatementReportDataHolders, reportHeaderDataHolderForNonEndowed, document, listKemidsInHeader, false); } } else if (KFSConstants.ParameterValues.NO.equalsIgnoreCase(endowmentOption) && EndowConstants.EndowmentReport.TOTAL.equalsIgnoreCase(reportOption)) { if (nonEndowedAssetStatementReportDataHolders != null && nonEndowedAssetStatementReportDataHolders.size() > 0) { // non-endowed total generateNonEndowedTotalReport(nonEndowedAssetStatementReportDataHolders, reportHeaderDataHolderForNonEndowed, document, listKemidsInHeader, false); } } else if (KFSConstants.ParameterValues.NO.equalsIgnoreCase(endowmentOption) && EndowConstants.EndowmentReport.BOTH.equalsIgnoreCase(reportOption)) { if (nonEndowedAssetStatementReportDataHolders != null && nonEndowedAssetStatementReportDataHolders.size() > 0) { // non-endowed detail generateNonEndowedDetailReport(nonEndowedAssetStatementReportDataHolders, reportHeaderDataHolderForNonEndowed, document, listKemidsInHeader, false); // non-endowed total generateNonEndowedTotalReport(nonEndowedAssetStatementReportDataHolders, reportHeaderDataHolderForNonEndowed, document, listKemidsInHeader, true); } } else if (EndowConstants.EndowmentReport.BOTH.equalsIgnoreCase(endowmentOption) && EndowConstants.EndowmentReport.DETAIL.equalsIgnoreCase(reportOption)) { if (endowmentAssetStatementReportDataHolders != null && endowmentAssetStatementReportDataHolders.size() > 0) { // endowment detail generateEndowmentDetailReport(endowmentAssetStatementReportDataHolders, reportHeaderDataHolderForEndowment, document, listKemidsInHeader, false); } if (nonEndowedAssetStatementReportDataHolders != null && nonEndowedAssetStatementReportDataHolders.size() > 0) { // non-endowed detail generateNonEndowedDetailReport(nonEndowedAssetStatementReportDataHolders, reportHeaderDataHolderForNonEndowed, document, listKemidsInHeader, true); } } else if (EndowConstants.EndowmentReport.BOTH.equalsIgnoreCase(endowmentOption) && EndowConstants.EndowmentReport.TOTAL.equalsIgnoreCase(reportOption)) { if (endowmentAssetStatementReportDataHolders != null && endowmentAssetStatementReportDataHolders.size() > 0) { // endowment total generateEndowmentTotalReport(endowmentAssetStatementReportDataHolders, reportHeaderDataHolderForEndowment, document, listKemidsInHeader, false); } if (nonEndowedAssetStatementReportDataHolders != null && nonEndowedAssetStatementReportDataHolders.size() > 0) { // non-endowed total generateNonEndowedTotalReport(nonEndowedAssetStatementReportDataHolders, reportHeaderDataHolderForNonEndowed, document, listKemidsInHeader, true); } } else if (EndowConstants.EndowmentReport.BOTH.equalsIgnoreCase(endowmentOption) && EndowConstants.EndowmentReport.BOTH.equalsIgnoreCase(reportOption)) { if (endowmentAssetStatementReportDataHolders != null && endowmentAssetStatementReportDataHolders.size() > 0) { // endowment detail generateEndowmentDetailReport(endowmentAssetStatementReportDataHolders, reportHeaderDataHolderForEndowment, document, listKemidsInHeader, false); // endowment total generateEndowmentTotalReport(endowmentAssetStatementReportDataHolders, reportHeaderDataHolderForEndowment, document, listKemidsInHeader, true); } if (nonEndowedAssetStatementReportDataHolders != null && nonEndowedAssetStatementReportDataHolders.size() > 0) { // non-endowed detail generateNonEndowedDetailReport(nonEndowedAssetStatementReportDataHolders, reportHeaderDataHolderForNonEndowed, document, listKemidsInHeader, true); // non-endowed total generateNonEndowedTotalReport(nonEndowedAssetStatementReportDataHolders, reportHeaderDataHolderForNonEndowed, document, listKemidsInHeader, true); } } document.close(); } catch (Exception e) { LOG.error("Error in AssetStatementReportPrint:printAssetStatementReport(): " + e.getMessage()); return null; } return pdfStream; }
From source file:org.kuali.kfs.module.endow.report.util.TransactionStatementReportPrint.java
License:Educational Community License
/** * Generates the report in PDF using iText * /*from www . j av a 2 s.c o m*/ * @param reportRequestHeaderDataHolder * @param transactionStatementDataReportHolders * @return */ public ByteArrayOutputStream printTransactionStatementReport( EndowmentReportHeaderDataHolder reportRequestHeaderDataHolder, List<TransactionStatementReportDataHolder> transactionStatementDataReportHolders, String listKemidsInHeader) { final org.apache.log4j.Logger LOG = org.apache.log4j.Logger .getLogger(TransactionStatementReportPrint.class); Document document = new Document(); document.setPageSize(LETTER_PORTRAIT); document.addTitle("Endowment Transaction Statement"); ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); try { PdfWriter.getInstance(document, pdfStream); document.open(); // print the report header if (printReportHeaderPage(reportRequestHeaderDataHolder, document, listKemidsInHeader)) { // and then the body if (transactionStatementDataReportHolders != null && transactionStatementDataReportHolders.size() > 0) { printTransactionStatementReportBody(transactionStatementDataReportHolders, document); } } else { LOG.error("Transaction Statement Report Header Error"); } document.close(); } catch (Exception e) { LOG.error("PDF Error: " + e.getMessage()); return null; } return pdfStream; }
From source file:org.kuali.kfs.module.endow.report.util.TransactionSummaryReportPrint.java
License:Educational Community License
/** * Generates the report in PDF using iText * //from w w w . j a va 2s. c o m * @param reportRequestHeaderDataHolder * @param transactionStatementDataReportHolders * @return pdfStream */ public ByteArrayOutputStream printTransactionSummaryReport( EndowmentReportHeaderDataHolder reportRequestHeaderDataHolder, List<TransactionSummaryReportDataHolder> transactionSummaryDataReportHolders, String listKemidsInHeader, String reportOption, String summaryTotalsOnly) { Document document = new Document(); document.setPageSize(LETTER_PORTRAIT); document.addTitle("Endowment Transaction Summary"); ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); try { PdfWriter.getInstance(document, pdfStream); document.open(); // page HeaderFooter header = new HeaderFooter(new Phrase(new Date().toString() + " Page: ", headerFont), true); header.setBorder(Rectangle.NO_BORDER); header.setAlignment(Element.ALIGN_RIGHT); header.setPageNumber(0); document.setHeader(header); // print the report header if (printReportHeaderPage(reportRequestHeaderDataHolder, document, listKemidsInHeader)) { if (transactionSummaryDataReportHolders != null && transactionSummaryDataReportHolders.size() > 0) { if ("Y".equalsIgnoreCase(summaryTotalsOnly)) { printReportBodyBySummaryTotals(transactionSummaryDataReportHolders, document, reportOption); } else { printReportBodyByAllTotals(transactionSummaryDataReportHolders, document, reportOption); } } } else { LOG.error("Transaction Summary Report Header Error"); } document.close(); } catch (Exception e) { LOG.error("PDF Error: " + e.getMessage()); return null; } return pdfStream; }
From source file:org.kuali.kfs.module.endow.report.util.TrialBalanceReportPrint.java
License:Educational Community License
/** * Generates the report in PDF using iText * /*from w w w .ja va 2 s .com*/ * @param reportRequestHeaderDataHolder * @param trialBalanceDataReportHolders * @return ByteArrayOutputStream */ public ByteArrayOutputStream printTrialBalanceReport( EndowmentReportHeaderDataHolder reportRequestHeaderDataHolder, List<TrialBalanceReportDataHolder> trialBalanceDataReportHolders, String listKemidsInHeader) { final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TrialBalanceReportPrint.class); Document document = new Document(); document.setPageSize(LETTER_PORTRAIT); document.addTitle("Endowment Trial Balance"); // get the stream for PDF ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); try { PdfWriter.getInstance(document, pdfStream); document.open(); // page HeaderFooter header = new HeaderFooter(new Phrase(new Date().toString() + " Page: ", headerFont), true); header.setBorder(Rectangle.NO_BORDER); header.setAlignment(Element.ALIGN_RIGHT); header.setPageNumber(0); document.setHeader(header); // print the report header if (printReportHeaderPage(reportRequestHeaderDataHolder, document, listKemidsInHeader)) { if (trialBalanceDataReportHolders != null && trialBalanceDataReportHolders.size() > 0) { document.setPageSize(LETTER_LANDSCAPE); document.resetPageCount(); header.setPageNumber(1); document.newPage(); printTrialBalanceReportBody(trialBalanceDataReportHolders, document); } else { LOG.error("Trial Balance Report Header Error"); } } document.close(); } catch (Exception e) { LOG.error("PDF Error: " + e.getMessage()); return null; } return pdfStream; }
From source file:org.mapfish.print.config.layout.MetaData.java
License:Open Source License
public void render(PJsonObject params, RenderingContext context) { final Document doc = context.getDocument(); if (title != null) { doc.addTitle(PDFUtils.evalString(context, params, title)); }/*ww w. j a va 2 s. c o m*/ if (author != null) { doc.addAuthor(PDFUtils.evalString(context, params, author)); } if (subject != null) { doc.addSubject(PDFUtils.evalString(context, params, subject)); } if (keywords != null) { doc.addKeywords(PDFUtils.evalString(context, params, keywords)); } if (creator != null) { doc.addCreator(PDFUtils.evalString(context, params, creator)); } }
From source file:org.mnsoft.pdfocr.CreatorSetter.java
License:Open Source License
/** * @param args/*from w w w . j av a 2 s. c om*/ * @throws DocumentException * @throws IOException * @throws IOException * @throws BadPdfFormatException */ @SuppressWarnings("rawtypes") public static void main(String[] args) throws DocumentException, IOException { /* * Verify arguments */ if ((args == null) || (args.length < 2)) { System.err.println("Usage: first parameter: Creator to set, following parameters: Files to work on."); System.exit(1); } final String creator = args[0]; for (int i = 1; i < args.length; i++) { final File f = new File(args[i]); if ((f == null) || !f.exists() || !f.isFile() || !f.getName().endsWith(".pdf")) { System.err.println("! ERROR: Could not read " + args[i] + " or this is not a .pdf"); continue; } final String p = f.getAbsolutePath(); /* * Open the reader */ PdfReader reader; try { reader = new PdfReader(p); } catch (Exception e) { System.err.println("! ERROR: " + e.getMessage() + " File: " + p); continue; } /* * Get the document information */ Map info = reader.getInfo(); /* * Get the document creator. If the document * has already been worked on, continue with * the next document. */ String doc_creator = (String) info.get("Creator"); if (creator.equals(doc_creator)) { System.out.println("+ INFO: File " + p + " had already the right creator."); continue; } /* * Get the document time stamp so that we can set it later. */ final Date doc_timestamp = new Date(f.lastModified()); /* * Get the number of pages in the original file */ int nOri = reader.getNumberOfPages(); System.out.print("+ INFO: Working on: " + p + " (" + nOri + " pages) ... "); /* * Get the remaining meta data */ String doc_title = ((String) info.get("Title") == null) ? "" : (String) info.get("Title"); String doc_subject = ((String) info.get("Subject") == null) ? "" : (String) info.get("Subject"); String doc_keywords = ((String) info.get("Keywords") == null) ? "" : (String) info.get("Keywords"); String doc_author = ((String) info.get("Author") == null) ? "" : (String) info.get("Author"); reader.close(); /* * Set the creator to our marker */ doc_creator = creator; /* * Merge the new document with the meta * data from the original document */ try { reader = new PdfReader(p); } catch (Exception e) { System.err.println("! ERROR: " + e.getMessage() + " File: " + p); continue; } /* * Get the document information */ info = reader.getInfo(); /* * Get the document creator. If the document * has already been worked on, we assume we * have had a successful output from the OCR * engine */ String doc_creator_copy = (String) info.get("Creator"); if (creator.equals(doc_creator_copy)) { System.out.println(); continue; } /* * Step 1: creation of a document object */ final Document document = new Document(reader.getPageSizeWithRotation(1)); /* * Step 2: we create a writer that listens to the document */ PdfCopy writer = new PdfCopy(document, new FileOutputStream(p + ".tmp")); /* * Step 3: we add the meta data */ document.addTitle(doc_title); document.addSubject(doc_subject); document.addKeywords(doc_keywords); document.addCreator(creator); document.addAuthor(doc_author); /* * Step 4: we open the document */ document.open(); PdfImportedPage page; int j = 0; /* * Step 5: we add content */ while (j < nOri) { j++; page = writer.getImportedPage(reader, j); writer.addPage(page); System.out.print("[" + j + "] "); } PRAcroForm form = reader.getAcroForm(); if (form != null) { writer.copyAcroForm(reader); } System.out.println(); /* * Step 6: we close the document */ document.close(); reader.close(); /* * Set the file access time and * rename the file. */ File file = new File(p + ".tmp"); if (file.exists()) { deleteFile(p); file.setLastModified(doc_timestamp.getTime()); file.renameTo(new File(p)); } } }