1

Jpedalツールを使用してPDFを画像に変換しています。Jpedal ツールは、任意または多数の PDF ページ (PDF ページ = 1200 としましょう) を .PNG 画像に変換するのに役立ちます。通常、これは機能していますが、これらの多数の PDF ページを画像に変換しているときに、Tomcat が予期せず停止することがあります。

public boolean createPDF2ImageTask(String sourcePDFAbsPath, String destinationImageAbsPath, Float scalingFactor, String fileFormat, int softLimitInKB) throws Exception
{ 

    System.setProperty("org.jpedal.flattenForm","true");
    logger.info("createPDF2ImageTask ( sourcePDFAbsPath = "+sourcePDFAbsPath+" , destinationImageAbsPath = "+destinationImageAbsPath+ ", scalingFactor = "+scalingFactor+ " , fileFormat = "+fileFormat+ " softLimitInKB ="+softLimitInKB );
    boolean status = true;
    Float newScalingFactor;
    int sizeOfImageInKB;

    //PdfDecoder object provides the conversion 

    PdfDecoderServer decoder = null;
    Map mapValues = null;
    BufferedImage imageToSave = null;
    BufferedOutputStream bufferedOutputStream = null;
    long startTime = System.currentTimeMillis();
    try
    {

        Helper.deleteFile(destinationImageAbsPath);

        //mappings for non-embedded fonts to use
        FontMappings.setFontReplacements();

        decoder = new PdfDecoderServer(true);
        decoder.openPdfFile(sourcePDFAbsPath);


        mapValues = new HashMap();


        mapValues.put(JPedalSettings.EXTRACT_AT_BEST_QUALITY_MAXSCALING, 2);

        //alternatively secify a page size (aspect ratio preserved so will do best fit)
        //set a page size (JPedal will put best fit to this)
        PdfPageData pageData = decoder.getPdfPageData();
        int width = (int)(scalingFactor*pageData.getCropBoxWidth(1));
        int height = (int)(scalingFactor*pageData.getCropBoxHeight(1));
        logger.info("width = "+ width + "   height= "+height);          
        mapValues.put(JPedalSettings.EXTRACT_AT_PAGE_SIZE, new String[]{String.valueOf(width),String.valueOf(height)});

        //which takes priority (default is false)
        mapValues.put(JPedalSettings.PAGE_SIZE_OVERRIDES_IMAGE, Boolean.TRUE);

        PdfDecoderServer.modifyJPedalParameters(mapValues);                              

        /////////////////////////////////////////////////////////////////////////////////////

        try
        {
            imageToSave = decoder.getPageAsHiRes(1, null, false);
            decoder.flushObjectValues(true);
            if(imageToSave != null)
            {
                logger.info("Start saving image as a file");
                bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(destinationImageAbsPath)));

                ImageIO.write(imageToSave, fileFormat, bufferedOutputStream);

            }
            else
            {
                throw new Exception("imageToSave is null, Exception in extractPageAsImage ");
            }
        }
        catch(Exception e)
        {
            logger.error("Exception in extractPageAsImage :: "+e);
            logger.error("Exception stack trace in extractPageAsImage :: ",e);
            throw new Exception("Exception in extractPageAsImage :: "+e);
        }

問題の内容と、Tomcat が停止する理由を突き止める必要があります。ログには、次の行しか表示されません。例外はありません。行logger.info("width = "+ width + " height= "+height);を実行した後 Tomcat を停止します。

[INFO ] 2015-09-02 04:49:45 com.pearson.ebook.pdfprocessors.PDF2IMAGEConversionTask.PDF2ImageConversationTask(PDF2IMAGEConversionTask.java:115) - Creating page level image using JPedal tool
[INFO ] 2015-09-02 04:49:45 com.pearson.ebook.pdfprocessors.PDF2IMAGEConversionTask.createPDF2ImageTask(PDF2IMAGEConversionTask.java:297) - createPDF2ImageTask ( sourcePDFAbsPath = /export/home/apps/ebookcm/dev1/content/simpleebook/curriculum/hcl_test/test1/test2_jg/ingest/pdf/cropped-pdf//7cad530e57768d8d7361baebf0b51b47.pdf , destinationImageAbsPath = /export/home/apps/ebookcm/dev1/content/simpleebook/curriculum/hcl_test/test1/test2_jg/ebookCM29922739/1.0/dlimages/7cad530e57768d8d7361baebf0b51b47.png, scalingFactor = 2.0 , fileFormat = png softLimitInKB =400
[INFO ] 2015-09-02 04:49:45 com.pearson.ebook.helper.Helper.deleteFile(Helper.java:381) - deleteFile sourceFile=/export/home/apps/ebookcm/dev1/content/simpleebook/curriculum/hcl_test/test1/test2_jg/ebookCM29922739/1.0/dlimages/7cad530e57768d8d7361baebf0b51b47.png
[INFO ] 2015-09-02 04:49:45 com.pearson.ebook.pdfprocessors.PDF2IMAGEConversionTask.createPDF2ImageTask(PDF2IMAGEConversionTask.java:334) - width = 1296   height= 1566
4

0 に答える 0