List of usage examples for com.lowagie.text Paragraph setSpacingAfter
public void setSpacingAfter(float spacing)
From source file:com.qcadoo.report.internal.PdfHelperImpl.java
License:Open Source License
@Override public void addDocumentHeaderThin(final Document document, final String name, final String documentTitle, final String documentAuthor, final Date date) throws DocumentException { SimpleDateFormat df = new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, getLocale()); LineSeparator line = new LineSeparator(2, 100f, ColorUtils.getLineDarkColor(), Element.ALIGN_LEFT, 0); Paragraph title = new Paragraph(new Phrase(documentTitle, FontUtils.getDejavuBold14Light())); title.add(new Phrase(" " + name, FontUtils.getDejavuBold14Dark())); title.setSpacingAfter(7f); document.add(title);//from ww w .j a va2 s.c o m document.add(line); PdfPTable userAndDate = new PdfPTable(2); userAndDate.setWidthPercentage(100f); userAndDate.setHorizontalAlignment(Element.ALIGN_LEFT); userAndDate.getDefaultCell().setBorderWidth(0); Paragraph userParagraph = new Paragraph(new Phrase(documentAuthor, FontUtils.getDejavuRegular9Light())); userParagraph.add(new Phrase(" " + getDocumentAuthor(), FontUtils.getDejavuRegular9Dark())); Paragraph dateParagraph = new Paragraph(df.format(date), FontUtils.getDejavuRegular9Light()); userAndDate.addCell(userParagraph); userAndDate.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); userAndDate.addCell(dateParagraph); userAndDate.setSpacingAfter(10f); document.add(userAndDate); }
From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java
License:Open Source License
private void writeFrontpage(String name, Document document, List<PdfSolution> solutions) throws DocumentException { document.open();/* ww w .jav a 2 s . com*/ Paragraph p = new Paragraph(name); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingBefore(20f); p.setSpacingAfter(20f); document.add(p); PdfPTable table = new PdfPTable(17); table.setWidthPercentage(100); int[] width = { 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; table.setWidths(width); PdfPCell cell; table.addCell(buildHeaderCell("Name", 90, true, false)); table.addCell(buildHeaderCell("Schwierigkeitsgrad", 90, false, false)); table.addCell(buildHeaderCell("Besetzte Zellen", 90, false, false)); table.addCell(buildHeaderCell("Simple", 90, false, false)); table.addCell(buildHeaderCell("Hidden Single", 90, false, false)); table.addCell(buildHeaderCell("Naked Pair", 90, false, false)); table.addCell(buildHeaderCell("Naked Triple", 90, false, false)); table.addCell(buildHeaderCell("Naked Quad", 90, false, false)); table.addCell(buildHeaderCell("Hidden Pair", 90, false, false)); table.addCell(buildHeaderCell("Hidden Triple", 90, false, false)); table.addCell(buildHeaderCell("Hidden Quad", 90, false, false)); table.addCell(buildHeaderCell("Intersection Removal", 90, false, false)); table.addCell(buildHeaderCell("Y-Wing", 90, false, false)); table.addCell(buildHeaderCell("X-Wing", 90, false, false)); table.addCell(buildHeaderCell("Jellyfish", 90, false, false)); table.addCell(buildHeaderCell("Swordfish", 90, false, false)); table.addCell(buildHeaderCell("Backtracking", 90, false, true)); boolean even = false; for (PdfSolution solution : solutions) { table.addCell(buildBodyNumberCell(solution.getId(), even, true, false)); table.addCell(buildBodyTextCell(solution.getLevel().toString(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getFixed(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategySimple(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyHiddenSingle(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyNakedPair(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyNakedTriple(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyNakedQuad(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyHiddenPair(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyHiddenTriple(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyHiddenQuad(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyIntersectionRemoval(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyYwing(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyXwing(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyJellyfish(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategySwordfish(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyBacktracking(), even, false, true)); even = (even ? false : true); } document.add(table); document.close(); }
From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.utils.PDFUtils.java
License:Open Source License
/** * method to create PDF/*from w w w .j ava 2 s . com*/ * @param adminUser The admin user * @param locale The locale * @param strNameFile PDF name * @param out OutputStream * @param nIdRecord the id record * @param listIdEntryConfig list of config id entry * @param bExtractNotFilledField if true, extract empty fields, false */ public static void doCreateDocumentPDF(AdminUser adminUser, Locale locale, String strNameFile, OutputStream out, int nIdRecord, List<Integer> listIdEntryConfig, Boolean bExtractNotFilledField) { Document document = new Document(PageSize.A4); Plugin plugin = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME); EntryFilter filter; Record record = RecordHome.findByPrimaryKey(nIdRecord, plugin); filter = new EntryFilter(); filter.setIdDirectory(record.getDirectory().getIdDirectory()); filter.setIsGroup(EntryFilter.FILTER_TRUE); List<IEntry> listEntry = DirectoryUtils.getFormEntries(record.getDirectory().getIdDirectory(), plugin, adminUser); int nIdDirectory = record.getDirectory().getIdDirectory(); Directory directory = DirectoryHome.findByPrimaryKey(nIdDirectory, plugin); try { PdfWriter.getInstance(document, out); } catch (DocumentException e) { AppLogService.error(e); } document.open(); if (record.getDateCreation() != null) { SimpleDateFormat monthDayYearformatter = new SimpleDateFormat( AppPropertiesService.getProperty(PROPERTY_POLICE_FORMAT_DATE)); Font fontDate = new Font( DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)), DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_DATE)), DirectoryUtils .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_DATE))); Paragraph paragraphDate = new Paragraph( new Phrase(monthDayYearformatter.format(record.getDateCreation()).toString(), fontDate)); paragraphDate.setAlignment(DirectoryUtils .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_ALIGN_DATE))); try { document.add(paragraphDate); } catch (DocumentException e) { AppLogService.error(e); } } Image image; try { image = Image.getInstance(ImageIO.read(new File(AppPathService .getAbsolutePathFromRelativePath(AppPropertiesService.getProperty(PROPERTY_IMAGE_URL)))), null); image.setAlignment( DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_IMAGE_ALIGN))); float fitWidth; float fitHeight; try { fitWidth = Float.parseFloat(AppPropertiesService.getProperty(PROPERTY_IMAGE_FITWIDTH)); fitHeight = Float.parseFloat(AppPropertiesService.getProperty(PROPERTY_IMAGE_FITHEIGHT)); } catch (NumberFormatException e) { fitWidth = 100f; fitHeight = 100f; } image.scaleToFit(fitWidth, fitHeight); try { document.add(image); } catch (DocumentException e) { AppLogService.error(e); } } catch (BadElementException e) { AppLogService.error(e); } catch (MalformedURLException e) { AppLogService.error(e); } catch (IOException e) { AppLogService.error(e); } directory.getTitle(); Font fontTitle = new Font( DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)), DirectoryUtils .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_TITLE_DIRECTORY)), DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_TITLE_DIRECTORY))); fontTitle.isUnderlined(); Paragraph paragraphHeader = new Paragraph(new Phrase(directory.getTitle(), fontTitle)); paragraphHeader.setAlignment(Element.ALIGN_CENTER); paragraphHeader.setSpacingBefore(DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_SPACING_BEFORE_TITLE_DIRECTORY))); paragraphHeader.setSpacingAfter(DirectoryUtils.convertStringToInt( AppPropertiesService.getProperty(PROPERTY_POLICE_SPACING_AFTER_TITLE_DIRECTORY))); try { document.add(paragraphHeader); } catch (DocumentException e) { AppLogService.error(e); } builderPDFWithEntry(document, plugin, nIdRecord, listEntry, listIdEntryConfig, locale, bExtractNotFilledField); document.close(); }
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 a v a 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: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 {//w w w .j a v a2 s . c o 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:managedbean.afos.FlightDutyBacking.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();//from w ww . ja v a2 s . co m pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "logo.png"; Image logoImg = Image.getInstance(logo); logoImg.scalePercent(20f); SimpleDateFormat sdf = new SimpleDateFormat("E, dd/MM/yyyy 'at' hh:mm:ss a"); Font titleFont = new Font(); Font subtitleFont = new Font(); titleFont.setSize(16); titleFont.setStyle(Font.BOLD); subtitleFont.setSize(12); subtitleFont.setStyle(Font.BOLD); Paragraph title = new Paragraph(flightReport.getType() + " Duty Report", titleFont); title.setAlignment(Element.ALIGN_CENTER); title.setSpacingAfter(12f); Paragraph subTitle1 = new Paragraph("Flight Information:", subtitleFont); subTitle1.setSpacingAfter(8f); Paragraph subTitle2 = new Paragraph(flightReport.getType() + " Checklist:", subtitleFont); subTitle2.setSpacingBefore(12f); subTitle2.setSpacingAfter(12f); com.lowagie.text.List list = new com.lowagie.text.List(true, 15); list.setLettered(true); list.add("Flight: " + selectedFlightSchedule.getFlight().getFlightNo()); list.add("Return Flight: " + selectedFlightSchedule.getFlight().getReturnedFlight().getFlightNo()); Airport departure, arrival; departure = selectedFlightSchedule.getLeg().getDepartAirport(); arrival = selectedFlightSchedule.getLeg().getArrivalAirport(); sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(departure))); list.add("Departure Time: " + sdf.format(selectedFlightSchedule.getDepartDate()) + " (" + departure.getCity().getCityName() + " Time)"); sdf.setTimeZone(TimeZone.getTimeZone(getTimeZone(arrival))); list.add("Arrival Time: " + sdf.format(selectedFlightSchedule.getArrivalDate()) + " (" + arrival.getCity().getCityName() + " Time)"); list.add("Origin: " + departure.getCity().getCityName() + " (" + departure.getAirportName() + ")"); list.add("Destination: " + arrival.getCity().getCityName() + " (" + arrival.getAirportName() + ")"); pdf.add(logoImg); pdf.add(new Paragraph(" ")); pdf.add(title); pdf.add(subTitle1); pdf.add(list); pdf.add(subTitle2); pdf.setMargins(72, 72, 72, 72); pdf.addAuthor("Merlion Airline"); pdf.addCreationDate(); sdf.applyPattern("dd/MM/yyyy_hh:mm:ss"); pdf.addTitle("Post-Flight Duty Report_" + selectedFlightSchedule.getFlight().getFlightNo() + "_" + sdf.format(selectedFlightSchedule.getDepartDate())); }
From source file:net.bull.javamelody.internal.web.pdf.PdfDocumentFactory.java
License:Apache License
Element createParagraphElement(String paragraphTitle, String iconName) throws DocumentException, IOException { final Paragraph paragraph = new Paragraph("", paragraphTitleFont); paragraph.setSpacingBefore(5);//ww w.j av a 2s . c o m paragraph.setSpacingAfter(5); if (iconName != null) { paragraph.add(new Chunk(getParagraphImage(iconName), 0, -5)); } final Phrase element = new Phrase(' ' + paragraphTitle, paragraphTitleFont); element.setLeading(12); paragraph.add(element); // chapter pour avoir la liste des signets final ChapterAutoNumber chapter = new ChapterAutoNumber(paragraph); // sans numro de chapitre chapter.setNumberDepth(0); chapter.setBookmarkOpen(false); chapter.setTriggerNewPage(false); return chapter; }
From source file:net.nosleep.superanalyzer.Share.java
License:Open Source License
public static void saveAnalysisPdf(JFrame window, Analysis analysis, JProgressBar progressBar) { File pdfFile = askForFile(window, "pdf"); if (pdfFile == null) return;// w w w . j av a2 s .co m Misc.printMemoryInfo("pdfstart"); DateFormat dateFormat = new SimpleDateFormat().getDateInstance(DateFormat.SHORT); String infoString = Misc.getString("CREATED_ON") + " " + dateFormat.format(Calendar.getInstance().getTime()); int viewCount = 15; int viewsDone = 0; progressBar.setMinimum(0); progressBar.setMaximum(viewCount); Dimension d = new Dimension(500, 400); try { String tmpPath = System.getProperty("java.io.tmpdir") + "/image.png"; // create the pdf document object Document document = new Document(); // create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileOutputStream(pdfFile)); // we open the document document.open(); Font titleFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.NORMAL, new Color(0x00, 0x00, 0x00)); Paragraph p = new Paragraph(Misc.getString("MY_MUSIC_COLLECTION"), titleFont); p.setSpacingAfter(4); document.add(p); Font subtitleFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x88, 0x88, 0x88)); p = new Paragraph("The Super Analyzer by Nosleep Software", subtitleFont); p.setSpacingAfter(-2); document.add(p); p = new Paragraph(infoString, subtitleFont); p.setSpacingAfter(30); document.add(p); PdfPTable table = new PdfPTable(2); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table.setTotalWidth(500f); table.setLockedWidth(true); Font statNameFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x66, 0x66, 0x66)); Font statValueFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x00, 0x00, 0x00)); Vector<StringTriple> statPairs = SummaryView.createStatPairs(analysis); Paragraph statParagraph = new Paragraph(); Font summaryTitleFont = FontFactory.getFont(FontFactory.HELVETICA, 11, Font.BOLD, new Color(0x00, 0x00, 0x00)); Paragraph titleParagraph = new Paragraph(Misc.getString("SUMMARY"), summaryTitleFont); statParagraph.add(titleParagraph); Paragraph spaceParagraph = new Paragraph("", statNameFont); statParagraph.add(spaceParagraph); for (int i = 0; i < statPairs.size(); i++) { Paragraph statLine = new Paragraph(); StringTriple triple = statPairs.elementAt(i); Phrase namePhrase = new Phrase(triple.Name + ": ", statNameFont); Phrase valuePhrase = new Phrase(triple.Value, statValueFont); statLine.add(namePhrase); statLine.add(valuePhrase); statParagraph.add(statLine); } table.addCell(statParagraph); viewsDone++; progressBar.setValue(viewsDone); GenreView genreView = new GenreView(analysis); genreView.saveImage(new File(tmpPath), d); genreView = null; Image img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); LikesView likesView = new LikesView(analysis); likesView.saveImage(new File(tmpPath), d); likesView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); YearView yearView = new YearView(analysis); yearView.saveImage(new File(tmpPath), d); yearView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); RatingView ratingView = new RatingView(analysis); ratingView.saveImage(new File(tmpPath), d); ratingView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); TimeView timeView = new TimeView(analysis); timeView.saveImage(new File(tmpPath), d); timeView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); QualityView qualityView = new QualityView(analysis); qualityView.saveImage(new File(tmpPath), d); qualityView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); PlayCountView playCountView = new PlayCountView(analysis); playCountView.saveImage(new File(tmpPath), d); playCountView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); MostPlayedAAView mostPlayedAAView = new MostPlayedAAView(analysis); mostPlayedAAView.saveImage(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedAAView.saveImageExtra(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedAAView = null; viewsDone++; progressBar.setValue(viewsDone); MostPlayedDGView mostPlayedDGView = new MostPlayedDGView(analysis); mostPlayedDGView.saveImage(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedDGView.saveImageExtra(new File(tmpPath), d); img = Image.getInstance(tmpPath); table.addCell(img); mostPlayedDGView = null; viewsDone++; progressBar.setValue(viewsDone); EncodingKindView encodingKindView = new EncodingKindView(analysis); encodingKindView.saveImage(new File(tmpPath), d); encodingKindView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); GrowthView growthView = new GrowthView(analysis); growthView.saveImage(new File(tmpPath), d); growthView = null; img = Image.getInstance(tmpPath); table.addCell(img); viewsDone++; progressBar.setValue(viewsDone); WordView wordView = new WordView(analysis); wordView.saveImage(new File(tmpPath), d); wordView = null; img = Image.getInstance(tmpPath); table.addCell(img); table.addCell(""); viewsDone++; progressBar.setValue(viewsDone); Misc.printMemoryInfo("pdfend"); document.add(table); // step 5: we close the document document.close(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }
From source file:net.nosleep.superanalyzer.Share.java
License:Open Source License
public static void saveListOfAlbumsAsPdf(JFrame window, Analysis analysis, JProgressBar progressBar) { File file = askForFile(window, "pdf"); if (file == null) return;//from ww w . ja v a 2s. co m Hashtable albums = analysis.getHash(Analysis.KIND_ALBUM); DecimalFormat timeFormat = new DecimalFormat("0.0"); StringPair list[] = new StringPair[albums.size()]; Enumeration keys = albums.keys(); Integer index = 0; String regex = Album.SeparatorRegEx; while (keys.hasMoreElements()) { String albumartist = (String) keys.nextElement(); String[] parts = albumartist.split(regex); StringPair pair = new StringPair(parts[1], parts[0]); list[index] = pair; index++; } Arrays.sort(list, new StringPairComparator()); int done = 0; progressBar.setMinimum(0); progressBar.setMaximum(list.length); String infoString = NumberFormat.getInstance().format(list.length) + " "; if (list.length == 1) infoString += Misc.getString("ALBUM") + ", "; else infoString += Misc.getString("ALBUMS") + ", "; DateFormat dateFormat = new SimpleDateFormat().getDateInstance(DateFormat.SHORT); infoString += "created on " + dateFormat.format(Calendar.getInstance().getTime()); try { String tmpPath = System.getProperty("java.io.tmpdir") + "/image.png"; // create the pdf document object Document document = new Document(); // create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileOutputStream(file)); // we open the document document.open(); Font titleFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.NORMAL, new Color(0x00, 0x00, 0x00)); Paragraph p = new Paragraph(Misc.getString("MY_ALBUMS"), titleFont); p.setSpacingAfter(4); document.add(p); Font subtitleFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, new Color(0x88, 0x88, 0x88)); p = new Paragraph("The Super Analyzer by Nosleep Software", subtitleFont); p.setSpacingAfter(-2); document.add(p); p = new Paragraph(infoString, subtitleFont); p.setSpacingAfter(30); document.add(p); FontSelector albumSelector = new FontSelector(); Color albumColor = new Color(0x55, 0x55, 0x55); albumSelector.addFont(FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, albumColor)); Font albumAsianFont = FontFactory.getFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED); albumAsianFont.setSize(8); albumAsianFont.setColor(albumColor); albumSelector.addFont(albumAsianFont); FontSelector artistSelector = new FontSelector(); Color artistColor = new Color(0x77, 0x77, 0x77); artistSelector.addFont(FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, artistColor)); Font artistAsianFont = FontFactory.getFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED); artistAsianFont.setSize(8); artistAsianFont.setColor(artistColor); artistSelector.addFont(artistAsianFont); for (index = 0; index < list.length; index++) { p = new Paragraph(); p.setLeading(9); // separate the string into the album and artist parts Phrase phrase = albumSelector.process(list[index].Value); p.add(phrase); phrase = artistSelector.process(" " + Misc.getString("BY") + " " + list[index].Name); p.add(phrase); document.add(p); done++; progressBar.setValue(done); } // step 5: we close the document document.close(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }
From source file:net.scs.reader.virtualprinter.PdfPrinter.java
License:Open Source License
private void printCurrentPage() { // first create a new page pdfdoc.newPage();//from ww w.j a v a2s . c o m pdfdoc.setPageCount(currentPage++); boolean emptypage = true; // second write the content for (VirtualLine currentLine : getLinesOnCurrentPage()) { emptypage = false; Paragraph p = new Paragraph(); p.setSpacingAfter(0.0f); p.setSpacingBefore(0.0f); p.setExtraParagraphSpace(0.0f); p.setLeading(leading); currentLine.position(0); StringBuilder sb = new StringBuilder(); boolean isbold = false; if (!currentLine.hasNext()) { // empty lines need at least one character sb.append(printerConfig.NL); } while (currentLine.hasNext()) { final EnhancedCharacter echar = currentLine.next(); // Workaround, replace 'normal spaces' with 'non-breaking-spaces' // <a href="http://sourceforge.net/tracker/?func=detail&aid=2866002&group_id=15255&atid=315255"> // Multiline paragraph, leading spaces are ignored problem - ID: 2866002 // </a> char c = (echar.getChar() == SP) ? NBSP : echar.getChar(); if (isbold == echar.isBold()) { sb.append(c); } else { p.add(new Chunk(sb.toString(), (isbold) ? fontbold : font)); sb = new StringBuilder(); sb.append(c); isbold = !isbold; // flip it } } p.add(new Chunk(sb.toString(), (isbold) ? fontbold : font)); try { pdfdoc.add(p); } catch (DocumentException e) { // transform into RuntimeException throw new RuntimeException(e); } } if (emptypage) { try { pdfdoc.add(new Paragraph(Character.toString(NBSP))); } catch (DocumentException e) { // transform into RuntimeException throw new RuntimeException(e); } } }