if (pdfVersion == null) {
currentPdfFile = null;
isDecoding = false;
throw new PdfException( "No version on first line ");
}
// read reference table so we can find all objects and say if
// encrypted
PdfObject pdfObject=null ;
int linearPageCount=-1;
//linear page object set differently
if(linearParser.hasLinearData()){
/**
* read and decode the hints table and the ref table
*/
pdfObject=linearParser.readHintTable(pdfObject,currentPdfFile);
linearPageCount=linearParser.getPageCount();
}else//<end-gpl>
pdfObject=currentPdfFile.getObjectReader().readReferenceTable(null);
//new load code - be more judicious in how far down tree we scan
final boolean ignoreRecursion=true;
// open if not encrypted or has password
if (!isEncrypted() || isPasswordSupplied()) {
if (pdfObject != null){
pdfObject.ignoreRecursion(ignoreRecursion);
res.setValues(pdfObject,currentPdfFile);
//check read as may be used for Dest
PdfObject nameObj=pdfObject.getDictionary(PdfDictionary.Names);
if (nameObj != null){
currentPdfFile.readNames(nameObj, options.getJS(),false);
}
}
int type=pdfObject.getParameterConstant(PdfDictionary.Type);
if(type!=PdfDictionary.Page){
PdfObject pageObj= pdfObject.getDictionary(PdfDictionary.Pages);
if(pageObj!=null){ //do this way incase in separate compressed stream
pdfObject=new PageObject(pageObj.getObjectRefAsString());
currentPdfFile.readObject(pdfObject);
// System.out.println("page="+pageObj+" "+pageObj.getObjectRefAsString());
//catch for odd files
if(pdfObject.getParameterConstant(PdfDictionary.Type)==-1)
pdfObject=pageObj;
//System.out.println("test code called");
}
}
if (pdfObject != null) {
if(LogWriter.isOutput())
LogWriter.writeLog("Pages being read from "+pdfObject+ ' '+pdfObject.getObjectRefAsString());
pageNumber = 1; // reset page number for metadata
// reset lookup table
//pageLookup = new PageLookup();
//flush annots before we reread
if(formRenderer!=null)
formRenderer.resetAnnotData(insetW, insetH, pageData, 1, currentPdfFile,null);
//recursively read all pages
int tempPageCount=readAllPageReferences(ignoreRecursion, pdfObject, new HashMap(1000), new HashMap(1000),1);
//set PageCount if in Linearized data
if(linearPageCount>0){
pageCount=linearPageCount;
}else{
pageCount = tempPageCount - 1; // save page count
}
pageNumber =0; // reset page number for metadata;
if (this.pageCount == 0 && LogWriter.isOutput())
LogWriter.writeLog("No pages found");
}
// pass handle into renderer
if (formRenderer != null) {
formRenderer.openFile(pageCount);
formRenderer.resetFormData(insetW, insetH, pageData, currentPdfFile, res.getPdfObject(PdfResources.AcroFormObj));
}
}
currentOffset = null;
// reset so if continuous view mode set it will be recalculated for page
pages.disableScreen();
pages.stopGeneratingPage();
//force back if only 1 page
if (pageCount < 2)
displayView = Display.SINGLE_PAGE;
else
displayView = options.getPageMode();
//<start-adobe>
setDisplayView(this.displayView, alignment); //force reset and add back listener
/**
//<end-adobe>
if (currentOffset == null)
currentOffset = new PageOffsets(pageCount, pageData);
/**/
isOpen = true;
} catch (PdfException e) {
//ensure all data structures/handles flushed
isDecoding = false;
isOpen=true; //temporarily set to true as otherwise will not work
closePdfFile();
isOpen=false;
isDecoding = false;
throw new PdfException(e.getMessage() + " opening file");
}
isDecoding = false;
}