List of usage examples for com.lowagie.text Document Document
public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
Document
-object. From source file:io.vertigo.dynamo.plugins.export.pdfrtf.AbstractExporterIText.java
License:Apache License
/** * Mthode principale qui gre l'export d'un tableau vers un fichier ODS. * * @param export paramtres du document exporter * @param out flux de sortie/*ww w. j a va2s . c om*/ * @throws DocumentException Exception */ public final void exportData(final Export export, final OutputStream out) throws DocumentException { // step 1: creation of a document-object final boolean landscape = export.getOrientation() == Export.Orientation.Landscape; final Rectangle pageSize = landscape ? PageSize.A4.rotate() : PageSize.A4; final Document document = new Document(pageSize, 20, 20, 50, 50); // left, // right, // top, // bottom // step 2: we create a writer that listens to the document and directs a // PDF-stream to out createWriter(document, out); // we add some meta information to the document, and we open it final String title = export.getTitle(); if (title != null) { final HeaderFooter header = new HeaderFooter(new Phrase(title), false); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(title); } final String author = export.getAuthor(); document.addAuthor(author); document.addCreator(CREATOR); document.open(); try { // pour ajouter l'ouverture automatique de la bote de dialogue // imprimer // (print(false) pour imprimer directement) // ((PdfWriter) writer).addJavaScript("this.print(true);", false); for (final ExportSheet exportSheet : export.getSheets()) { final Table datatable; if (exportSheet.hasDtObject()) { // table datatable = new Table(2); datatable.setCellsFitPage(true); datatable.setPadding(4); datatable.setSpacing(0); // data rows renderObject(exportSheet, datatable); } else { // table datatable = new Table(exportSheet.getExportFields().size()); datatable.setCellsFitPage(true); datatable.setPadding(4); datatable.setSpacing(0); // headers renderHeaders(exportSheet, datatable); // data rows renderList(exportSheet, datatable); } document.add(datatable); } } finally { // we close the document document.close(); } }
From source file:io.vertigo.quarto.plugins.export.pdfrtf.AbstractExporterIText.java
License:Apache License
/** * Mthode principale qui gre l'export d'un tableau vers un fichier ODS. * * @param export paramtres du document exporter * @param out flux de sortie/* ww w. j ava2s .c o m*/ * @throws DocumentException Exception */ public final void exportData(final Export export, final OutputStream out) throws DocumentException { // step 1: creation of a document-object final boolean landscape = export.getOrientation() == Export.Orientation.Landscape; final Rectangle pageSize = landscape ? PageSize.A4.rotate() : PageSize.A4; final Document document = new Document(pageSize, 20, 20, 50, 50); // left, right, top, bottom // step 2: we create a writer that listens to the document and directs a PDF-stream to out createWriter(document, out); // we add some meta information to the document, and we open it final String title = export.getTitle(); if (title != null) { final HeaderFooter header = new HeaderFooter(new Phrase(title), false); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(title); } final String author = export.getAuthor(); document.addAuthor(author); document.addCreator(CREATOR); document.open(); try { // pour ajouter l'ouverture automatique de la bote de dialogue imprimer (print(false) pour imprimer directement) // ((PdfWriter) writer).addJavaScript("this.print(true);", false); for (final ExportSheet exportSheet : export.getSheets()) { final Table datatable; if (exportSheet.hasDtObject()) { // table datatable = new Table(2); datatable.setCellsFitPage(true); datatable.setPadding(4); datatable.setSpacing(0); // data rows renderObject(exportSheet, datatable); } else { // table datatable = new Table(exportSheet.getExportFields().size()); datatable.setCellsFitPage(true); datatable.setPadding(4); datatable.setSpacing(0); // headers renderHeaders(exportSheet, datatable); // data rows renderList(exportSheet, datatable); } document.add(datatable); } } finally { // we close the document document.close(); } }
From source file:is.idega.idegaweb.egov.cases.business.CaseWriter.java
License:Open Source License
protected MemoryFileBuffer writePDF(IWContext iwc) { Font titleFont = new Font(Font.HELVETICA, 14, Font.BOLD); Font labelFont = new Font(Font.HELVETICA, 11, Font.BOLD); Font textFont = new Font(Font.HELVETICA, 11, Font.NORMAL); try {//from w w w . java 2 s . co m MemoryFileBuffer buffer = new MemoryFileBuffer(); MemoryOutputStream mos = new MemoryOutputStream(buffer); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter.getInstance(document, mos); document.addAuthor("Idegaweb eGov"); document.addSubject("Case"); document.open(); document.newPage(); String title = iwrb.getLocalizedString("case_overview", "Case overview"); Paragraph cTitle = new Paragraph(title, titleFont); cTitle.setSpacingAfter(24); document.setPageCount(1); document.add(cTitle); int[] widths = { 25, 75 }; PdfPTable table = new PdfPTable(2); table.setWidths(widths); table.getDefaultCell().setBorder(0); table.getDefaultCell().setPaddingBottom(8); CaseCategory category = theCase.getCaseCategory(); CaseCategory parentCategory = category.getParent(); CaseType type = theCase.getCaseType(); User user = theCase.getOwner(); Address address = user != null ? getUserBusiness(iwc).getUsersMainAddress(user) : null; PostalCode postal = null; if (address != null) { postal = address.getPostalCode(); } Phone phone = null; if (user != null) { try { phone = getUserBusiness(iwc).getUsersHomePhone(user); } catch (NoPhoneFoundException e) { //No phone found... } } Email email = null; if (user != null) { try { email = getUserBusiness(iwc).getUsersMainEmail(user); } catch (NoEmailFoundException e) { //No email found... } } IWTimestamp created = new IWTimestamp(theCase.getCreated()); if (user != null) { table.addCell(new Phrase(iwrb.getLocalizedString("name", "Name"), labelFont)); table.addCell(new Phrase( new Name(user.getFirstName(), user.getMiddleName(), user.getLastName()).getName(locale), textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("personal_id", "Personal ID"), labelFont)); table.addCell(new Phrase(PersonalIDFormatter.format(user.getPersonalID(), locale), textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("address", "Address"), labelFont)); table.addCell(new Phrase(address != null ? address.getStreetAddress() : "-", textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("zip_code", "Postal code"), labelFont)); table.addCell(new Phrase(postal != null ? postal.getPostalAddress() : "-", textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("home_phone", "Home phone"), labelFont)); table.addCell(new Phrase(phone != null ? phone.getNumber() : "-", textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("email", "Email"), labelFont)); table.addCell(new Phrase(email != null ? email.getEmailAddress() : "-", textFont)); table.addCell(new Phrase("")); table.addCell(new Phrase("")); table.addCell(new Phrase("")); table.addCell(new Phrase("")); } table.addCell(new Phrase(iwrb.getLocalizedString("case_nr", "Case nr."), labelFont)); table.addCell(new Phrase(theCase.getPrimaryKey().toString(), textFont)); if (getCasesBusiness(iwc).useTypes()) { table.addCell(new Phrase(iwrb.getLocalizedString("case_type", "Case type"), labelFont)); table.addCell(new Phrase(type.getName(), textFont)); } if (parentCategory != null) { table.addCell(new Phrase(iwrb.getLocalizedString("case_category", "Case category"), labelFont)); table.addCell(new Phrase(parentCategory.getLocalizedCategoryName(locale), textFont)); table.addCell(new Phrase(iwrb.getLocalizedString("sub_case_category", "Case category"), labelFont)); table.addCell(new Phrase(category.getLocalizedCategoryName(locale), textFont)); } else { table.addCell(new Phrase(iwrb.getLocalizedString("case_category", "Case category"), labelFont)); table.addCell(new Phrase(category.getLocalizedCategoryName(locale), textFont)); } table.addCell(new Phrase(iwrb.getLocalizedString("created_date", "Created date"), labelFont)); table.addCell(new Phrase(created.getLocaleDateAndTime(locale, IWTimestamp.SHORT, IWTimestamp.SHORT), textFont)); if (theCase.getSubject() != null) { table.addCell(new Phrase(iwrb.getLocalizedString("subject", "Subject"), labelFont)); table.addCell(new Phrase(theCase.getSubject(), textFont)); } table.addCell(new Phrase(iwrb.getLocalizedString("message", "Message"), labelFont)); table.addCell(new Phrase(theCase.getMessage(), textFont)); if (theCase.getReference() != null) { table.addCell(new Phrase(iwrb.getLocalizedString("reference", "Reference"), labelFont)); table.addCell(new Phrase(theCase.getReference(), textFont)); } table.setWidthPercentage(100); document.add(table); document.close(); try { mos.close(); } catch (Exception ex) { ex.printStackTrace(); } buffer.setMimeType("application/pdf"); return buffer; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java
License:Open Source License
protected Document getLetterDocumentTemplate() { // Margins defined in millimeters: float headFootMarginsMM = 9.0f; float leftRightMarginsMM = 30.0f; // Margins defined in points: float headFootMargins = getPointsFromMM(headFootMarginsMM); float leftRightMargins = getPointsFromMM(leftRightMarginsMM); Document document = new Document(PageSize.A4, leftRightMargins, leftRightMargins, headFootMargins, headFootMargins);// w w w . j a v a2s . co m // document.setMargins(leftRightMargins,leftRightMargins,headFootMargins,headFootMargins); document.addAuthor("IdegaWeb"); document.addSubject("PrintedLetter"); // document.open(); return document; }
From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java
License:Open Source License
private ByteArrayOutputStream exportAsPdf(Experiment3VO experiment, List<Buffer3VO> buffers, Proposal3VO proposal) throws Exception { Document document = new Document(PageSize.A4.rotate(), 10, 10, 20, 20); document.addTitle("exportSamplesView"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); HeaderFooter header = new HeaderFooter( new Phrase(proposal.getTitle() + " " + proposal.getCode() + proposal.getNumber()), false); header.setAlignment(Element.ALIGN_CENTER); header.getBefore().getFont().setSize(8); HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true); footer.setAlignment(Element.ALIGN_RIGHT); footer.setBorderWidth(1);// www. j ava 2 s . co m footer.getBefore().getFont().setSize(6); document.setHeader(header); document.setFooter(footer); document.open(); BaseFont bf = BaseFont.createFont(FONTS[0][0], FONTS[0][1], BaseFont.EMBEDDED); Font font = new Font(bf, 6); document.add(new Paragraph("Data Acquisition: " + experiment.getName(), font)); document.add(new Paragraph("Type: " + experiment.getType(), font)); document.add(new Paragraph("Date: " + experiment.getCreationDate(), font)); document.add(new Paragraph("Proposal: " + proposal.getCode() + proposal.getNumber(), font)); document.add(new Paragraph("Title: " + proposal.getTitle(), font)); document.add(new Paragraph(" ")); document.add(new Paragraph("Measurements", PdfRtfExporter.FONT_DOC_BOLD)); document.add(new Paragraph(" ")); document.add(this.getMeasurementTable(experiment, buffers)); document.newPage(); document.add(new Paragraph(" ")); document.add(new Paragraph("Analysis", PdfRtfExporter.FONT_DOC_BOLD)); document.add(new Paragraph(" ")); document.add(this.getAnalysis(experiment, buffers)); document.newPage(); document.add(this.getImageTable(experiment, buffers)); document.close(); return baos; }
From source file:ispyb.client.mx.collection.PdfRtfExporter.java
License:Open Source License
/** * export datacollection report/*from www . j av a2 s . c o m*/ * * @param rtfFormat * @return * @throws Exception */ public ByteArrayOutputStream exportDataCollectionReport(boolean rtfFormat) throws Exception { // create simple doc and write to a ByteArrayOutputStream Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (!rtfFormat) { PdfWriter.getInstance(document, baos); } else { RtfWriter2.getInstance(document, baos); } // ============================= // Header + footer // ============================= setHeader(document); setFooter(document); document.open(); // =============================== // Body // =============================== // Crystallographer added only for IFX proposal in case of MXPress // experiment setCrystallographer(document); // Session comments setSessionComments(document); // session title& info setSessionTable(document); // ====================== // Data Collection table // ====================== document.add(new Paragraph(" ")); setDataCollectionTable(document); // ====================== // Energy scans // ====================== document.add(new Paragraph(" ")); setEnergyScansTable(document); // ====================== // XRF Spectra // ====================== document.add(new Paragraph(" ")); setXfrSpectraTable(document); // ====================== // Summary // ====================== setSummary(document); // ====================== // End of file // ====================== document.close(); return baos; }
From source file:ispyb.client.mx.collection.PdfRtfExporter.java
License:Open Source License
/** * export detailed dataCollection// ww w. j a v a 2 s . c o m * * @return * @throws Exception */ public ByteArrayOutputStream exportScreeningAsPDF(boolean rtfFormat, HttpServletRequest mRequest) throws Exception { // create simple doc and write to a ByteArrayOutputStream Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (!rtfFormat) { PdfWriter.getInstance(document, baos); } else { RtfWriter2.getInstance(document, baos); } // ============================= // Header + footer // ============================= setHeader(document); setFooter(document); document.open(); // =============================== // Body // =============================== // Session comments setSessionComments(document); document.add(new Paragraph(" ")); if (dataCollectionList.isEmpty()) { document.add(new Paragraph("There is no data collection in this report", PdfRtfExporter.FONT_DOC)); } else { Iterator<DataCollection3VO> it = dataCollectionList.iterator(); Session3Service sessionService = (Session3Service) ejb3ServiceLocator .getLocalService(Session3Service.class); AutoProc3VO[] autoProcs = wrapper.getAutoProcs(); AutoProcScalingStatistics3VO[] autoProcsOverall = wrapper.getScalingStatsOverall(); AutoProcScalingStatistics3VO[] autoProcsInner = wrapper.getScalingStatsInner(); AutoProcScalingStatistics3VO[] autoProcsOuter = wrapper.getScalingStatsOuter(); int i = 0; // int mNbDataCollectionOnPage = 0; boolean firstPage = true; while (it.hasNext()) { if (firstPage) { firstPage = false; } else { document.newPage(); } DataCollection3VO dcValue = it.next(); DataCollectionExporter dcExporter = new DataCollectionExporter(df2, df3, proposalCode, proposalNumber, mRequest); DataCollectionInformation dcInfo = dcExporter.getDataCollectionInformation(dcValue, getSampleRankingVO(dcValue.getDataCollectionId()), getAutoProcRankingVO(dcValue.getDataCollectionId())); // dataCollection general info: Date, screen/Collect, indexing // status setDataCollectionGeneralInfo(document, dcValue, dcInfo); Table table = new Table(NB_COL_DATACOLLECTION); table.setCellsFitPage(true); // dataCollection table - one row table = setDataCollectionHeader(document, table, true); setDataCollectionData(document, table, dcValue, sessionService, autoProcs[i], autoProcsOverall[i], autoProcsInner[i], autoProcsOuter[i], true, false, null, null); document.add(table); i++; document.add(new Paragraph(" ", VERY_SMALL_FONT)); // Images setImagesTable(document, dcInfo); setEDNATable(document, dcInfo); setStrategyTable(document, dcInfo); // End of the page? // mNbDataCollectionOnPage++; // if (mNbDataCollectionOnPage == // NB_DATA_COLLECTION_PER_PAGE){// New Page // document.newPage(); // mNbDataCollectionOnPage = 0; // } else{ // Same Page // document.add(new Paragraph(" ", VERY_SMALL_FONT)); // } } } // ====================== // End of file // ====================== document.close(); return baos; }
From source file:ispyb.client.mx.collection.PdfRtfExporter.java
License:Open Source License
/** * export detailed dataCollection report: new screening report * /*from ww w .ja v a 2 s. c o m*/ * @return * @throws Exception */ public ByteArrayOutputStream exportDetails(boolean rtfFormat, HttpServletRequest mRequest) throws Exception { // create simple doc and write to a ByteArrayOutputStream Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (!rtfFormat) { PdfWriter.getInstance(document, baos); } else { RtfWriter2.getInstance(document, baos); } // ============================= // Header + footer // ============================= setHeaderForDetails(document); setFooter(document); document.open(); // =============================== // Body // =============================== // Session comments setSessionComments(document); document.add(new Paragraph(" ")); // build the list with the collect and collects group by workflow + // energyScan+ XRFSpectra // this list is sorted by time List<SessionDataObjectInformation> listSessionDataObject = sessionDataObjectList; if (listSessionDataObject.isEmpty()) { document.add(new Paragraph("There is no data in this report", PdfRtfExporter.FONT_DOC)); } else { // for each object, we will display a different table int countTables = 0; for (Iterator<SessionDataObjectInformation> iterator = listSessionDataObject.iterator(); iterator .hasNext();) { SessionDataObjectInformation sessionDataObject = (SessionDataObjectInformation) iterator.next(); if (countTables > 1) { // System.out.println("page break"); document.newPage(); countTables = 0; } setDetailSessionObjectTable(document, sessionDataObject, mRequest); countTables++; } } // ====================== // End of file // ====================== document.close(); return baos; }
From source file:ispyb.client.mx.collection.PdfRtfExporter.java
License:Open Source License
/** * export ranking dataCollection/* ww w . j a v a 2 s . c o m*/ * * @return * @throws Exception */ public ByteArrayOutputStream exportRankingAsPDF(boolean rtfFormat, HttpServletRequest mRequest) throws Exception { // create simple doc and write to a ByteArrayOutputStream Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20); // Document document = new Document(PageSize.A4); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (!rtfFormat) { PdfWriter.getInstance(document, baos); } else { RtfWriter2.getInstance(document, baos); } // ============================= // Header + footer // ============================= setHeader(document); setFooter(document); document.open(); // =============================== // Body // =============================== // Session comments setSessionComments(document); document.add(new Paragraph(" ")); if (dataCollectionList.isEmpty()) { document.add(new Paragraph("There is no data collection in this report", PdfRtfExporter.FONT_DOC)); } else { Iterator<DataCollection3VO> it = dataCollectionList.iterator(); Session3Service sessionService = (Session3Service) ejb3ServiceLocator .getLocalService(Session3Service.class); AutoProc3VO[] autoProcs = wrapper.getAutoProcs(); AutoProcScalingStatistics3VO[] autoProcsOverall = wrapper.getScalingStatsOverall(); AutoProcScalingStatistics3VO[] autoProcsInner = wrapper.getScalingStatsInner(); AutoProcScalingStatistics3VO[] autoProcsOuter = wrapper.getScalingStatsOuter(); int i = 0; boolean firstPage = true; while (it.hasNext()) { if (firstPage) { firstPage = false; } else { document.newPage(); } DataCollection3VO dcValue = it.next(); DataCollectionExporter dcExporter = new DataCollectionExporter(df2, df3, proposalCode, proposalNumber, mRequest); DataCollectionInformation dcInfo = dcExporter.getDataCollectionInformation(dcValue, getSampleRankingVO(dcValue.getDataCollectionId()), getAutoProcRankingVO(dcValue.getDataCollectionId())); // dataCollection general info: Date, screen/Collect, indexing // status setDataCollectionGeneralInfo(document, dcValue, dcInfo); Table table = new Table(NB_COL_DATACOLLECTION); table.setCellsFitPage(true); // dataCollection table - one row table = setDataCollectionHeader(document, table, false); setDataCollectionData(document, table, dcValue, sessionService, autoProcs[i], autoProcsOverall[i], autoProcsInner[i], autoProcsOuter[i], false, false, null, null); document.add(table); i++; document.add(new Paragraph(" ", VERY_SMALL_FONT)); setRankingTable(document, dcInfo); // Images setImagesTable(document, dcInfo); setEDNATable(document, dcInfo); setStrategyTable(document, dcInfo); } } // ====================== // End of file // ====================== document.close(); return baos; }
From source file:ispyb.client.mx.collection.PdfRtfExporter.java
License:Open Source License
/** * export auto proc ranking dataCollection * //from w w w. j a va2 s.c o m * @return * @throws Exception */ public ByteArrayOutputStream exportAutoProcRankingAsPDF(boolean rtfFormat, HttpServletRequest mRequest) throws Exception { // create simple doc and write to a ByteArrayOutputStream Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20); // Document document = new Document(PageSize.A4); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (!rtfFormat) { PdfWriter.getInstance(document, baos); } else { RtfWriter2.getInstance(document, baos); } // ============================= // Header + footer // ============================= setHeader(document); setFooter(document); document.open(); // =============================== // Body // =============================== // Session comments setSessionComments(document); document.add(new Paragraph(" ")); if (dataCollectionList.isEmpty()) { document.add(new Paragraph("There is no data collection in this report", PdfRtfExporter.FONT_DOC)); } else { Iterator<DataCollection3VO> it = dataCollectionList.iterator(); Session3Service sessionService = (Session3Service) ejb3ServiceLocator .getLocalService(Session3Service.class); AutoProc3VO[] autoProcs = wrapper.getAutoProcs(); AutoProcScalingStatistics3VO[] autoProcsOverall = wrapper.getScalingStatsOverall(); AutoProcScalingStatistics3VO[] autoProcsInner = wrapper.getScalingStatsInner(); AutoProcScalingStatistics3VO[] autoProcsOuter = wrapper.getScalingStatsOuter(); int i = 0; boolean firstPage = true; while (it.hasNext()) { if (firstPage) { firstPage = false; } else { document.newPage(); } DataCollection3VO dcValue = it.next(); DataCollectionExporter dcExporter = new DataCollectionExporter(df2, df3, proposalCode, proposalNumber, mRequest); DataCollectionInformation dcInfo = dcExporter.getDataCollectionInformation(dcValue, getSampleRankingVO(dcValue.getDataCollectionId()), getAutoProcRankingVO(dcValue.getDataCollectionId())); // dataCollection general info: Date, screen/Collect, indexing // status setDataCollectionGeneralInfo(document, dcValue, dcInfo); Table table = new Table(NB_COL_DATACOLLECTION); table.setCellsFitPage(true); // dataCollection table - one row table = setDataCollectionHeader(document, table, false); setDataCollectionData(document, table, dcValue, sessionService, autoProcs[i], autoProcsOverall[i], autoProcsInner[i], autoProcsOuter[i], false, false, null, null); document.add(table); i++; document.add(new Paragraph(" ", VERY_SMALL_FONT)); setAutoProcRankingTable(document, dcInfo); // Images setImagesTable(document, dcInfo); setEDNATable(document, dcInfo); setStrategyTable(document, dcInfo); } } // ====================== // End of file // ====================== document.close(); return baos; }