public COSObject getID() { return getKey(ASAtom.ID); }
public COSXRefTableReader() { this.startXRef = 0; this.offsets = new HashMap<>(); this.trailer = new COSTrailer(); }
private void getTrailer(final COSTrailer trailer) throws IOException { if (findKeyword(Token.Keyword.KW_TRAILER)) { COSObject obj = nextObject(); trailer.setObject(obj); } if (trailer.knownKey(ASAtom.ENCRYPT)) { this.isEncrypted = true; this.encryption = trailer.getEncrypt(); } }
public void setTrailer(final COSTrailer trailer, final long prev) { COSObject element = new COSObject(); COSCopier copier = new COSCopier(element); trailer.getObject().accept(copier); this.info.getTrailer().setObject(element); this.info.getTrailer().setPrev(prev); if (prev == 0) { this.info.getTrailer().removeKey(ASAtom.ID); } }
private static COSObject getInformationDictionary(COSDocument document) { final COSObject info = document.getTrailer().getInfo(); if (info != null && info.getType() == COSObjType.COS_DICT) { return info; } return null; }
public Long getPrev() { return getObject().getIntegerKey(ASAtom.PREV); }
public PDCatalog getCatalog() { if (!catalog.empty() || document == null) { return catalog; } COSObject root = document.getTrailer().getRoot(); if (root == COSObject.getEmpty()) { root = new COSObject(); document.getTrailer().setRoot(root); } if (!root.empty()) { catalog.setObject(root); return catalog; } root.setNameKey(ASAtom.TYPE, ASAtom.CATALOG); COSObject pages = new COSObject(); pages.setNameKey(ASAtom.TYPE, ASAtom.PAGES); pages.setArrayKey(ASAtom.KIDS); pages.setIntegerKey(ASAtom.COUNT, 0); pages = COSIndirect.construct(root, document); root.setKey(ASAtom.PAGES, pages); root = COSIndirect.construct(root, document); document.getTrailer().setRoot(root); catalog.setObject(root); return catalog; }
public void writeXRefInfo() { try { this.info.setStartXRef(getOffset() + incrementalOffset); this.info.getTrailer().setSize(this.info.getXRefSection().next()); this.write("xref"); this.write(EOL); this.write(info.getXRefSection()); this.write("trailer"); this.write(EOL); this.write(this.info.getTrailer().getObject()); this.write(EOL); this.write("startxref"); this.write(EOL); this.write(this.info.getStartXRef()); this.write(EOL); this.write("%%EOF"); this.write(EOL); } catch (IOException e) { e.printStackTrace(); } }
private COSDictionary getCatalog() { COSBase catalogLocal = cosDocument.getTrailer().getRoot().getDirectBase(); if (catalogLocal != null && catalogLocal.getType() == COSObjType.COS_DICT) { return (COSDictionary) catalogLocal; } return null; }
private void parseXrefStream(final COSXRefInfo section) throws IOException { nextToken(); if (this.getToken().type != Token.Type.TT_INTEGER) { throw new IOException("PDFParser::GetXRefSection(...)" + StringExceptions.CAN_NOT_LOCATE_XREF_TABLE); } nextToken(); if (this.getToken().type != Token.Type.TT_KEYWORD || this.getToken().keyword != Token.Keyword.KW_OBJ) { throw new IOException("PDFParser::GetXRefSection(...)" + StringExceptions.CAN_NOT_LOCATE_XREF_TABLE); } COSObject xrefCOSStream = getDictionary(); if (!(xrefCOSStream.getType() == COSObjType.COS_STREAM)) { throw new IOException("PDFParser::GetXRefSection(...)" + StringExceptions.CAN_NOT_LOCATE_XREF_TABLE); } XrefStreamParser xrefStreamParser = new XrefStreamParser(section, (COSStream) xrefCOSStream.getDirectBase()); xrefStreamParser.parseStreamAndTrailer(); if (section.getTrailer().knownKey(ASAtom.ENCRYPT)) { this.isEncrypted = true; this.encryption = section.getTrailer().getEncrypt(); } }
public void set(final List<COSXRefInfo> infos) { this.startXRef = 0; this.offsets.clear(); this.trailer.clear(); if (infos == null || infos.isEmpty()) { return; } COSXRefInfo lastInfo = infos.get(infos.size()-1); this.startXRef = lastInfo.getStartXRef(); this.trailer = lastInfo.getTrailer(); Map<Long, COSTrailer> trailers = new HashMap<>(); for (COSXRefInfo info : infos) { trailers.put(info.getStartXRef(), info.getTrailer()); info.getXRefSection().addTo(this.offsets); } setFirstLastTrailers(trailers); infos.clear(); }
private void getXRefInfo(final List<COSXRefInfo> info, Set<Long> processedOffsets, Long offset) throws IOException { if (offset.longValue() == 0) { offset = findLastXRef(); if (offset.longValue() == 0) { throw new IOException("PDFParser::GetXRefInfo(...)" + StringExceptions.START_XREF_VALIDATION); } } if (processedOffsets.contains(offset)) { throw new LoopedException("XRef loop"); } processedOffsets.add(offset); clear(); //for files with junk before header if (offsetShift > 0) { offset += offsetShift; } //we will skip eol marker in any case source.seek(offset.longValue() - 1); COSXRefInfo section = new COSXRefInfo(); info.add(0, section); section.setStartXRef(offset.longValue()); getXRefSectionAndTrailer(section); offset = section.getTrailer().getPrev(); if (offset == null || offset.longValue() == 0) { return; } getXRefInfo(info, processedOffsets, offset); }
private boolean docCanBeDecrypted() { try { COSObject cosEncrypt = this.parser.getEncryption(); if (cosEncrypt.isIndirect().booleanValue()) { cosEncrypt = this.parser.getObject(this.getOffset(cosEncrypt.getObjectKey()).longValue()); } PDEncryption encryption = new PDEncryption(cosEncrypt); if (encryption.getFilter() != ASAtom.STANDARD) { return false; } StandardSecurityHandler ssh = new StandardSecurityHandler(encryption, this.getTrailer().getID(), this.parser.getDocument()); boolean res = ssh.isEmptyStringPassword(); if (res) { this.parser.getDocument().setStandardSecurityHandler(ssh); } return res; } catch (IOException e) { LOGGER.log(Level.FINE, "Cannot read object " + this.parser.getEncryption().getObjectKey(), e); return false; } }
private InfoDictionaryImpl getInfo() { COSTrailer trailer = this.document.getDocument().getTrailer(); COSObject infoDict = trailer.getInfo(); return (infoDict != null && infoDict.getType() == COSObjType.COS_DICT) ? new InfoDictionaryImpl(infoDict, this.document.getDocument()) : null; }
public Long getSize() { return getObject().getIntegerKey(ASAtom.SIZE); }
private void parseDocumentFeatures(PDDocument document) { COSDocument cosDocument = document.getDocument(); COSTrailer trailer = cosDocument.getTrailer(); if (trailer != null) { reporter.report(GFFeaturesObjectCreator.createInfoDictFeaturesObject(trailer.getInfo())); } StandardSecurityHandler standardSecurityHandler = cosDocument.getStandardSecurityHandler(); if (standardSecurityHandler != null) { reporter.report(GFFeaturesObjectCreator.createDocSecurityFeaturesObject(standardSecurityHandler.getPdEncryption())); } try { PDCatalog catalog = document.getCatalog(); if (catalog != null) { getCatalogFeatures(catalog); } } catch (IOException e) { LOGGER.log(Level.SEVERE, "Problem in parsing document catalog", e); } reporter.report(GFFeaturesObjectCreator.createLowLvlInfoFeaturesObject(cosDocument)); }
public COSObject getRoot() { return getKey(ASAtom.ROOT); }
public void setID(final COSObject id) { getObject().setArrayKey(ASAtom.ID, id); }