private PDFDocument toPDFDocument(Object source,String password, Resource directory) throws PageException {
if(source instanceof PDFDocument)
return (PDFDocument)source;
if(Decision.isBinary(source)){
return new PDFDocument(Caster.toBinary(source),password);
}
if(source instanceof Resource){
return new PDFDocument((Resource) source,password);
}
if(source instanceof String){
if(directory!=null) {
Resource res = directory.getRealResource((String)source);
if(!res.isFile()){
Resource res2 = ResourceUtil.toResourceNotExisting(pageContext, (String)source);
if(res2.isFile())
res=res2;
else
throw new ExpressionException("file or directory "+res+" not exist");
}
return new PDFDocument(res,password);
}
return new PDFDocument(ResourceUtil.toResourceExisting(pageContext, (String)source),password);
}
throw new CasterException(source,PdfReader.class);
}