Linuxでの環境の違いによるPDF化の問題について

1,152 views
Skip to first unread message

ui-tarou

unread,
Jun 11, 2021, 5:04:23 AM6/11/21
to excella
お世話になっております。

Excella PDF化処理についてご質問させて頂きます。

[旧環境→Excel〇、PDF〇]
OS:CentOS release 6.4(64bit)
Java:1.6.0.31
Tomcat:6.0.32
OpenOffice:3.2.1
excella-core-1.8.jar
excella-reports-1.6.jar
jodconverter-core-3.0-beta-4.jar

この環境下で正常にExcel出力、PDF出力が行えていた処理があります。
処理内容を変えずに以下の環境に移したところ、Excelは出力可能ですが、
PDFが出力出来ないと言う状況になりました。

[新環境→Excel〇、PDF×]
OS:CentOS release 8(64bit)
Java:1.8.0.202
Tomcat:8.0.53
OpenOffice:3.2.1
excella-core-1.8.jar
excella-reports-1.6.jar
jodconverter-core-3.0-beta-4.jar

[エラー内容]
org.artofsolving.jodconverter.office.OfficeException: failed to start and connect
    at org.artofsolving.jodconverter.office.ManagedOfficeProcess.startAndWait(ManagedOfficeProcess.java:64)
    at org.artofsolving.jodconverter.office.PooledOfficeManager.start(PooledOfficeManager.java:101)
    at org.artofsolving.jodconverter.office.ProcessPoolOfficeManager.start(ProcessPoolOfficeManager.java:62)
    at org.bbreak.excella.reports.exporter.OoPdfExporter.output(OoPdfExporter.java:138)
    at org.bbreak.excella.reports.exporter.OoPdfOutputStreamExporter.output(OoPdfOutputStreamExporter.java:104)
    at org.bbreak.excella.reports.exporter.ReportBookExporter.export(ReportBookExporter.java:96)
    at org.bbreak.excella.reports.processor.ReportProcessor.processBook(ReportProcessor.java:207)
    at org.bbreak.excella.reports.processor.ReportProcessor.process(ReportProcessor.java:110)
        ~中略~
Caused by: java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError: org.hyperic.sigar.ptql.SigarProcessQuery.create(Ljava/lang/String;)V
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at org.artofsolving.jodconverter.office.ManagedOfficeProcess.startAndWait(ManagedOfficeProcess.java:62)
    ... 37 more
Caused by: java.lang.UnsatisfiedLinkError: org.hyperic.sigar.ptql.SigarProcessQuery.create(Ljava/lang/String;)V
    at org.hyperic.sigar.ptql.SigarProcessQuery.create(Native Method)
    at org.hyperic.sigar.ptql.ProcessQueryFactory.getQuery(ProcessQueryFactory.java:66)
    at org.hyperic.sigar.ptql.ProcessFinder.find(ProcessFinder.java:68)
    at org.hyperic.sigar.ptql.ProcessFinder.find(ProcessFinder.java:56)
    at org.artofsolving.jodconverter.process.SigarProcessManager.findPid(SigarProcessManager.java:42)
    at org.artofsolving.jodconverter.office.OfficeProcess.start(OfficeProcess.java:65)
    at org.artofsolving.jodconverter.office.OfficeProcess.start(OfficeProcess.java:60)
    at org.artofsolving.jodconverter.office.ManagedOfficeProcess.doStartProcessAndConnect(ManagedOfficeProcess.java:119)
    at org.artofsolving.jodconverter.office.ManagedOfficeProcess.access$000(ManagedOfficeProcess.java:31)
    at org.artofsolving.jodconverter.office.ManagedOfficeProcess$1.run(ManagedOfficeProcess.java:58)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    ... 1 more

[処理内容]
    try {
//        System.setProperty("java.io.tmpdir", "/usr/local/tomcat/temp");
//        System.setProperty("office.home", "/opt/openoffice.org3");

        String s出力Excelファイル名 = "Output.xls";
        String sテンプレートパス = "template.xls";
        String templateFilePath = URLDecoder.decode( sテンプレートパス, "UTF-8");

        ReportBook outputBook = null;
        if(bPDF出力){
            //PDFで出力
            outputBook = new ReportBook( templateFilePath, null, OoPdfOutputStreamExporter.FORMAT_TYPE);
        } else {
            //Excelで出力
            outputBook = new ReportBook( templateFilePath, null, ExcelOutputStreamExporter.FORMAT_TYPE);
        }

        // テンプレートファイル内のシート名と出力シート名を指定し、
        // ReportSheetインスタンスを生成して、ReportBookに追加します。
        //
        ReportSheet outputSheet = null;
        outputSheet = new ReportSheet( "XXXXXX","XXXXXXX");

        outputBook.addReportSheet(outputSheet);

        List<ParamInfo> pageInfos = new ArrayList<ParamInfo>();
        ParamInfo pageInfo = null;

        pageInfo = new ParamInfo();

        pageInfo.addParam( SingleParamParser.DEFAULT_TAG, "提出日", "yyyy/MM/dd");

        ~中略~

        pageInfos.add(pageInfo);
        ParamInfo[] allPageInfos = pageInfos.toArray( new ParamInfo[pageInfos.size()]);

        outputSheet.addParam( BlockRowRepeatParamParser.DEFAULT_TAG, "ページ", allPageInfos);

        // レスポンス設定
        if(bPDF出力){
            response.setContentType("application/pdf");
        } else {
            response.setContentType("application/vnd.ms-excel");
        }
        funcダウンロード用_レスポンスヘッダ設定();

        ReportProcessor reportProcessor = new ReportProcessor();
        if(bPDF出力){
            reportProcessor.addReportBookExporter( new OoPdfOutputStreamExporter( outStream));
        } else {
            reportProcessor.addReportBookExporter( new ExcelOutputStreamExporter( outStream));
        }
        synchronized(oOOfficeLock) {
            reportProcessor.process( outputBook);
        }
    } catch (java.sql.SQLException se){
        StMsg.makeMsg("データ検索時にエラーが発生しました。", getClass().getName());
        log4j.error(StMsg.getMsgLog4J(),se);
        return false;
    } finally {
    }

[試したこと]
    1)OpenOfficeの再インストール、OpenのOffice.homeの明示的指定
        【結果】
            状況変化なし。
    2)以下の処理でJodConveterを単独起動
        【処理内容】
            OfficeManager officeManager = LocalOfficeManager.make();
            DocumentConverter converter = LocalConverter.make(officeManager);
            try {
                officeManager.start();

                File inputFile = new File("template/test.xls");
                File outputFile = new File("pdf/test.pdf");
                // Convert...
                converter.convert(inputFile).to(outputFile).execute();
            } catch(OfficeException oe) {
                log4j.error("pdfError",oe);
            } finally {
                officeManager.stop();
            }
        【結果】
            正常にPDF化実施完了。

    3)Excella環境を以下のバージョンに換装
        excella-core-2.0.jar
        excella-pdfexporter-2.0.jar
        excella-reports-2.0.jar
        jodconverter-core-4.2.2.jar
        jodconverter-local-4.2.2.jar
    【結果】
        Excelは正常に出力可能。
        PDFの出力は以下のエラーが発生。

[エラー内容]
org.bbreak.excella.core.exception.ExportException: org.jodconverter.office.OfficeException: Task failed
    at org.bbreak.excella.reports.exporter.OoPdfExporter.output(OoPdfExporter.java:158)
    at org.bbreak.excella.reports.exporter.OoPdfOutputStreamExporter.output(OoPdfOutputStreamExporter.java:103)
    at org.bbreak.excella.reports.exporter.ReportBookExporter.export(ReportBookExporter.java:89)
    at org.bbreak.excella.reports.processor.ReportProcessor.processBook(ReportProcessor.java:203)
    at org.bbreak.excella.reports.processor.ReportProcessor.process(ReportProcessor.java:105)
    at xxxxxx.ns_excel.ucExcel_XXXXXX.outExcel(ucExcel_XXXXXX.java:434)
        ~中略~
Caused by: org.jodconverter.office.OfficeException: Task failed
    at org.jodconverter.office.AbstractOfficeManagerPoolEntry.execute(AbstractOfficeManagerPoolEntry.java:106)
    at org.jodconverter.office.AbstractOfficeManagerPool.execute(AbstractOfficeManagerPool.java:84)
    at org.jodconverter.office.LocalOfficeManager.execute(LocalOfficeManager.java:38)
    at org.jodconverter.LocalConverter$LocalConversionJob.doExecute(LocalConverter.java:189)
    at org.jodconverter.job.AbstractConversionJob.execute(AbstractConversionJob.java:57)
    at org.bbreak.excella.reports.exporter.OoPdfExporter.output(OoPdfExporter.java:155)
    ... 34 more
Caused by: java.util.concurrent.CancellationException
    at java.util.concurrent.FutureTask.report(FutureTask.java:121)
    at java.util.concurrent.FutureTask.get(FutureTask.java:206)
    at org.jodconverter.office.AbstractOfficeManagerPoolEntry.execute(AbstractOfficeManagerPoolEntry.java:86)
    ... 39 more

以上、なにかヒントがあればご教授頂けませんでしょうか。

丸山貴之

unread,
Jun 11, 2021, 5:27:56 PM6/11/21
to excella
丸山です。

java.lang.UnsatisfiedLinkError はnativeメソッドの実装が見つからない場合にスローされるErrorですね。
jodconverterの SigarProcessManagerのソースを見たところ、

* Requires the sigar.jar in the classpath and the appropriate system-specific

* native library (e.g. <tt>libsigar-x86-linux.so</tt> on Linux x86) available

* in the <em>java.library.path</em>.

とありますので、新環境にはnative libraryが不足しているのかと思います。

>     3)Excella環境を以下のバージョンに換装
>     【結果】
>         Excelは正常に出力可能。
>         PDFの出力は以下のエラーが発生。
CancellationExceptionなのでOpenOfficeがクラッシュしているかもしれません。
「 OpenOffice:3.2.1」ということはOpenOffice.orgですよね?
ExCella(JODConverter)のバージョンを上げるのであれば、LibreOfficeかApache OpenOfficeの
可能な限り新しいバージョンを使用することもご検討下さい。

2021年6月11日金曜日 18:04:23 UTC+9 ui-tarou:
Message has been deleted

ui-tarou

unread,
Jun 14, 2021, 3:18:12 AM6/14/21
to excella
ご返答ありがとうございます。
情報、大変助かります。

1)  >とありますので、新環境にはnative libraryが不足しているのかと思います。

「/usr/lib64」配下に
   libsigar-x86-linux.so
   libsigar-amd64-linux.so
の二つを設置してみました。

2)   >CancellationExceptionなのでOpenOfficeがクラッシュしているかもしれません。
 OpenOffice.org 3.2.1→Apache OpenOffice 4.1.10
にインストールし直しました。

これにより、現状下記のような環境となっております。
 OS:CentOS release 8(64bit)
 Java:1.8.0.202
 Tomcat:8.0.53
 OpenOffice:4.2.10
 excella-core-2.0.jar
    excella-pdfexporter-2.0.jar
 excella-reports-2.0.jar
    jodconverter-core-4.2.2.jar
    jodconverter-local-4.2.2.jar

上記2点を試してみたところ、やはり Excel=〇、PDF=×と言う状況に変わりはないものの
エラーの内容が下記に変わりました。

[エラー内容]
org.bbreak.excella.core.exception.ExportException: org.jodconverter.office.OfficeException: Could not store document: nulltmp.pdf; errorCode: 283

    at org.bbreak.excella.reports.exporter.OoPdfExporter.output(OoPdfExporter.java:158)
    at org.bbreak.excella.reports.exporter.OoPdfOutputStreamExporter.output(OoPdfOutputStreamExporter.java:103)
    at org.bbreak.excella.reports.exporter.ReportBookExporter.export(ReportBookExporter.java:89)
    at org.bbreak.excella.reports.processor.ReportProcessor.processBook(ReportProcessor.java:203)
    at org.bbreak.excella.reports.processor.ReportProcessor.process(ReportProcessor.java:105)
    at xxxxx.ns_excel.ucExcel_XXXXX.outExcel(ucExcel_XXXXX.java:434)
    at xxxxx.ajax.SvExcelManager.service(SvExcelManager.java:712)

以前と変わらず、 JodConveterによるPDF化は正常に成功しております。

  【処理内容】
            OfficeManager officeManager = LocalOfficeManager.make();
            DocumentConverter converter = LocalConverter.make(officeManager);
            try {
                officeManager.start();

                File inputFile = new File("template/test.xls");
                File outputFile = new File("pdf/test.pdf");
                // Convert...
                converter.convert(inputFile).to(outputFile).execute();
            } catch(OfficeException oe) {
                log4j.error("pdfError",oe);
            } finally {
                officeManager.stop();
            }


御面倒かとは思いますが、以上ご教授お願いいたします。

2021年6月12日土曜日 6:27:56 UTC+9 bis5...@gmail.com:

丸山貴之

unread,
Jul 11, 2021, 4:03:11 AM7/11/21
to excella
丸山です。

遅くなりましたが、簡単に検証してみました。

を利用して、以下の環境でApache OpenOffice 4.1.10 または LibreOffice 6.4.7.2を使用して試しましたが、いずれも例外は発生せず正常に出力されました。

【環境】
Ubuntu 20.04, excella-reports-2.0, excella-pdfexporter-2.0, AdoptOpenJDK 8u265

【(参考) 確認に使用した出力処理】
        ReportProcessor reportProcessor = new ReportProcessor();
        OfficeManager officeManager = LocalOfficeManager.make();
        officeManager.start();
        try ( OutputStream out = Files.newOutputStream(Paths.get("/tmp/output.pdf"), StandardOpenOption.TRUNCATE_EXISTING)) {
            reportProcessor.addReportBookExporter( new OoPdfOutputStreamExporter(officeManager, out));
            reportProcessor.process( outputBook);
        } finally {
            officeManager.stop();
        }

> Could not store document: nulltmp.pdf; errorCode: 283
このエラーコードはOpenOffice側の物ですから、OpenOffice側について調べてみてはいかがでしょう?

2021年6月14日月曜日 16:18:12 UTC+9 ui-tarou:
Reply all
Reply to author
Forward
0 new messages