001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.text.pdf; 020 021import java.io.IOException; 022import java.util.Set; 023 024import lucee.commons.io.res.Resource; 025import lucee.commons.lang.ExceptionUtil; 026import lucee.commons.lang.SystemOut; 027import lucee.runtime.exp.ExpressionException; 028import lucee.runtime.exp.PageException; 029import lucee.runtime.img.Image; 030 031public abstract class PDF2Image { 032 033 private static PDF2Image instance; 034 035 public static PDF2Image getInstance() { 036 if(instance==null){ 037 try{ 038 try{ 039 instance=new PDF2ImageICEpdf(); 040 SystemOut.printDate("using ICEpdf PDF2Image Library"); 041 } 042 catch(Throwable t){ 043 ExceptionUtil.rethrowIfNecessary(t); 044 instance=new PDF2ImagePDFRenderer(); 045 SystemOut.printDate("using PDFRenderer PDF2Image Library"); 046 } 047 } 048 catch(Throwable t){ 049 ExceptionUtil.rethrowIfNecessary(t); 050 instance=new PDF2ImageJPedal(); 051 SystemOut.printDate("using JPedal PDF2Image Library"); 052 } 053 } 054 //return new PDF2ImageJPedal(); 055 return instance; 056 } 057 058 059 protected static Resource createDestinationResource(Resource dir,String prefix,int page,String format, boolean overwrite) throws ExpressionException { 060 Resource res = dir.getRealResource(prefix+"_page_"+page+"."+format); 061 if(res.exists()) { 062 if(!overwrite)throw new ExpressionException("can't overwrite existing image ["+res+"], attribute [overwrite] is false"); 063 } 064 return res; 065 } 066 067 068 public abstract Image toImage(byte[] input,int page) throws IOException, PageException; 069 public abstract void writeImages(byte[] input,Set pages,Resource outputDirectory, String prefix,String format, int scale, boolean overwrite, boolean goodQuality,boolean transparent) throws PageException, IOException; 070}