/** * trailer dictionary */ private List<CosTrailer> getTrailer() { List<CosTrailer> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); list.add(new GFCosTrailer((COSDictionary) cosDocument.getTrailer().getObject().getDirectBase())); return Collections.unmodifiableList(list); }
public PDDocument getPDDocument() { final COSDocument cosDocument = super.getObject().getDocument(); if (cosDocument != null) { return cosDocument.getPDDocument(); } else { return null; } }
public void close() { if (document != null) { try { if (document.getPDFSource() != null) { document.getPDFSource().close(); } document.getResourceHandler().close(); } catch (IOException e) { LOGGER.log(Level.FINE, "Error in closing stream", e); } document = null; } StaticResources.clear(); catalog.clear(); //this.info.clear; }
/** * Constructor using greenfield COSDocument * * @param cosDocument * greenfield COSDocument */ public GFCosDocument(COSDocument cosDocument) { super(cosDocument, COS_DOCUMENT_TYPE); this.catalog = this.getCatalog(); COSHeader cosHeader = cosDocument.getHeader(); this.indirectObjectCount = cosDocument.getObjects().size(); this.version = cosHeader.getVersion(); this.headerOffset = cosHeader.getHeaderOffset(); this.header = cosHeader.getHeader(); this.headerCommentByte1 = cosHeader.getHeaderCommentByte1(); this.headerCommentByte2 = cosHeader.getHeaderCommentByte2(); this.headerCommentByte3 = cosHeader.getHeaderCommentByte3(); this.headerCommentByte4 = cosHeader.getHeaderCommentByte4(); this.isOptionalContentPresent = parseOptionalContentPresent(); this.postEOFDataSize = cosDocument.getPostEOFDataSize(); this.isLinearised = cosDocument.getTrailer() != cosDocument.getLastTrailer() && cosDocument.isLinearized(); this.lastID = getTrailerID(cosDocument.getLastTrailer().getKey(ASAtom.ID)); this.firstPageID = getTrailerID(cosDocument.getFirstTrailer().getKey(ASAtom.ID)); PDFAFlavour.Specification specification = StaticContainers.getFlavour().getPart(); if (specification == PDFAFlavour.Specification.ISO_19005_3 || specification == PDFAFlavour.Specification.ISO_19005_4) { FileSpecificationKeysHelper.registerFileSpecificationKeys(cosDocument); } }
private void init(COSDocument document) { this.isPresent = document != null; if (document != null) { COSHeader documentHeader = document.getHeader(); if (documentHeader != null) { this.headerVersion = documentHeader.getVersion(); if (document.getObjects() != null) { this.indirectObjectsNumber = document.getObjects().size(); COSArray ids = document.getID(); if (ids != null) { this.creationId = ids.at(0).getString(); PDDocument pdDocument = document.getPDDocument(); if (pdDocument != null) { PDCatalog catalog = pdDocument.getCatalog();
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)); }
if (this.document.isReaderInitialized() && this.document.getOffset(keyOfCurrentObject) == 0) { return new COSObject(); if (this.document.isEncrypted()) { this.document.getStandardSecurityHandler().decryptStream( (COSStream) obj.getDirectBase(), new COSKey((int) number, (int) generation));
public void writeIncrementalUpdate(List<COSObject> changedObjects, List<COSObject> addedObjects) { List<COSKey> objectsToWrite = new ArrayList<>(); for (COSObject obj : changedObjects) { COSKey key = obj.getObjectKey(); if (key != null) { objectsToWrite.add(obj.getObjectKey()); } } changedObjects.clear(); objectsToWrite.addAll(prepareAddedObjects(addedObjects)); this.addToWrite(objectsToWrite); this.writeBody(); COSTrailer trailer = document.getTrailer(); // document.getLastTrailerOffset() + 1 point EXACTLY at first byte of xref this.setTrailer(trailer, document.getLastTrailerOffset() + 1); this.writeXRefInfo(); this.clear(); }
private List<Glyph> getUsedGlyphs() { org.verapdf.pd.font.PDFont font = getFontFromResources(); if (font == null) { return Collections.emptyList(); } FontProgram fontProgram = font.getFontProgram(); if (fontProgram instanceof CFFFontProgram) { StaticContainers.getDocument().getDocument().getResourceHandler().addResource( fontProgram.getFontProgramResource()); } List<Glyph> res = new ArrayList<>(); List<byte[]> strings = GFOpTextShow.getStrings(this.arguments); for (byte[] string : strings) { try (InputStream inputStream = new ByteArrayInputStream(string)) { while (inputStream.available() > 0) { int code = font.readCode(inputStream); Glyph glyph; glyph = GFGlyph.getGlyph(font, code, this.renderingMode.getValue(), markedContent, structureElementAccessObject); res.add(glyph); } } catch (IOException e) { LOGGER.log(Level.FINE, "Error processing text show operator's string argument : " + new String(string), e); StaticContainers.setValidPDF(false); } } return Collections.unmodifiableList(res); }
@Override public boolean isNeedToBeUpdated() { return this.doc.isObjectChanged(this.info); }
source.seek(currentOffset + document.getHeader().getHeaderOffset()); source.read(buffer); source.unread(buffer.length - 1); source.seek(currentOffset + document.getHeader().getHeaderOffset()); return source.getStreamLength(); this.isStreamEnd = true; source.seek(currentOffset + document.getHeader().getHeaderOffset()); return result;
private COSObject decryptCOSString(COSObject string) { StandardSecurityHandler ssh = this.document.getStandardSecurityHandler(); try { ssh.decryptString((COSString) string.getDirectBase(), this.keyOfCurrentObject); return string; } catch (IOException | GeneralSecurityException e) { LOGGER.log(Level.WARNING, "Can't decrypt string in object " + this.keyOfCurrentObject); return string; } } }
private Set<String> getAllFilters(COSDocument document) { Set<String> res = new HashSet<>(); for (COSObject base : document.getObjects()) { if (base.getType() == COSObjType.COS_STREAM) { COSFilters baseFilters = ((COSStream) base.getDirectBase()).getFilters(); addFilters(res, baseFilters); } } return res; }
public GFPDSignature(org.verapdf.pd.PDSignature pdSignature, COSObject signatureReference) { super(pdSignature, SIGNATURE_TYPE); if(signatureReference.isIndirect().booleanValue()) { COSKey key = signatureReference.getObjectKey(); this.signatureOffset = StaticContainers.getDocument().getDocument().getOffset(key).longValue(); } contents = pdSignature.getContents(); }
if (StaticContainers.getDocument() != null && StaticContainers.getDocument().getDocument() != null) { StaticContainers.getDocument().getDocument().getResourceHandler().addAll( streamParser.getImageDataStreams());
@Override public boolean isNeedToBeUpdated() { return this.doc.isObjectChanged(this.stream); }
private COSObject decryptCOSString(COSObject string) { StandardSecurityHandler ssh = this.document.getStandardSecurityHandler(); try { ssh.decryptString((COSString) string.getDirectBase(), this.keyOfCurrentObject); return string; } catch (IOException | GeneralSecurityException e) { LOGGER.log(Level.WARNING, "Can't decrypt string in object " + this.keyOfCurrentObject); return string; } } }
private static COSObject getInformationDictionary(COSDocument document) { final COSObject info = document.getTrailer().getInfo(); if (info != null && info.getType() == COSObjType.COS_DICT) { return info; } return null; }
private static InputStream getMetadataStream(COSDocument document) throws IOException { PDMetadata meta = document.getPDDocument().getMetadata(); if (meta != null) { return meta.getStream(); } return null; }