1

I am using PDFBox to create PDFs and that is working great. I also have a need to create PostScript files which I would like to generate from the PDF I create. I am using the following code to have PDFBox work with SimpleDoc to create the PostScript file. That is working but the file is massive. A 30KB PDF produces a 2meg PostScript file. What do I need to change to create a reasonably sized PostScript file?

    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(MediaSizeName.NA_LETTER);

    FileOutputStream fos = new FileOutputStream(filePathAndName);
    Map<Integer, String> pageLayoutMap = pdfGenerator.getPageLayoutMap();
    for (int i = 1; i <= document.getNumberOfPages(); i++) {
        aset.add(new PageRanges(i, i));
        if (pageLayoutMap.get(i).equals(PDFGenerator.ORIENTATION_LANDSCAPE)) {
            aset.add(OrientationRequested.LANDSCAPE);
        } else {
            aset.add(OrientationRequested.PORTRAIT);
        }
        StreamPrintService sps = factories[0].getPrintService(fos);
        DocPrintJob dpj = sps.createPrintJob();
        SimpleDoc sd = new SimpleDoc(new PDFPrintable(document, Scaling.ACTUAL_SIZE, false), flavor, null);
        factories[0].getPrintService(fos).createPrintJob().print(
                new SimpleDoc(new PDFPrintable(document, Scaling.ACTUAL_SIZE, false), flavor, daset), aset);
    }
    fos.close();
    document.close();

Thank you

  • it could be the difference between the PDF containing text, and the postscript being a PICTURE of text... – Marc B Aug 23 '16 at 20:09
  • 1
    Yes, good point. We have a legacy tool that does this with windows components that we are trying to get away from. I took the postscript file from it and had Adobe make a PDF out of it, then I fed the PDF through this and the postscript file was originally 163kb, this logic generated a postscript file of 3142kb. I don't understand the file size difference. – user3991484 Aug 23 '16 at 21:06
  • well, go look inside the postscript file. if the pdf was converted text->text, then your text should be visible in the .ps somewhere. if all you see is a bunch of garbage, then your .ps is a picture of text, and the size will naturally drastically balloon upwwards. – Marc B Aug 23 '16 at 21:08
  • Postscript files are always bloated. PDFBox makes it even worse because glyphs are converted into vector graphics when rendering, because awt does not always render fonts properly. – Tilman Hausherr Aug 24 '16 at 05:18
  • PostScript files are not 'always bloated', In general its possible to create a sensibly sized PostScript output from a PDF file. However..... You need to bear in mind that the graphics models of the two are not the same. If the PDF contains transparency then that cannot be represented in PostScript and so the PDF must be rendered to an image format, and the image wrapped up instead. As the resolution of the rendering increases, so does the size. Without seeing the original PDF and the PDFBox PostScript output I can't say why the problem exists. You could try Ghostscript instead. – KenS Aug 24 '16 at 07:46

0 Answers0