Refine search
/** * According to the PDF Reference, A linearized PDF contain a dictionary as first object (linearized dictionary) and * only this one in the first section. * * @param document the document to validate. * @return the linearization dictionary or null. */ protected COSDictionary getLinearizedDictionary(PDDocument document) { // ---- Get Ref to obj COSDocument cDoc = document.getDocument(); List<?> lObj = cDoc.getObjects(); for (Object object : lObj) { COSBase curObj = ((COSObject) object).getObject(); if (curObj instanceof COSDictionary && ((COSDictionary) curObj).keySet().contains(COSName.getPDFName(DICTIONARY_KEY_LINEARIZED))) { return (COSDictionary) curObj; } } return null; }
float currentVersion = getVersion(); if (getDocument().getVersion() >= 1.4f) getDocumentCatalog().setVersion(Float.toString(newVersion)); getDocument().setVersion(newVersion);
/** * This will close the underlying COSDocument object. * * @throws IOException If there is an error releasing resources. */ @Override public void close() throws IOException { document.close(); } }
/** * Constructor, creates a new FDF document. * */ public FDFDocument() { document = new COSDocument(); document.setVersion(1.2f); // First we need a trailer document.setTrailer(new COSDictionary()); // Next we need the root dictionary. FDFCatalog catalog = new FDFCatalog(); setCatalog(catalog); }
COSDocument cosDoc = doc.getDocument(); Map<COSObjectKey, Long> xrefTable = cosDoc.getXrefTable(); Set<COSObjectKey> keySet = xrefTable.keySet(); long highestNumber = doc.getDocument().getHighestXRefObjectNumber(); for ( COSObjectKey cosObjectKey : keySet ) COSBase object = cosDoc.getObjectFromPool(cosObjectKey).getObject(); if (object != null && cosObjectKey!= null && !(object instanceof COSNumber))
try doc = PDDocument.load(new File(inputFilename)); for(COSObject objStream : doc.getDocument().getObjectsByType(COSName.OBJ_STM)) PDFObjectStreamParser sp = new PDFObjectStreamParser(stream, doc.getDocument()); sp.parse(); for(COSObject next : sp.getObjects()) COSObject obj = doc.getDocument().getObjectFromPool(key); obj.setObject(next.getObject()); doc.getDocument().removeObject(new COSObjectKey(objStream)); doc.save(outputFilename);
AccessPermission ap = document.getCurrentAccessPermission(); metadata.set(AccessPermissions.EXTRACT_FOR_ACCESSIBILITY, Boolean.toString(ap.canExtractForAccessibility())); Boolean.toString(ap.canPrintDegraded())); if (document.getDocumentCatalog().getLanguage() != null) { metadata.set(TikaCoreProperties.LANGUAGE, document.getDocumentCatalog().getLanguage()); for (COSName key : info.getCOSObject().keySet()) { String name = key.getName(); if (!handledMetadata.contains(name)) { addMetadata(metadata, name, info.getCOSObject().getDictionaryObject(key)); addMetadata(metadata, PDF.PDF_DOC_INFO_CUSTOM_PREFIX + name, info.getCOSObject().getDictionaryObject(key)); metadata.set(PDF.PDF_VERSION, Float.toString(document.getDocument().getVersion())); metadata.add(TikaCoreProperties.FORMAT.getName(), MEDIA_TYPE.toString() + "; version=" + Float.toString(document.getDocument().getVersion()));
throws IOException try (PDDocument doc = PDDocument.load(new File(in), password)) doc.setAllSecurityToBeRemoved(true); for (COSObject cosObject : doc.getDocument().getObjects())
float headerVersionFloat = getDocument().getVersion(); String catalogVersion = getDocumentCatalog().getVersion(); float catalogVersionFloat = -1; if (catalogVersion != null)
Long idTime = doc.getDocumentId() == null ? System.currentTimeMillis() : doc.getDocumentId(); if(doc.isAllSecurityToBeRemoved()) COSDocument cosDoc = doc.getDocument(); COSDictionary trailer = cosDoc.getTrailer(); trailer.removeItem(COSName.ENCRYPT); COSDocument cosDoc = pdDocument.getDocument(); COSDictionary trailer = cosDoc.getTrailer(); COSArray idArray; boolean missingID = true; COSBase base = trailer.getDictionaryObject(COSName.ID); if (base instanceof COSArray) COSDictionary info = (COSDictionary)trailer.getDictionaryObject( COSName.INFO ); if( info != null ) trailer.setItem( COSName.ID, idArray ); cosDoc.accept(this);
/** * Constructor. Internal PDFBox use only! If you need to get the document catalog, call * {@link PDDocument#getDocumentCatalog()}. * * @param doc The document that this catalog is part of. */ protected PDDocumentCatalog(PDDocument doc) { document = doc; root = new COSDictionary(); root.setItem(COSName.TYPE, COSName.CATALOG); document.getDocument().getTrailer().setItem(COSName.ROOT, root); }
/** * Creates a new empty PDStream object. * * @param document The document that the stream will be part of. */ public PDStream(PDDocument document) { stream = document.getDocument().createCOSStream(); }
/** * This will get the document info dictionary. If it doesn't exist, an empty document info * dictionary is created in the document trailer. * * @return The documents /Info dictionary, never null. */ public PDDocumentInformation getDocumentInformation() { if (documentInformation == null) { COSDictionary trailer = document.getTrailer(); COSDictionary infoDic = (COSDictionary) trailer.getDictionaryObject(COSName.INFO); if (infoDic == null) { infoDic = new COSDictionary(); trailer.setItem(COSName.INFO, infoDic); } documentInformation = new PDDocumentInformation(infoDic); } return documentInformation; }
COSStream saveGraphicsStateStream = getDocument().getDocument().createCOSStream(); try (OutputStream saveStream = saveGraphicsStateStream.createOutputStream()) COSStream restoreGraphicsStateStream = getDocument().getDocument().createCOSStream(); try (OutputStream restoreStream = restoreGraphicsStateStream.createOutputStream()) COSBase contents = pageDictionary.getDictionaryObject(COSName.CONTENTS); if (contents instanceof COSStream) array.add(restoreGraphicsStateStream); pageDictionary.setItem(COSName.CONTENTS, array);
COSStream stream = destination.getDocument().createCOSStream(); try (OutputStream output = stream.createRawOutputStream(); InputStream input = originalStream.createRawInputStream()) retval = new COSDictionary(); clonedVersion.put( base, retval ); for( Map.Entry<COSName, COSBase> entry : dic.entrySet() ) ((COSDictionary)retval).setItem( entry.getKey(), cloneForNewDocument(entry.getValue()));
COSStream stream = destination.getDocument().createCOSStream(); try (OutputStream output = stream.createOutputStream(originalStream.getFilters())) for( Map.Entry<COSName, COSBase> entry : dic.entrySet() ) if (((COSDictionary)target).getItem(key) != null) cloneMerge(value, ((COSDictionary)target).getItem(key));
List<COSName> keys = new ArrayList<>(dict.keySet()); Collections.sort( keys ); COSName key = keys.get( index ); COSBase value = dict.getDictionaryObject(key); MapEntry entry = new MapEntry(); entry.setKey( key ); entry.setValue( value ); entry.setItem(dict.getItem(key)); retval = entry; retval = ((COSDocument)parent).getObjects().get( index );
this.flavour = flavour; this.indirectObjectCount = cosDocument.getObjects().size(); this.version = cosDocument.getVersion(); this.headerOffset = cosDocument.getHeaderOffset(); this.header = cosDocument.getHeader(); this.headerCommentByte1 = cosDocument.getHeaderCommentByte1(); this.headerCommentByte2 = cosDocument.getHeaderCommentByte2(); this.headerCommentByte3 = cosDocument.getHeaderCommentByte3(); this.headerCommentByte4 = cosDocument.getHeaderCommentByte4(); this.isOptionalContentPresent = parseOptionalContentPresent(); this.postEOFDataSize = cosDocument.getPostEOFDataSize(); if (cosDocument.getLastTrailer() != null) { this.lastID = getTrailerID((COSArray) cosDocument.getLastTrailer().getDictionaryObject(ID)); } else { this.lastID = null; if (cosDocument.getFirstPageTrailer() != null) { this.firstPageID = getTrailerID((COSArray) cosDocument.getFirstPageTrailer().getDictionaryObject(ID)); } else { this.firstPageID = null; this.isLinearised = cosDocument.getTrailer() != cosDocument.getLastTrailer() && cosDocument.isLinearized(); this.doesInfoMatchXMP = XMPChecker.doesInfoMatchXMP(cosDocument); this.needsRendering = this.getNeedsRenderingValue();
/** * This will write the header to the PDF document. * * @param doc The document to get the data from. * * @throws IOException If there is an error writing to the stream. */ protected void doWriteHeader(COSDocument doc) throws IOException { String headerString; if (fdfDocument != null) { headerString = "%FDF-"+ Float.toString(fdfDocument.getDocument().getVersion()); } else { headerString = "%PDF-"+ Float.toString(pdDocument.getDocument().getVersion()); } getStandardOutput().write( headerString.getBytes(Charsets.ISO_8859_1) ); getStandardOutput().writeEOL(); getStandardOutput().write(COMMENT); getStandardOutput().write(GARBAGE); getStandardOutput().writeEOL(); }