List of usage examples for com.lowagie.text.pdf PdfName EF
PdfName EF
To view the source code for com.lowagie.text.pdf PdfName EF.
Click Source Link
From source file:eu.europa.cedefop.europass.jtool.util.ExtractAttachments.java
License:EUPL
/** * Get the attachment file /*from ww w . j a va2 s.c om*/ * @param filespec * @throws IOException */ public void unpackFile(PdfDictionary filespec) throws IOException { if (filespec == null) return; PdfName type = (PdfName) PdfReader.getPdfObject(filespec.get(PdfName.TYPE)); if (!PdfName.F.equals(type) && !PdfName.FILESPEC.equals(type)) return; PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(filespec.get(PdfName.EF)); if (ef == null) return; PdfString fn = (PdfString) PdfReader.getPdfObject(filespec.get(PdfName.F)); if (fn == null) return; PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F)); if (prs == null) return; byte b[] = PdfReader.getStreamBytes(prs); FileOutputStream fout = new FileOutputStream(trgfile); fout.write(b); fout.close(); }
From source file:net.sqs2.omr.master.sqm.PDFAttachmentExtractor.java
License:Apache License
/** * Unpacks a file attachment./*ww w. java2s .c om*/ * * @param reader * The object that reads the PDF document * @param filespec * The dictionary containing the file specifications * @param outPath * The path where the attachment has to be written * @throws IOException */ private static byte[] unpackFile(PdfReader reader, PdfDictionary filespec, String suffix) throws IOException { if (filespec == null) { return null; } PdfName type = (PdfName) PdfReader.getPdfObject(filespec.get(PdfName.TYPE)); if (!PdfName.F.equals(type) && !PdfName.FILESPEC.equals(type)) { return null; } PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(filespec.get(PdfName.EF)); if (ef == null) { return null; } PdfString fn = (PdfString) PdfReader.getPdfObject(filespec.get(PdfName.F)); if (fn == null) { return null; } File fLast = new File(fn.toUnicodeString()); String filename = fLast.getName(); if (!filename.endsWith(suffix)) { return null; } PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F)); if (prs == null) { return null; } return PdfReader.getStreamBytes(prs); }
From source file:org.kuali.coeus.propdev.impl.budget.subaward.PropDevPropDevBudgetSubAwardServiceImpl.java
License:Open Source License
/** * Unpacks a file attachment./*from ww w . ja v a2s. co m*/ * @param reader The object that reads the PDF document * @param filespec The dictonary containing the file specifications * @throws IOException */ protected static Object[] unpackFile(PdfReader reader, PdfDictionary filespec) throws IOException { Object arr[] = new Object[2]; //use to store name and file bytes if (filespec == null) { return null; } PdfName type = (PdfName) PdfReader.getPdfObject(filespec.get(PdfName.TYPE)); if (!PdfName.F.equals(type) && !PdfName.FILESPEC.equals(type)) { return null; } PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(filespec.get(PdfName.EF)); if (ef == null) { return null; } PdfString fn = (PdfString) PdfReader.getPdfObject(filespec.get(PdfName.F)); if (fn == null) { return null; } File fLast = new File(fn.toUnicodeString()); PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F)); if (prs == null) { return null; } byte attachmentByte[] = PdfReader.getStreamBytes(prs); arr[0] = fLast.getName(); arr[1] = attachmentByte; return arr; }
From source file:org.kuali.coeus.propdev.impl.s2s.S2sUserAttachedFormServiceImpl.java
License:Open Source License
/** * Unpacks a file attachment.//ww w . j a v a2 s . co m * @param filespec * The dictonary containing the file specifications * @throws IOException */ private Object[] unpackFile(PdfDictionary filespec) throws IOException { if (filespec == null) return null; PdfName type = (PdfName) PdfReader.getPdfObject(filespec.get(PdfName.TYPE)); if (!PdfName.F.equals(type) && !PdfName.FILESPEC.equals(type)) return null; PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(filespec.get(PdfName.EF)); if (ef == null) return null; PdfString fn = (PdfString) PdfReader.getPdfObject(filespec.get(PdfName.F)); if (fn == null) return null; File fLast = new File(fn.toUnicodeString()); PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F)); if (prs == null) return null; byte attachmentByte[] = PdfReader.getStreamBytes(prs); Object[] fileInfo = new Object[2]; fileInfo[0] = fLast.getName(); fileInfo[1] = attachmentByte; return fileInfo; }
From source file:org.kuali.kra.s2s.service.impl.S2SUserAttachedFormServiceImpl.java
License:Educational Community License
/** * Unpacks a file attachment./*from w ww . ja v a 2 s . c om*/ * * @param reader * The object that reads the PDF document * @param filespec * The dictonary containing the file specifications * @throws IOException */ private Object[] unpackFile(PdfReader reader, PdfDictionary filespec) throws IOException { S2sUserAttachedFormAtt userAttachedS2SFormAttachmentBean = new S2sUserAttachedFormAtt(); if (filespec == null) return null; PdfName type = (PdfName) PdfReader.getPdfObject(filespec.get(PdfName.TYPE)); if (!PdfName.F.equals(type) && !PdfName.FILESPEC.equals(type)) return null; PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(filespec.get(PdfName.EF)); if (ef == null) return null; PdfString fn = (PdfString) PdfReader.getPdfObject(filespec.get(PdfName.F)); if (fn == null) return null; File fLast = new File(fn.toUnicodeString()); PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F)); if (prs == null) return null; byte attachmentByte[] = PdfReader.getStreamBytes(prs); Object[] fileInfo = new Object[2]; fileInfo[0] = fLast.getName(); fileInfo[1] = attachmentByte; return fileInfo; }
From source file:org.pdfsam.console.business.pdf.handlers.UnpackCmdExecutor.java
License:Open Source License
/** * Unpack/*from w w w . j a v a 2s . c o m*/ * @param filespec the dictionary * @param outPath output directory * @param overwrite if true overwrite if already exists * @return number of unpacked files * @throws IOException */ private int unpackFile(PdfDictionary filespec, File outPath, boolean overwrite) throws IOException { int retVal = 0; if (filespec != null) { PdfName type = (PdfName) PdfReader.getPdfObject(filespec.get(PdfName.TYPE)); if (PdfName.F.equals(type) || PdfName.FILESPEC.equals(type)) { PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(filespec.get(PdfName.EF)); PdfString fn = (PdfString) PdfReader.getPdfObject(filespec.get(PdfName.F)); if (fn != null && ef != null) { LOG.debug("Unpacking file " + fn + " to " + outPath); File fLast = new File(fn.toUnicodeString()); File fullPath = new File(outPath, fLast.getName()); if (fullPath.exists()) { //check if overwrite is allowed if (overwrite) { if (!fullPath.delete()) { LOG.warn("Unable to overwrite " + fullPath.getAbsolutePath() + ", unable to unpack."); } } else { LOG.warn("Cannot overwrite " + fullPath.getAbsolutePath() + " (overwrite is false), unable to unpack."); } } else { PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F)); if (prs != null) { byte b[] = PdfReader.getStreamBytes(prs); FileOutputStream fout = new FileOutputStream(fullPath); fout.write(b); fout.close(); retVal = 1; } } } } } return retVal; }
From source file:org.sejda.impl.itext.component.PdfUnpacker.java
License:Apache License
private void unpack(Set<PdfDictionary> dictionaries) throws TaskIOException { for (PdfDictionary dictionary : dictionaries) { PdfName type = (PdfName) PdfReader.getPdfObject(dictionary.get(PdfName.TYPE)); if (PdfName.F.equals(type) || PdfName.FILESPEC.equals(type)) { PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(dictionary.get(PdfName.EF)); PdfString fn = (PdfString) PdfReader.getPdfObject(dictionary.get(PdfName.F)); if (fn != null && ef != null) { PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F)); if (prs != null) { File tmpFile = copyToTemporaryFile(prs); outputWriter.addOutput(file(tmpFile).name(fn.toUnicodeString())); }/*from ww w.j a v a 2 s.co m*/ } } } }