/** * 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()); }
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 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(); }
private static MetadataImpl parseMetadata(PDMetadata meta, PDDocument document) { try { VeraPDFMeta xmp = VeraPDFMeta.parse(meta.getStream()); if (xmp != null) { return new MetadataImpl(xmp, meta.getObject(), document.getDocument(), false); } } catch (XMPException e) { LOGGER.log(Level.FINE, "Problems with XMP parsing. " + e.getMessage(), e); } return null; }
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); }
@Override public int removeFiltersForAllMetadataObjects() { int res = 0; List<COSObject> objects = this.document.getDocument().getObjectsByType(ASAtom.METADATA); List<COSStream> metas = new ArrayList<>(); for (COSObject obj : objects) { if (obj.getType() == COSObjType.COS_STREAM) { metas.add((COSStream) obj.getDirectBase()); } else { LOGGER.log(Level.SEVERE, "Found non-stream Metadata dictionary."); } } for (COSStream stream : metas) { if (stream.getFilters().size() > 0) { try { stream.setFilters(new COSFilters()); res++; } catch (IOException e) { LOGGER.log(Level.FINE, "Error when removing filter from stream", e); return -1; } } } isUnfiltered = res > 0; return res; }
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); }
streamParser.close(); if (StaticContainers.getDocument() != null && StaticContainers.getDocument().getDocument() != null) { StaticContainers.getDocument().getDocument().getResourceHandler().addAll( streamParser.getImageDataStreams());
/** * {@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 GFPDCIDFont(PDFont font, RenderingMode renderingMode) { super(font, renderingMode, CID_FONT_TYPE); if(font != null) { FontProgram program = font.getFontProgram(); if (program != null) { StaticContainers.getDocument().getDocument().getResourceHandler().addResource( program.getFontProgramResource()); } if(program != null) { try { if (!program.isAttemptedParsing()) { program.parseFont(); } this.fontProgramParsed = program.isSuccessfulParsing(); this.pdFont.setSuccessfullyParsed(program.isSuccessfulParsing()); } catch (IOException e) { LOGGER.log(Level.FINE, "Can't parse font program of font " + font.getName(), e); this.fontProgramParsed = false; this.pdFont.setSuccessfullyParsed(false); } } } }
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)); }
long offest = pdfSource.getOffset(); SignatureParser parser = new SignatureParser(pdfSource, StaticContainers.getDocument().getDocument()); long[] actualByteRange = parser.getByteRangeBySignatureOffset(signatureOffset);
public GFPDType1Font(org.verapdf.pd.font.type1.PDType1Font pdFont, RenderingMode renderingMode) { super(pdFont, renderingMode, TYPE1_FONT_TYPE); if (pdFont != null) { FontProgram program = pdFont.getFontProgram(); if (program != null) { StaticContainers.getDocument().getDocument().getResourceHandler().addResource( program.getFontProgramResource()); } if (program != null) { try { if (!program.isAttemptedParsing()) { program.parseFont(); } this.fontProgramParsed = program.isSuccessfulParsing(); this.pdFont.setSuccessfullyParsed(program.isSuccessfulParsing()); } catch (IOException e) { LOGGER.log(Level.FINE, "Can't parse font program of font " + pdFont.getName(), e); this.fontProgramParsed = false; this.pdFont.setSuccessfullyParsed(false); } } } }