List of usage examples for com.lowagie.text.pdf PdfWriter setCompressionLevel
public void setCompressionLevel(int compressionLevel)
From source file:org.mapfish.print.MapPrinter.java
License:Open Source License
/** * Generate the PDF using the given spec. * * @return The context that was used for printing. *///from w ww .j ava 2s . c o m public RenderingContext print(PJsonObject jsonSpec, OutputStream outFile, String referer) throws DocumentException { final String layoutName = jsonSpec.getString(Constants.JSON_LAYOUT_KEY); Layout layout = config.getLayout(layoutName); if (layout == null) { throw new RuntimeException("Unknown layout '" + layoutName + "'"); } Document doc = new Document(layout.getFirstPageSize(null, jsonSpec)); PdfWriter writer = PdfWriter.getInstance(doc, outFile); if (!layout.isSupportLegacyReader()) { writer.setFullCompression(); writer.setPdfVersion(PdfWriter.PDF_VERSION_1_5); writer.setCompressionLevel(PdfStream.BEST_COMPRESSION); } RenderingContext context = new RenderingContext(doc, writer, config, jsonSpec, configDir, layout, referer); layout.render(jsonSpec, context); doc.close(); writer.close(); return context; }
From source file:org.pdfsam.console.business.pdf.handlers.interfaces.AbstractCmdExecutor.java
License:Open Source License
/** * Sets the compression settings on the pdf writer depending on the inputCommand * //from w ww . j av a 2 s .co m * @param inputCommand * @param pdfWriter */ protected void setCompressionSettingOnWriter(AbstractParsedCommand inputCommand, PdfWriter pdfWriter) { if (inputCommand.isCompress()) { pdfWriter.setFullCompression(); pdfWriter.setCompressionLevel(PdfStream.BEST_COMPRESSION); } }
From source file:questions.compression.CompressionLevelsFonts.java
public static void createPdf(int compressionLevel) { try {//from w ww . ja v a 2 s. c o m Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT[compressionLevel + 1])); writer.setCompressionLevel(compressionLevel); document.open(); BaseFont bf = BaseFont.createFont(RESOURCE, BaseFont.WINANSI, BaseFont.EMBEDDED); bf.setCompressionLevel(compressionLevel); Font f = new Font(bf, 12); document.add(new Paragraph("0123456789", f)); document.add(new Paragraph("abcdefghijklmnopqrstuvwxyz", f)); document.add(new Paragraph("ABCDEFGHIJKLMNOPQRSTUVWXYZ", f)); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.compression.CompressionLevelsImage.java
public static void createPdf(int compressionLevel) { try {//from w w w . j a v a 2s . c om Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT[compressionLevel + 1])); writer.setCompressionLevel(compressionLevel); document.open(); Image img = Image.getInstance(RESOURCE); img.setCompressionLevel(compressionLevel); document.add(img); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.compression.CompressionLevelsWriter.java
public static void createPdf(int compressionLevel) { try {/*from www .j ava 2s . c o m*/ Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT[compressionLevel + 1])); writer.setCompressionLevel(compressionLevel); document.open(); BufferedReader reader = new BufferedReader(new FileReader(RESOURCE)); String line; Paragraph p; while ((line = reader.readLine()) != null) { p = new Paragraph(line); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.add(Chunk.NEWLINE); } reader.close(); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }