/** Returns the amount of memory currently used by the */ public long memoryUsed() { return pdfBytes.size(); } }
public static PdfObject createInfoId(byte[] id) { ByteBuffer buf = new ByteBuffer(90); buf.append('[').append('<'); for (int k = 0; k < 16; ++k) buf.appendHex(id[k]); buf.append('>').append('<'); id = createDocumentId(); for (int k = 0; k < 16; ++k) buf.appendHex(id[k]); buf.append('>').append(']'); return new PdfLiteral(buf.toByteArray()); }
/** * Changes the currentgray tint for filling paths (device dependent colors!). * <P> * Sets the color space to <B>DeviceGray</B> (or the <B>DefaultGray</B> color space), * and sets the gray tint to use for filling paths.</P> * * @param gray a value between 0 (black) and 1 (white) */ public void setGrayFill(float gray) { content.append(gray).append(" g").append_i(separator); }
/** * Appends a string representation of a <CODE>double</CODE> according * to the Pdf conventions. * @param d the <CODE>double</CODE> to be appended * @return a reference to this <CODE>ByteBuffer</CODE> object */ public ByteBuffer append(double d) { append(formatDouble(d, this)); return this; }
pageN.put(PdfName.CONTENTS, ar); ByteBuffer out = new ByteBuffer(); if (ps.under != null) { out.append(PdfContents.SAVESTATE); applyRotation(pageN, out); out.append(ps.under.getInternalBuffer()); out.append(PdfContents.RESTORESTATE); out.append(PdfContents.SAVESTATE); PdfStream stream = new PdfStream(out.toByteArray()); stream.flateCompress(this.compressionLevel); ar.addFirst(addToBody(stream).getIndirectReference()); out.reset(); if (ps.over != null) { out.append(' '); out.append(PdfContents.RESTORESTATE); ByteBuffer buf = ps.over.getInternalBuffer(); out.append(buf.getBuffer(), 0, ps.replacePoint); out.append(PdfContents.SAVESTATE); applyRotation(pageN, out); out.append(buf.getBuffer(), ps.replacePoint, buf.size() - ps.replacePoint); out.append(PdfContents.RESTORESTATE); stream = new PdfStream(out.toByteArray()); stream.flateCompress(this.compressionLevel); ar.add(addToBody(stream).getIndirectReference());
throw new DocumentException("preClose() must be called first."); //$NON-NLS-1$ final ByteBuffer bf = new ByteBuffer(); for (final Iterator it = update.getKeys().iterator(); it.hasNext();) { final PdfName key = (PdfName)it.next(); throw new IllegalArgumentException("The key " + key.toString() + " didn't reserve space in preClose()."); //$NON-NLS-1$ //$NON-NLS-2$ bf.reset(); obj.toPdf(null, bf); if (bf.size() > lit.getPosLength()) { throw new IllegalArgumentException("The key " + key.toString() + " is too big. Is " + bf.size() + ", reserved " + lit.getPosLength()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ System.arraycopy(bf.getBuffer(), 0, this.bout, lit.getPosition(), bf.size()); } else { this.raf.seek(lit.getPosition()); this.raf.write(bf.getBuffer(), 0, bf.size());
bout = sigout.getBuffer(); boutLen = sigout.size(); range[range.length - 1] = boutLen - range[range.length - 2]; ByteBuffer bf = new ByteBuffer(); bf.append('['); for (int k = 0; k < range.length; ++k) bf.append(range[k]).append(' '); bf.append(']'); System.arraycopy(bf.getBuffer(), 0, bout, byteRangePosition, bf.size()); int boutLen = (int)raf.length(); range[range.length - 1] = boutLen - range[range.length - 2]; ByteBuffer bf = new ByteBuffer(); bf.append('['); for (int k = 0; k < range.length; ++k) bf.append(range[k]).append(' '); bf.append(']'); raf.seek(byteRangePosition); raf.write(bf.getBuffer(), 0, bf.size());
pageN.put(PdfName.CONTENTS, ar); ByteBuffer out = new ByteBuffer(); if (under != null) { out.append(PdfContents.SAVESTATE); applyRotation(pageN, out); out.append(under.getInternalBuffer()); out.append(PdfContents.RESTORESTATE); out.append(PdfContents.SAVESTATE); PdfStream stream = new PdfStream(out.toByteArray()); stream.flateCompress(cstp.getCompressionLevel()); PdfIndirectReference ref1 = cstp.addToBody(stream).getIndirectReference(); ar.addFirst(ref1); out.reset(); if (over != null) { out.append(' '); out.append(PdfContents.RESTORESTATE); out.append(PdfContents.SAVESTATE); applyRotation(pageN, out); out.append(over.getInternalBuffer()); out.append(PdfContents.RESTORESTATE); stream = new PdfStream(out.toByteArray()); stream.flateCompress(cstp.getCompressionLevel()); ar.add(cstp.addToBody(stream).getIndirectReference());
private void flushObjStm() throws IOException { if (numObj == 0) return; int first = index.size(); index.append(streamObjects); PdfStream stream = new PdfStream(index.toByteArray()); stream.flateCompress(writer.getCompressionLevel()); stream.put(PdfName.TYPE, PdfName.OBJSTM); stream.put(PdfName.N, new PdfNumber(numObj)); stream.put(PdfName.FIRST, new PdfNumber(first)); add(stream, currentObjNum); index = null; streamObjects = null; numObj = 0; }
private void internalDispose(ByteBuffer buf) { int last = 0; int pos = 0; ByteBuffer buf2 = cb.getInternalBuffer(); if (kids != null) { for (int k = 0; k < kids.size(); k += 2) { pos = ((Integer)kids.get(k)).intValue(); PdfGraphics2D g2 = (PdfGraphics2D)kids.get(k + 1); g2.cb.restoreState(); g2.cb.restoreState(); buf.append(buf2.getBuffer(), last, pos - last); g2.dg2.dispose(); g2.dg2 = null; g2.internalDispose(buf); last = pos; } } buf.append(buf2.getBuffer(), last, buf2.size() - last); }
private PdfWriter.PdfBody.PdfCrossReference addToObjStm(PdfObject obj, int nObj) throws IOException { if (numObj >= OBJSINSTREAM) flushObjStm(); if (index == null) { index = new ByteBuffer(); streamObjects = new ByteBuffer(); currentObjNum = getIndirectReferenceNumber(); numObj = 0; } int p = streamObjects.size(); int idx = numObj++; PdfEncryption enc = writer.crypto; writer.crypto = null; obj.toPdf(writer, streamObjects); writer.crypto = enc; streamObjects.append(' '); index.append(nObj).append(' ').append(p).append(' '); return new PdfWriter.PdfBody.PdfCrossReference(2, nObj, currentObjNum, idx); }
/** * @see Graphics#dispose() */ public void dispose() { if (kid) return; if (!disposeCalled) { disposeCalled = true; cb.restoreState(); cb.restoreState(); dg2.dispose(); dg2 = null; if (kids != null) { ByteBuffer buf = new ByteBuffer(); internalDispose(buf); ByteBuffer buf2 = cb.getInternalBuffer(); buf2.reset(); buf2.append(buf); } } }
/** * Escapes a <CODE>byte</CODE> array according to the PDF conventions. * * @param b the <CODE>byte</CODE> array to escape * @return an escaped <CODE>byte</CODE> array */ static byte[] escapeString(byte b[]) { ByteBuffer content = new ByteBuffer(); escapeString(b, content); return content.toByteArray(); }
ByteBuffer buf = new ByteBuffer(length + 20); buf.append('/'); char c; char chars[] = name.toCharArray(); case '/': case '#': buf.append('#'); buf.append(Integer.toString(c, 16)); break; default: if (c >= 32 && c <= 126) buf.append(c); else { buf.append('#'); if (c < 16) buf.append('0'); buf.append(Integer.toString(c, 16)); return buf.toByteArray();
/** * @since 2.1.6 private is now protected */ protected void restoreCanvases(PdfContentByte[] canvases) { int last = PdfPTable.TEXTCANVAS + 1; for (int k = 0; k < last; ++k) { ByteBuffer bb = canvases[k].getInternalBuffer(); int p1 = bb.size(); canvases[k].restoreState(); if (p1 == canvasesPos[k * 2 + 1]) bb.setSize(canvasesPos[k * 2]); } }
/** * Outputs a <CODE>double</CODE> into a format suitable for the PDF. * @param d a double * @return the <CODE>String</CODE> representation of the <CODE>double</CODE> */ public static String formatDouble(double d) { return formatDouble(d, null); }
/** * Makes this <CODE>PdfContentByte</CODE> empty. * @param validateContent will call <code>sanityCheck()</code> if true. * @since 2.1.6 */ public void reset( boolean validateContent ) { content.reset(); if (validateContent) { sanityCheck(); } state = new GraphicState(); }
/** * You can fill the cache in advance if you want to. * * @param decimals */ public static void fillCache(int decimals) { int step = 1; switch(decimals) { case 0: step = 100; break; case 1: step = 10; break; } for (int i = 1; i < byteCacheSize; i += step) { if (byteCache[i] != null) continue; byteCache[i] = convertToBytes(i); } }
pageN.put(PdfName.CONTENTS, ar); ByteBuffer out = new ByteBuffer(); if (ps.under != null) { out.append(PdfContents.SAVESTATE); applyRotation(pageN, out); out.append(ps.under.getInternalBuffer()); out.append(PdfContents.RESTORESTATE); out.append(PdfContents.SAVESTATE); PdfStream stream = new PdfStream(out.toByteArray()); stream.flateCompress(compressionLevel); ar.addFirst(addToBody(stream).getIndirectReference()); out.reset(); if (ps.over != null) { out.append(' '); out.append(PdfContents.RESTORESTATE); ByteBuffer buf = ps.over.getInternalBuffer(); out.append(buf.getBuffer(), 0, ps.replacePoint); out.append(PdfContents.SAVESTATE); applyRotation(pageN, out); out.append(buf.getBuffer(), ps.replacePoint, buf.size() - ps.replacePoint); out.append(PdfContents.RESTORESTATE); stream = new PdfStream(out.toByteArray()); stream.flateCompress(compressionLevel); ar.add(addToBody(stream).getIndirectReference());
if (!preClosed) throw new DocumentException(MessageLocalization.getComposedMessage("preclose.must.be.called.first")); ByteBuffer bf = new ByteBuffer(); for (Iterator it = update.getKeys().iterator(); it.hasNext();) { PdfName key = (PdfName)it.next(); if (lit == null) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.key.1.didn.t.reserve.space.in.preclose", key.toString())); bf.reset(); obj.toPdf(null, bf); if (bf.size() > lit.getPosLength()) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.key.1.is.too.big.is.2.reserved.3", key.toString(), String.valueOf(bf.size()), String.valueOf(lit.getPosLength()))); if (tempFile == null) System.arraycopy(bf.getBuffer(), 0, bout, lit.getPosition(), bf.size()); else { raf.seek(lit.getPosition()); raf.write(bf.getBuffer(), 0, bf.size());