public GFPDDocument(org.verapdf.pd.PDDocument document) { super(document, PD_DOCUMENT_TYPE); PDCatalog catalog; catalog = document.getCatalog(); this.catalog = catalog; }
/** * Method return root object of model implementation from greenfield model * together with the hierarchy. * * @return root object representing by * {@link org.verapdf.model.coslayer.CosDocument} * @throws IOException when target file is not pdf or pdf file is not contain root * object */ @Override public org.verapdf.model.baselayer.Object getRoot() { return new GFCosDocument(this.document.getDocument()); }
/** * Create a new PDFDocumentImpl from the passed InputStream * * @param pdfStream an {@link InputStream} to be parsed as a PDF Document. * @throws IOException when there's a problem reading or parsing the file. */ public PDFDocumentImpl(InputStream pdfStream) throws IOException { this(new PDDocument(pdfStream)); }
public List<PDPage> getPages() { final List<PDPage> pages = new ArrayList<>(); final int pageCount = this.getCatalog().getPageTree().getPageCount(); for (int i = 0; i < pageCount; i++) { pages.add(this.getPage(i)); } return pages; }
private MetadataImpl parseMetadata() { PDCatalog catalog = this.document.getCatalog(); PDMetadata meta = catalog.getMetadata(); if (meta == null) { COSObject stream = COSStream.construct(); catalog.setKey(ASAtom.METADATA, stream); this.document.getDocument().addObject(stream); VeraPDFMeta xmp = VeraPDFMeta.create(); return new MetadataImpl(xmp, stream, this.document.getDocument(), true); } return parseMetadata(meta, this.document); }
/** * {@inheritDoc} Implemented by GreenField library. */ @Override public MetadataFixerResult saveDocumentIncremental(final MetadataFixerResultImpl.RepairStatus status, OutputStream output) { MetadataFixerResultImpl.Builder builder = new MetadataFixerResultImpl.Builder(); try { PDMetadata meta = this.document.getCatalog().getMetadata(); boolean isMetaPresent = meta != null && this.isNeedToBeUpdated(); boolean isMetaAdd = meta == null && this.metadata != null; if (isMetaPresent || isMetaAdd) { this.metadata.updateMetadataStream(); if (isMetaAdd) { this.document.getDocument().addChangedObject( this.document.getCatalog().getObject()); } this.document.saveTo(output); output.close(); builder.status(getStatus(status)); } else { builder.status(status); } } catch (Exception e) { LOGGER.log(Level.FINE, e.getMessage(), e); builder.status(FIX_ERROR).addFix("Problems with document save. " + e.getMessage()); } return builder.build(); }
public static void registerFileSpecificationKeys(COSDocument document) { PDDocument pdDocument = document.getPDDocument(); if (pdDocument == null) { return; } PDCatalog catalog = pdDocument.getCatalog(); if (catalog != null) { registerDictionaryAFKeys(catalog.getObject()); processStructElements(catalog.getStructTreeRoot()); } List<PDPage> pages = pdDocument.getPages(); for (PDPage page : pages) { processPage(page); } visitedKeys.clear(); }
public Boolean getdoesByteRangeCoverEntireDocument() { try { SeekableInputStream pdfSource = StaticContainers.getDocument().getPDFSource(); long offest = pdfSource.getOffset(); SignatureParser parser = new SignatureParser(pdfSource, StaticContainers.getDocument().getDocument()); long[] actualByteRange = parser.getByteRangeBySignatureOffset(signatureOffset);
@Override public void close() { if (this.document != null) { this.document.close(); } }
private List<PDAcroForm> getAcroForms() { org.verapdf.pd.form.PDAcroForm acroForm = document.getAcroForm(); if (acroForm != null) { List<PDAcroForm> forms = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); forms.add(new GFPDAcroForm(acroForm)); return Collections.unmodifiableList(forms); } return Collections.emptyList(); }
public PDPage newPage(final double[] bbox, final int insertAt) { final PDPage page = new PDPage(bbox, document); this.addPage(page, insertAt); return page; }
public PDDocument() throws IOException { this.catalog = new PDCatalog(); this.constructDocument(); }
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 void open(final InputStream inputStream) throws IOException { this.close(); document = new COSDocument(inputStream, this); }
public PDStructTreeRoot getStructTreeRoot() { return getCatalog().getStructTreeRoot(); }
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 void open(final String filename) throws IOException { this.close(); document = new COSDocument(filename, this); }
private GFModelParser(final File pdfFile, PDFAFlavour flavour) throws IOException { try { this.document = new PDDocument(pdfFile.getAbsolutePath()); this.flavour = (flavour == PDFAFlavour.NO_FLAVOUR) ? obtainFlavour(this.document) : flavour; initializeStaticContainers(this.document, this.flavour); } catch (Throwable t) { this.close(); throw t; } }
public List<PDOutputIntent> getOutputIntents() { return getCatalog().getOutputIntents(); }
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(); }