Refine search
@Override public void actionPerformed(ActionEvent actionEvent) { try { InputStream data = stream.createInputStream(stopFilters); saveStream(IOUtils.toByteArray(data), null, null); } catch (IOException e) { e.printStackTrace(); } } });
/** * Returns the content streams which make up this page. * * @return content stream iterator */ public Iterator<PDStream> getContentStreams() { List<PDStream> streams = new ArrayList<>(); COSBase base = page.getDictionaryObject(COSName.CONTENTS); if (base instanceof COSStream) { streams.add(new PDStream((COSStream) base)); } else if (base instanceof COSArray && ((COSArray) base).size() > 0) { COSArray array = (COSArray)base; for (int i = 0; i < array.size(); i++) { COSStream stream = (COSStream) array.getObject(i); streams.add(new PDStream(stream)); } } return streams.iterator(); }
/** * Create a new appearance stream. Note that this is not actually a "page" content stream. * * @param doc The document the page is part of. * @param appearance The appearance stream to write to. * @throws IOException If there is an error writing to the page contents. */ public PDPageContentStream(PDDocument doc, PDAppearanceStream appearance) throws IOException { this (doc, appearance, appearance.getStream().createOutputStream()); }
private List<String> getStopFilterList(final int stopFilterIndex) { List<COSName> avaiablrFilters = new PDStream(stream).getFilters(); final List<String> stopFilters = new ArrayList<>(1); stopFilters.add(avaiablrFilters.get(stopFilterIndex).getName()); return stopFilters; }
private byte[] getLookupData() throws IOException { if (lookupData == null) { COSBase lookupTable = array.getObject(3); if (lookupTable instanceof COSString) { lookupData = ((COSString) lookupTable).getBytes(); } else if (lookupTable instanceof COSStream) { lookupData = new PDStream((COSStream)lookupTable).toByteArray(); } else if (lookupTable == null) { lookupData = new byte[0]; } else { throw new IOException("Error: Unknown type for lookup table " + lookupTable); } } return lookupData; }
/** * Creates a new XObject of the given subtype for writing. * @param document The document in which to create the XObject. * @param subtype The subtype of the new XObject. */ protected PDXObject(PDDocument document, COSName subtype) { stream = new PDStream(document); stream.getCOSObject().setName(COSName.TYPE, COSName.XOBJECT.getName()); stream.getCOSObject().setName(COSName.SUBTYPE, subtype.getName()); }
COSArray destThreads = (COSArray) destCatalog.getCOSObject().getDictionaryObject(COSName.THREADS); COSArray srcThreads = (COSArray) cloner.cloneForNewDocument(destCatalog.getCOSObject().getDictionaryObject( COSName.THREADS)); if (destThreads == null) destCatalog.getCOSObject().setItem(COSName.THREADS, srcThreads); destThreads.addAll(srcThreads); destLabels = new COSDictionary(); destNums = new COSArray(); destLabels.setItem(COSName.NUMS, destNums); destCatalog.getCOSObject().setItem(COSName.PAGE_LABELS, destLabels); if (srcNums != null) int startSize = destNums.size(); for (int i = 0; i < srcNums.size(); i += 2) PDStream newStream = new PDStream(destination, srcMetadata.createInputStream(), (COSName) null); mergeInto(srcMetadata, newStream.getCOSObject(), new HashSet<>(Arrays.asList(COSName.FILTER, COSName.LENGTH))); destCatalog.getCOSObject().setItem(COSName.METADATA, newStream);
PDResources resources) throws IOException super(document, stream.createOutputStream(compress ? COSName.FLATE_DECODE : null), resources); COSBase contents = sourcePage.getCOSObject().getDictionaryObject(COSName.CONTENTS); COSArray array; if (contents instanceof COSArray) array = new COSArray(); array.add(contents); array.add(0, stream.getCOSObject()); PDStream prefixStream = new PDStream(document); OutputStream prefixOut = prefixStream.createOutputStream(); prefixOut.write("q".getBytes(Charsets.US_ASCII)); prefixOut.write('\n'); array.add(0, prefixStream.getCOSObject()); sourcePage.getCOSObject().setItem(COSName.CONTENTS, array);
private void writeToBuffer(PDImageXObject pdImage, String suffix, OutputStream out) throws IOException { BufferedImage image = pdImage.getImage(); if (image != null) { if ("jpg".equals(suffix)) { String colorSpaceName = pdImage.getColorSpace().getName(); PDDeviceRGB.INSTANCE.getName().equals(colorSpaceName)) { InputStream data = pdImage.getStream().createInputStream(JPEG); org.apache.pdfbox.io.IOUtils.copy(data, out); org.apache.pdfbox.io.IOUtils.closeQuietly(data); } else { InputStream data = pdImage.createInputStream(JP2); org.apache.pdfbox.io.IOUtils.copy(data, out); org.apache.pdfbox.io.IOUtils.closeQuietly(data); } else if ("jb2".equals(suffix)) {
/** * Sets the range for this color space. * @param range the new range for the a component * @param n the component to set the range for */ public void setRangeForComponent(PDRange range, int n) { COSArray rangeArray = (COSArray) stream.getCOSObject().getDictionaryObject(COSName.RANGE); if (rangeArray == null) { rangeArray = new COSArray(); stream.getCOSObject().setItem(COSName.RANGE, rangeArray); } // extend range array with default values if needed while (rangeArray.size() < (n + 1) * 2) { rangeArray.add(new COSFloat(0)); rangeArray.add(new COSFloat(1)); } rangeArray.set(n*2, new COSFloat(range.getMin())); rangeArray.set(n*2+1, new COSFloat(range.getMax())); }
.createOutputStream(COSName.FLATE_DECODE)) pdProfile.getPDStream().getCOSObject().setInt(COSName.N, srcCspace.getNumComponents()); pdProfile.getPDStream().getCOSObject().setItem(COSName.ALTERNATE, srcCspace.getType() == ColorSpace.TYPE_CMYK ? COSName.DEVICECMYK : PDImageXObject imageXObject = new PDImageXObject(document, new ByteArrayInputStream(stream.toByteArray()), COSName.FLATE_DECODE, w, h, bitsPerComponent, pdColorSpace); COSDictionary decodeParms = new COSDictionary(); decodeParms.setItem(COSName.BITS_PER_COMPONENT, COSInteger.get(bitsPerComponent)); decodeParms.setItem(COSName.PREDICTOR, COSInteger.get(15)); decodeParms.setItem(COSName.COLUMNS, COSInteger.get(w)); decodeParms.setItem(COSName.COLORS, COSInteger.get(srcCspace.getNumComponents())); imageXObject.getCOSObject().setItem(COSName.DECODE_PARMS, decodeParms); imageXObject.getCOSObject().setItem(COSName.SMASK, pdMask);
/** * Get the CIDSet stream. * * @return A stream containing a CIDSet. */ public PDStream getCIDSet() { COSObjectable cidSet = dic.getDictionaryObject(COSName.CID_SET); if (cidSet instanceof COSStream) { return new PDStream((COSStream) cidSet); } return null; }
Encoding encoding) throws IOException dict.setItem(COSName.SUBTYPE, COSName.TYPE1); byte[] pfbBytes = IOUtils.toByteArray(pfbStream); PfbParser pfbParser = new PfbParser(pfbBytes); type1 = Type1Font.createWithPFB(pfbBytes); PDStream fontStream = new PDStream(doc, pfbParser.getInputStream(), COSName.FLATE_DECODE); fontStream.getCOSObject().setInt("Length", pfbParser.size()); for (int i = 0; i < pfbParser.getLengths().length; i++) fontStream.getCOSObject().setInt("Length" + (i + 1), pfbParser.getLengths()[i]); dict.setItem(COSName.FONT_DESC, fd); dict.setName(COSName.BASE_FONT, type1.getName());
if (widget.getCOSObject().getDictionaryObject(COSName.DA) != null) if (rect == null) widget.getCOSObject().removeItem(COSName.AP); LOG.warn("widget of field " + field.getFullyQualifiedName() + " has no rectangle, no appearance stream created"); continue; widget.getCOSObject().getDictionaryObject(COSName.AP) != null) if (widget.getAppearanceCharacteristics() != null || appearanceStream.getContentStream().getLength() == 0)
/** * Creates a new ICC color space using the PDF array. * * @param iccArray the ICC stream object * @throws IOException if there is an error reading the ICC profile or if the parameter * is invalid. */ public PDICCBased(COSArray iccArray) throws IOException { if (iccArray.size() < 2) { throw new IOException("ICCBased colorspace array must have two elements"); } if (!(iccArray.getObject(1) instanceof COSStream)) { throw new IOException("ICCBased colorspace array must have a stream as second element"); } useOnlyAlternateColorSpace = System .getProperty("org.apache.pdfbox.rendering.UseAlternateInsteadOfICCColorSpace") != null; array = iccArray; stream = new PDStream((COSStream) iccArray.getObject(1)); loadICCProfile(); }
public void addCompression() List<COSName> filters = getFilters(); if (filters == null) try byte[] bytes = IOUtils.toByteArray(stream.createInputStream()); out = stream.createOutputStream(COSName.FLATE_DECODE); out.write(bytes); IOUtils.closeQuietly(out); setFilters(filters);
/** * This will copy the stream into a byte array. * * @return The byte array of the filteredStream. * @throws IOException if an I/O error occurs. */ public byte[] toByteArray() throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); try (InputStream is = createInputStream()) { IOUtils.copy(is, output); } return output.toByteArray(); }
COSBase alternate = stream.getCOSObject().getDictionaryObject(COSName.ALTERNATE); COSArray alternateArray; if(alternate == null) alternateArray = new COSArray(); int numComponents = getNumberOfComponents(); COSName csName; throw new IOException("Unknown color space number of components:" + numComponents); alternateArray.add(csName); alternateArray = new COSArray(); alternateArray.add(alternate);
PDPage importedPage = new PDPage(new COSDictionary(page.getCOSObject()), resourceCache); PDStream dest = new PDStream(this, page.getContents(), COSName.FLATE_DECODE); importedPage.setContents(dest); addPage(importedPage); importedPage.setMediaBox(page.getMediaBox()); importedPage.setRotation(page.getRotation()); if (page.getResources() != null && !page.getCOSObject().containsKey(COSName.RESOURCES))