Использование инструмента Jpedal и Tomcat неожиданно остановились
Я использую инструмент Jpedal для преобразования PDF в изображение. Инструмент Jpedal помогает конвертировать любое или большое количество страниц PDF (скажем, PDF pages = 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);
}
Я должен проследить, в чем заключается проблема и почему она заставляет кота остановиться. В логах я вижу только следующие строки. Там нет никаких исключений. После выполнения строки logger.info("ширина = "+ ширина + "высота = "+ высота); это останавливает 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