iText旋转创建显示内存不足异常的pdf

iText旋转创建显示内存不足异常的pdf,itext,Itext,下面是创建pdf文件的代码片段,在该文件中可以旋转页面。这适用于大多数pdf文件。但是1.6版的一个pdf文件页面已经旋转了180度,对其应用进一步旋转(例如90度)并保存该文件会导致其损坏。事实上,即使您不旋转文件并使用iText将其写入另一个文件,生成的pdf也会损坏,并在Adobe reader中打开时显示内存不足异常 为什么会这样?我在文件中缺少某种压缩 private String createPdfFileWithoutForms(final EditStateData[] edit

下面是创建pdf文件的代码片段,在该文件中可以旋转页面。这适用于大多数pdf文件。但是1.6版的一个pdf文件页面已经旋转了180度,对其应用进一步旋转(例如90度)并保存该文件会导致其损坏。事实上,即使您不旋转文件并使用iText将其写入另一个文件,生成的pdf也会损坏,并在Adobe reader中打开时显示内存不足异常

为什么会这样?我在文件中缺少某种压缩

private String createPdfFileWithoutForms(final EditStateData[] editStateData, final String directory)
        throws EditingException {

        Long startTime = System.currentTimeMillis();

        File pdfFileToReturn = new File(directory + File.separator + UidGenerator.generate() + ".pdf");

        com.lowagie.text.Document document = null;
        FileOutputStream outputStream = null;
        PdfCopy pdfCopy = null;
        PdfReader reader = null;
        PdfDictionary pageDict = null;
        int rotationAngle = 0;
        Map<Integer, Integer> rotationQuadrants = null;

        try {

            document = new com.lowagie.text.Document();
            outputStream = new FileOutputStream(pdfFileToReturn);
            pdfCopy = new PdfCopy(document, outputStream);
            pdfCopy.setFullCompression();
            pdfCopy.setCompressionLevel(9);
            document.open();

            for (EditStateData state : editStateData) {
                try {
                    reader = new PdfReader(state.getFileName());
                    reader.selectPages(state.getPages());
                    rotationQuadrants = state.getRotationQuadrants();
                    for (int i = 1; i <= reader.getNumberOfPages(); i++) {
                        // Rotation quadrant key is the source page number
                        if (rotationQuadrants.containsKey(state.getPages().get(i - 1))) {
                            rotationAngle = reader.getPageRotation(i);
                            pageDict = reader.getPageN(i);
                            pageDict.put(PdfName.ROTATE,
                                new PdfNumber((rotationAngle 
                                    + rotationQuadrants.get(state.getPages().get(i - 1))) % 360));
                        }

                        document.setPageSize(reader.getPageSizeWithRotation(i));
                        document.newPage();
                        // import the page from source pdf
                        PdfImportedPage page = pdfCopy.getImportedPage(reader, i);
                        // add the page to the destination pdf
                        pdfCopy.addPage(page);
                    }
                } catch (final IOException e) {
                    LOGGER.error(e.getMessage(), e);
                    throw new EditingException(e.getMessage(), e);
                } finally {
                    if (reader != null) {
                        reader.close();
                    }
                }
            }
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
            throw new EditingException(e.getMessage(), e);
        } finally {
            if (document != null) {
                document.close();
            }

            if (pdfCopy != null) {
                pdfCopy.close();
            }
            IoUtils.closeQuietly(outputStream);
        }

        LOGGER.debug("Combining " + editStateData.length + " pdf files took "
            + ((System.currentTimeMillis() - startTime) / 1000) + " msecs");

        return pdfFileToReturn.getAbsolutePath();
    }
private String createPdfFileWithoutForms(最终EditStateData[]EditStateData,最终字符串目录)
抛出编辑异常{
Long startTime=System.currentTimeMillis();
File pdfFileToReturn=新文件(directory+File.separator+uidgeGenerator.generate()+“.pdf”);
com.lowagie.text.Document Document=null;
FileOutputStream outputStream=null;
PdfCopy PdfCopy=null;
PdfReader reader=null;
PdfDictionary pageDict=null;
int rotationAngle=0;
地图旋转象限=空;
试一试{
document=new com.lowagie.text.document();
outputStream=新文件outputStream(PdfileToReturn);
pdfCopy=新的pdfCopy(文档、输出流);
pdfCopy.setFullCompression();
pdfCopy.setCompressionLevel(9);
document.open();
for(EditStateData状态:EditStateData){
试一试{
reader=newpdfreader(state.getFileName());
reader.selectPages(state.getPages());
rotationQuadrants=state.getRotationQuadrants();

对于(int i=1;我在您的代码中看到了我的名字。请理解,iText 5之前的所有版本都已弃用,因此不再受支持。请参阅您能否提供示例输出PDF,并检查该问题?