2

我正在尝试替换我们在公司使用的 PDF 转换器,但我遇到了 Ghost4J 的问题。请注意,我的代码与他们提供的示例非常相似......

我正在为 Win 64 位使用 Java SE 1.6 (jrockit-jre1.6.0_33-R28.2.4) 和 Ghostscript 9.10。

我的代码是:

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.        

有任何想法吗?提前谢谢你,泰国人

4

2 回答 2

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());
        }
 }
于 2013-10-16T04:58:20.390 回答
0

公共同步无效 convertPostScriptToPDF()

或者

公共无效转换PostScriptToPDF(){同步(这个){...}}

于 2015-03-25T07:29:14.967 回答