我正在尝试替换我们在公司中使用的PDF转换器,但我遇到了Ghost4J的这个问题。请注意,我的代码与他们提供的示例非常相似......
我正在使用Java SE 1.6(jrockit-jre1.6.0_33-R28.2.4)和Ghostscript 9.10 for Win 64位。
我的代码是:
public void convertPostScriptToPDF() {
File file= new File (this.getClass().getResource( "/resources/employer_report_last_page.ps").getFile());
FileOutputStream fos = null;
try{
//load PostScript document
PSDocument document = new PSDocument();
document.load(file);
fos = new FileOutputStream(new File("rendition.pdf"));
//create converter
PDFConverter converter = new PDFConverter();
//set options
converter.setPDFSettings(PDFConverter.OPTION_PDFSETTINGS_PREPRESS);
//convert
converter.convert(document, fos);
} catch (Exception e) {
System.out.println("ERROR: " + e.getMessage());
} finally{
IOUtils.closeQuietly(fos);
}
}
JVM崩溃,发生在“converter.convert(document,fos);”在转储文件上显示消息:
Error Message: Illegal memory access. [54]
Exception Rec: EXCEPTION_ACCESS_VIOLATION (00000000c0000005) at 0x0000000067ECE347 - memory at 0xFFFFFFFFFFFFFFFF could not be read.
Minidump : Wrote mdmp. Size is 650MB
SafeDllMode : -1
Version : Oracle JRockit(R) R28.2.4-14-151097-1.6.0_33-20120618-1634-windows-x86_64
CPU : Intel SSE SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 Intel64**strong text**
Number CPUs : 4
Tot Phys Mem : 4110749696 (3920 MB)
OS version : Microsoft Windows 7 version 6.1 Service Pack 1 (Build 7601) (64-bit)
Thread System: Windows Threads
Java locking : Lazy unlocking enabled (class banning) (transfer banning)
State : JVM is running
Command Line : -Xms=512m -Xmx=512m -Dfile.encoding=Cp1252 -Dsun.java.command=org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 57292 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -test au.edu.nsw.det.reportgenerator.business.ReportManagerTest:convertPostScriptToPDF -Dsun.java.launcher=SUN_STANDARD org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 57292 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -test au.edu.nsw.det.reportgenerator.business.ReportManagerTest:convertPostScriptToPDF
Repository :
java.home : C:\Program Files\Java\jrockit-jre1.6.0_33-R28.2.4
j.class.path : C:\EmployerReportGenerator\bin;C:\EmployerReportGenerator\lib\emp-model.jar;C:\EmployerReportGenerator\lib\ghost4j-0.5.0.jar;C:\EmployerReportGenerator\lib\commons-io-1.3.1.jar;C:\EmployerReportGenerator\lib\jna-platform-4.0.0.jar;C:\EmployerReportGenerator\lib\log4j-1.2.15.jar;C:\EmployerReportGenerator\lib\xmlgraphics-commons-1.4.jar;C:\EmployerReportGenerator\lib\commons-beanutils-1.8.3.jar;C:\EmployerReportGenerator\lib\commons-logging-1.1.1.jar;C:\EmployerReportGenerator\lib\itext-2.1.7.jar;C:\EmployerReportGenerator\lib\jna-3.3.0.jar;C:\projects\det\lib\jasperreports-1.2.8.jar;C:\projects\det\release\PDFGeneratorService-client-1.0.jar;C:\TBO\DependentJars\ojdbc14.jar;C:\oracle\oc4j10.1.3.2\j2ee\home\applib\rdbthin.jar;C:\projects\det\release\xmlCommon-1_0.jar;C:\projects\det\release\jet-3_0.jar;C:\eclipse\configuration\org.eclipse.osgi\bundles\797\1\.cp\lib\j2ee-1.3\ejb-api.jar;C:\eclipse\configuration\org.eclipse.osgi\bundles\797\1\.cp\lib\j2ee-1.3\jca-api.jar;C:\eclipse\configuration\org.eclipse.osgi\bundles\797\1\.cp\lib\j2ee-1.3\jms-api.jar;C:\eclipse\configuration\org.eclipse.osgi\bundles\797\1\.cp\lib\j2ee-1.3\jsp-api.jar;C:\eclipse\configuration\org.eclipse.osgi\bundles\797\1\.cp\lib\j2ee-1.3\jta-api.jar;C:\eclipse\configuration\org.eclipse.osgi\bundles\797\1\.cp\lib\j2ee-1.3\servlet-api.jar;C:\eclipse\configuration\org.eclipse.osgi\bundles\797\1\.cp\lib\j2ee-1.3\sql-api.jar;C:\eclipse\plugins\org.junit_4.10.0.v4_10_0_v20120426-0900\junit.jar;C:\eclipse\plugins\org.hamcrest.core_1.1.0.v20090501071000.jar;C:\projects\det\lib\commons-logging-1.1.jar;/C:/eclipse/configuration/org.eclipse.osgi/bundles/346/1/.cp/;/C:/eclipse/configuration/org.eclipse.osgi/bundles/979/1/.cp/
j.lib.path : C:\Program Files\Java\jrockit-jre1.6.0_33-R28.2.4\bin;C:\Windows\system32;C:\Windows;C:\app\tfirmino\product\11.2.0\client_1;C:\app\tfirmino\product\11.2.0\client_1\bin;C:\oracle\product\10.2.0\client_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Common Files\GTK\2.0\bin;C:\Program Files (x86)\cvsnt;C:\Program Files\Internet Explorer;C:\Program Files (x86)\SSH Communications Security\SSH Secure Shell;C:\Program Files\SlikSvn\bin;C:\Program Files (x86)\Sybase\Shared\PowerBuilder\;C:\Program Files (x86)\SSH Communications Security\SSH Secure Shell;C:\Users\thais.firmino\Application Data\SSH\UserKeys;C:\Python27;C:\Program Files\apache-maven-3.0.5\bin;C:\Program Files\Java\jdk1.7.0_17\bin;;.
JAVA_HOME : C:\Program Files\Java\jdk1.7.0_17\
_JAVA_OPTIONS: <not set>
PATH : C:\app\tfirmino\product\11.2.0\client_1;C:\app\tfirmino\product\11.2.0\client_1\bin;C:\oracle\product\10.2.0\client_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Common Files\GTK\2.0\bin;C:\Program Files (x86)\cvsnt;C:\Program Files\Internet Explorer;C:\Program Files (x86)\SSH Communications Security\SSH Secure Shell;C:\Program Files\SlikSvn\bin;C:\Program Files (x86)\Sybase\Shared\PowerBuilder\;C:\Program Files (x86)\SSH Communications Security\SSH Secure Shell;C:\Users\thais.firmino\Application Data\SSH\UserKeys;C:\Python27;C:\Program Files\apache-maven-3.0.5\bin;C:\Program Files\Java\jdk1.7.0_17\bin;
StackOverFlow: 0 StackOverFlowErrors have occured
OutOfMemory : 0 OutOfMemoryErrors have occured
C Heap : Good; no memory allocations have failed
GC Strategy : Mode: throughput, with strategy: genparpar (basic strategy: genparpar)
GC Status : OC is not running. Last finished OC was OC#0.
: YC is not running. Last finished YC was YC#0.
有什么想法吗? 先感谢您, 泰国人
答案 0 :(得分:1)
我的想法是,在http://www.java.com/en/download/help/exception_access.xml上提到的我的问题与Windows操作系统上的UAC有关,但是如所建议的那样改变并没有解决问题。 无论如何,通过解决方法我解决了我的问题。请参阅下文我使用核心API而不是高级API:
public void convert() {
//get Ghostscript instance
Ghostscript gs = Ghostscript.getInstance();
File file= new File (this.getClass().getResource( "/resources/employer_report_last_page2.ps").getFile());//(Config.EMP_REPORT.REPORT_LAST_PAGE_STORE_PATH);
// File file= new File (this.getClass().getResource( "/resources/Issues.ps").getFile());
//prepare Ghostscript interpreter parameters
//refer to Ghostscript documentation for parameter usage
String[] gsArgs = new String[10];
gsArgs[0] = "-ps2pdf";
gsArgs[1] = "-dNOPAUSE";
gsArgs[2] = "-dBATCH";
gsArgs[3] = "-dSAFER";
gsArgs[4] = "-sDEVICE=pdfwrite";
gsArgs[5] = "-sOutputFile=output2.pdf";//output file name
// gsArgs[5] = "-sOutputFile=" + file.getAbsolutePath();
gsArgs[6] = "-c";
gsArgs[7] = ".setpdfwrite";
gsArgs[8] = "-f";
// gsArgs[9] = "input.ps";//input file name
gsArgs[9] = file.getAbsolutePath();//input file name
//execute and exit interpreter
try {
gs.initialize(gsArgs);
gs.exit();
} catch (GhostscriptException e) {
System.out.println("ERROR: " + e.getMessage());
}
}
答案 1 :(得分:0)
public synchronized void convertPostScriptToPDF()
或
public void convertPostScriptToPDF(){ synchronized(this){ ... } }