Printing to PostScript with PDFBox produces a massive file, why?

蹲街弑〆低调 提交于 2019-12-12 03:48:42

问题


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

来源:https://stackoverflow.com/questions/39109841/printing-to-postscript-with-pdfbox-produces-a-massive-file-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!