Java 为什么我在尝试获取Pdfile实例的页面时会获得PDFParseException?

Java 为什么我在尝试获取Pdfile实例的页面时会获得PDFParseException?,java,pdf,coldfusion,pdfrenderer,pdf-rendering,Java,Pdf,Coldfusion,Pdfrenderer,Pdf Rendering,我使用版本0.9.1在ColdFusion中以编程方式将PDF转换为PNG 以下是我编写的UDF: LOCAL.DestinationFilePath= 修剪(参数.destinationPath) & "\" &REQUEST.UDFLib.File.getFileNameWithoutExtension( GetFileFromPath(ARGUMENTS.sourcePath) ) & "." &LCase(Trim(ARGUMENTS.format)); LOCAL.rando

我使用版本0.9.1在ColdFusion中以编程方式将PDF转换为PNG

以下是我编写的UDF:


LOCAL.DestinationFilePath=
修剪(参数.destinationPath)
&   "\"
&REQUEST.UDFLib.File.getFileNameWithoutExtension(
GetFileFromPath(ARGUMENTS.sourcePath)
)
&   "."
&LCase(Trim(ARGUMENTS.format));
LOCAL.random访问文件=
CreateObject(
“爪哇”,
“java.io.RandomAccessFile”
).init(
CreateObject(
“爪哇”,
“java.io.File”
).init(ARGUMENTS.sourcePath),
“r”
);
LOCAL.FileChannel=LOCAL.RandomAccessFile.getChannel();
LOCAL.PDFFile=
CreateObject(
“爪哇”,
“com.sun.pdfview.PDFFile”
).init(
LOCAL.FileChannel.map(
CreateObject(
“爪哇”,
“java.nio.channels.FileChannel$MapMode”
).只读,
0,
LOCAL.FileChannel.size()文件
)
) />
LOCAL.PDFPage=LOCAL.PDFFile.getPage(1)/>
//下一行引发异常“Element PDFPAGE在LOCAL中未定义”
LOCAL.Rectangle=LOCAL.PDFPage.getBBox();
LOCAL.buffereImage=
CreateObject(
“爪哇”,
“java.awt.image.buffereImage”
).init(
LOCAL.Rectangle.width,
LOCAL.Rectangle.height,
CreateObject(
“爪哇”,
“java.awt.image.buffereImage”
).TYPE_INT_RGB
);
LOCAL.Graphics=LOCAL.buffereImage.createGraphics();
LOCAL.Graphics.drawImage(
LOCAL.PDFPage.getImage(
LOCAL.Rectangle.width,
LOCAL.Rectangle.height,
局部矩形,
JavaCast(“null”,“null”),
是的,
真的
),
0,
0,
JavaCast(“null”,“”)
);
LOCAL.Graphics.dispose();
LOCAL.ImageFile=
CreateObject(
“爪哇”,
“java.io.File”
).init(LOCAL.DestinationFilePath);
//删除现有图像文件
if(LOCAL.ImageFile.exists())
LOCAL.ImageFile.delete();
//将图像导出为指定格式
CreateObject(
“爪哇”,
“javax.imageio.imageio”
).写(
LOCAL.buffereImage,
JavaCast(“字符串”,Trim(ARGUMENTS.format)),
LOCAL.ImageFile
);
LOCAL.RandomAccessFile.close();
返回LOCAL.DestinationFilePath;
这对大多数我扔的PDF来说都很好。但是,它偶尔会为某些PDF抛出异常(所有PDF都是适当的,不能共享)

当尝试使用
PDFFile.getPage(1)
引用PDF的第一页时,我得到一个ColdFusion异常:
元素PDFPAGE在本地未定义。

我已经通过调试器运行了这个程序,在深入检查后,我看到某个PDF的以下值:

PDFFile.getNumPages() : 0
PDFFile.getVersionString() : 1.7
PDFFile.getRoot() : 
    Indirect to #182
    Catalog dictionary. Keys:
       StructTreeRoot  Indirect to #40com.sun.pdfview.PDFParseException: Could not decrypt: Need at least 2880 bytes of space in output buffer
       Pages  Indirect to #178com.sun.pdfview.PDFParseException: Could not decrypt: Need at least 80 bytes of space in output buffer
       Type  Name: /Catalog
       ViewerPreferences  Untyped dictionary. Keys:
       Direction  Name: /L2R
       Metadata  Indirect to #23
    Caught an error: com.sun.pdfview.PDFParseException: Could not decrypt: Need at least 2672 bytes of space in output buffer
       MarkInfo  Untyped dictionary. Keys:
       Marked  Boolean: true
我不太精通Java,所以我不知道这意味着什么,但这让我相信PDF格式不正确,Java库无法正确读取


你知道到底是什么导致了这种错误吗?这可能是因为PDF是如何生成/制作的,因为它是一个与PDFRenderer库不兼容的较新版本吗?

FYI,我根据我阅读的文章和stackoverflow文章编写了这个UDF,其中有代码示例,所以我不想为代码而受到赞扬(尽管我的版本可能不是最好的)。FYI,我尝试将
CFPDF action=“thumbnail”
与引发上述异常的同一个PDF一起使用,我也收到了一个异常,因此我相信问题出在PDF上。