Using Jpedal tool and Tomcat stopped unexpectedly

160 Views Asked by At

I am using Jpedal tool to convert PDF to Image. Jpedal tool helps to convert any or large number of PDF pages (let's say PDF pages = 1200) into .PNG images. In general this is working, however once in a while during converting these large number of PDF pages into images it causes Tomcat to stop unexpectedly.

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);
        }

I have to trace out what is the issue and why is it causing tomcat to stop. In logs, I can see only following lines. No exception is there. After executing line logger.info("width = "+ width + " height= "+height); it stops 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
0

There are 0 best solutions below