/** Creates a JavaScript action. If the JavaScript is smaller than * 50 characters it will be placed as a string, otherwise it will * be placed as a compressed stream. * @param code the JavaScript code * @param writer the writer for this action * @param unicode select JavaScript unicode. Note that the internal * Acrobat JavaScript engine does not support unicode, * so this may or may not work for you * @return the JavaScript action */ public static PdfAction JavaScript(string code, PdfWriter writer, bool unicode) { PdfAction js = new PdfAction(); js.Put(PdfName.S, PdfName.JAVASCRIPT); if (unicode && code.Length < 50) { js.Put(PdfName.JS, new PdfString(code, PdfObject.TEXT_UNICODE)); } else if (!unicode && code.Length < 100) { js.Put(PdfName.JS, new PdfString(code)); } else { try { byte[] b = PdfEncodings.ConvertToBytes(code, unicode ? PdfObject.TEXT_UNICODE : PdfObject.TEXT_PDFDOCENCODING); PdfStream stream = new PdfStream(b); stream.FlateCompress(writer.CompressionLevel); js.Put(PdfName.JS, writer.AddToBody(stream).IndirectReference); } catch { js.Put(PdfName.JS, new PdfString(code)); } } return(js); }
/** * Gets the stream representing this object. * * @param compressionLevel the compressionLevel * @return the stream representing this template * @since 2.1.3 (replacing the method without param compressionLevel) * @throws IOException */ internal override PdfStream GetFormXObject(int compressionLevel) { PdfStream s = new PdfStream(content.ToByteArray()); s.Put(PdfName.TYPE, PdfName.XOBJECT); s.Put(PdfName.SUBTYPE, PdfName.PS); s.FlateCompress(compressionLevel); return(s); }
/** * Sets the XFA key from a byte array. The old XFA is erased. * @param form the data * @param reader the reader * @param writer the writer * @throws java.io.IOException on error */ public static void SetXfa(XfaForm form, PdfReader reader, PdfWriter writer) { PdfDictionary af = (PdfDictionary)PdfReader.GetPdfObjectRelease(reader.Catalog.Get(PdfName.ACROFORM)); if (af == null) { return; } PdfObject xfa = GetXfaObject(reader); if (xfa.IsArray()) { PdfArray ar = (PdfArray)xfa; int t = -1; int d = -1; for (int k = 0; k < ar.Size; k += 2) { PdfString s = ar.GetAsString(k); if ("template".Equals(s.ToString())) { t = k + 1; } if ("datasets".Equals(s.ToString())) { d = k + 1; } } if (t > -1 && d > -1) { reader.KillXref(ar.GetAsIndirectObject(t)); reader.KillXref(ar.GetAsIndirectObject(d)); PdfStream tStream = new PdfStream(SerializeDoc(form.templateNode)); tStream.FlateCompress(writer.CompressionLevel); ar[t] = writer.AddToBody(tStream).IndirectReference; PdfStream dStream = new PdfStream(SerializeDoc(form.datasetsNode)); dStream.FlateCompress(writer.CompressionLevel); ar[d] = writer.AddToBody(dStream).IndirectReference; af.Put(PdfName.XFA, new PdfArray(ar)); return; } } reader.KillXref(af.Get(PdfName.XFA)); PdfStream str = new PdfStream(SerializeDoc(form.domDocument)); str.FlateCompress(writer.CompressionLevel); PdfIndirectReference refe = writer.AddToBody(str).IndirectReference; af.Put(PdfName.XFA, refe); }
/** Creates a ToUnicode CMap to allow copy and paste from Acrobat. * @param metrics metrics[0] contains the glyph index and metrics[2] * contains the Unicode code * @throws DocumentException on error * @return the stream representing this CMap or <CODE>null</CODE> */ private PdfStream GetToUnicode(Object[] metrics) { if (metrics.Length == 0) { return(null); } StringBuilder buf = new StringBuilder( "/CIDInit /ProcSet findresource begin\n" + "12 dict begin\n" + "begincmap\n" + "/CIDSystemInfo\n" + "<< /Registry (TTX+0)\n" + "/Ordering (T42UV)\n" + "/Supplement 0\n" + ">> def\n" + "/CMapName /TTX+0 def\n" + "/CMapType 2 def\n" + "1 begincodespacerange\n" + "<0000><FFFF>\n" + "endcodespacerange\n"); int size = 0; for (int k = 0; k < metrics.Length; ++k) { if (size == 0) { if (k != 0) { buf.Append("endbfrange\n"); } size = Math.Min(100, metrics.Length - k); buf.Append(size).Append(" beginbfrange\n"); } --size; int[] metric = (int[])metrics[k]; string fromTo = ToHex(metric[0]); buf.Append(fromTo).Append(fromTo).Append(ToHex(metric[2])).Append('\n'); } buf.Append( "endbfrange\n" + "endcmap\n" + "CMapName currentdict /CMap defineresource pop\n" + "end end\n"); string s = buf.ToString(); PdfStream stream = new PdfStream(PdfEncodings.ConvertToBytes(s, null)); stream.FlateCompress(compressionLevel); return(stream); }
/** * Returns the CrossReferenceTable of the <CODE>Body</CODE>. * @param os * @param root * @param info * @param encryption * @param fileID * @param prevxref * @throws IOException */ internal void WriteCrossReferenceTable(Stream os, PdfIndirectReference root, PdfIndirectReference info, PdfIndirectReference encryption, PdfObject fileID, int prevxref) { int refNumber = 0; if (writer.FullCompression) { FlushObjStm(); refNumber = IndirectReferenceNumber; xrefs[new PdfCrossReference(refNumber, position)] = null; } int first = ((PdfCrossReference)xrefs.GetMinKey()).Refnum; int len = 0; ArrayList sections = new ArrayList(); foreach (PdfCrossReference entry in xrefs.Keys) { if (first + len == entry.Refnum) ++len; else { sections.Add(first); sections.Add(len); first = entry.Refnum; len = 1; } } sections.Add(first); sections.Add(len); if (writer.FullCompression) { int mid = 4; uint mask = 0xff000000; for (; mid > 1; --mid) { if ((mask & position) != 0) break; mask >>= 8; } ByteBuffer buf = new ByteBuffer(); foreach (PdfCrossReference entry in xrefs.Keys) { entry.ToPdf(mid, buf); } PdfStream xr = new PdfStream(buf.ToByteArray()); buf = null; xr.FlateCompress(writer.CompressionLevel); xr.Put(PdfName.SIZE, new PdfNumber(Size)); xr.Put(PdfName.ROOT, root); if (info != null) { xr.Put(PdfName.INFO, info); } if (encryption != null) xr.Put(PdfName.ENCRYPT, encryption); if (fileID != null) xr.Put(PdfName.ID, fileID); xr.Put(PdfName.W, new PdfArray(new int[]{1, mid, 2})); xr.Put(PdfName.TYPE, PdfName.XREF); PdfArray idx = new PdfArray(); for (int k = 0; k < sections.Count; ++k) idx.Add(new PdfNumber((int)sections[k])); xr.Put(PdfName.INDEX, idx); if (prevxref > 0) xr.Put(PdfName.PREV, new PdfNumber(prevxref)); PdfEncryption enc = writer.crypto; writer.crypto = null; PdfIndirectObject indirect = new PdfIndirectObject(refNumber, xr, writer); indirect.WriteTo(writer.Os); writer.crypto = enc; } else { byte[] tmp = GetISOBytes("xref\n"); os.Write(tmp, 0, tmp.Length); IEnumerator i = xrefs.Keys; i.MoveNext(); for (int k = 0; k < sections.Count; k += 2) { first = (int)sections[k]; len = (int)sections[k + 1]; tmp = GetISOBytes(first.ToString()); os.Write(tmp, 0, tmp.Length); os.WriteByte((byte)' '); tmp = GetISOBytes(len.ToString()); os.Write(tmp, 0, tmp.Length); os.WriteByte((byte)'\n'); while (len-- > 0) { ((PdfCrossReference)i.Current).ToPdf(os); i.MoveNext(); } } } }
internal void FlushObjStm() { if (numObj == 0) return; int first = index.Size; index.Append(streamObjects); PdfStream stream = new PdfStream(index.ToByteArray()); stream.FlateCompress(writer.CompressionLevel); 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; }
/** Creates a ToUnicode CMap to allow copy and paste from Acrobat. * @param metrics metrics[0] contains the glyph index and metrics[2] * contains the Unicode code * @throws DocumentException on error * @return the stream representing this CMap or <CODE>null</CODE> */ private PdfStream GetToUnicode(Object[] metrics) { if (metrics.Length == 0) return null; StringBuilder buf = new StringBuilder( "/CIDInit /ProcSet findresource begin\n" + "12 dict begin\n" + "begincmap\n" + "/CIDSystemInfo\n" + "<< /Registry (TTX+0)\n" + "/Ordering (T42UV)\n" + "/Supplement 0\n" + ">> def\n" + "/CMapName /TTX+0 def\n" + "/CMapType 2 def\n" + "1 begincodespacerange\n" + "<0000><FFFF>\n" + "endcodespacerange\n"); int size = 0; for (int k = 0; k < metrics.Length; ++k) { if (size == 0) { if (k != 0) { buf.Append("endbfrange\n"); } size = Math.Min(100, metrics.Length - k); buf.Append(size).Append(" beginbfrange\n"); } --size; int[] metric = (int[])metrics[k]; string fromTo = ToHex(metric[0]); buf.Append(fromTo).Append(fromTo).Append(ToHex(metric[2])).Append('\n'); } buf.Append( "endbfrange\n" + "endcmap\n" + "CMapName currentdict /CMap defineresource pop\n" + "end end\n"); string s = buf.ToString(); PdfStream stream = new PdfStream(PdfEncodings.ConvertToBytes(s, null)); stream.FlateCompress(compressionLevel); return stream; }
/** Outputs to the writer the font dictionaries and streams. * @param writer the writer for this document * @param ref the font indirect reference * @param parms several parameters that depend on the font type * @throws IOException on error * @throws DocumentException error in generating the object */ internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms) { Hashtable longTag = (Hashtable)parms[0]; AddRangeUni(longTag, true, subset); ArrayList tmp = new ArrayList(); foreach (object o in longTag.Values) { tmp.Add(o); } Object[] metrics = tmp.ToArray(); Array.Sort(metrics, this); PdfIndirectReference ind_font = null; PdfObject pobj = null; PdfIndirectObject obj = null; PdfIndirectReference cidset = null; if (writer.PDFXConformance == PdfWriter.PDFA1A || writer.PDFXConformance == PdfWriter.PDFA1B) { PdfStream stream; if (metrics.Length == 0) { stream = new PdfStream(new byte[]{(byte)0x80}); } else { int top = ((int[])metrics[metrics.Length - 1])[0]; byte[] bt = new byte[top / 8 + 1]; for (int k = 0; k < metrics.Length; ++k) { int v = ((int[])metrics[k])[0]; bt[v / 8] |= rotbits[v % 8]; } stream = new PdfStream(bt); stream.FlateCompress(compressionLevel); } cidset = writer.AddToBody(stream).IndirectReference; } // sivan: cff if (cff) { byte[] b = ReadCffFont(); if (subset || subsetRanges != null) { CFFFontSubset cffs = new CFFFontSubset(new RandomAccessFileOrArray(b),longTag); b = cffs.Process((cffs.GetNames())[0] ); } pobj = new StreamFont(b, "CIDFontType0C", compressionLevel); obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } else { byte[] b; if (subset || directoryOffset != 0) { TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), longTag, directoryOffset, false, false); b = sb.Process(); } else { b = GetFullFont(); } int[] lengths = new int[]{b.Length}; pobj = new StreamFont(b, lengths, compressionLevel); obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } String subsetPrefix = ""; if (subset) subsetPrefix = CreateSubsetPrefix(); PdfDictionary dic = GetFontDescriptor(ind_font, subsetPrefix, cidset); obj = writer.AddToBody(dic); ind_font = obj.IndirectReference; pobj = GetCIDFontType2(ind_font, subsetPrefix, metrics); obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; pobj = GetToUnicode(metrics); PdfIndirectReference toUnicodeRef = null; if (pobj != null) { obj = writer.AddToBody(pobj); toUnicodeRef = obj.IndirectReference; } pobj = GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef); writer.AddToBody(pobj, piref); }
/** Outputs to the writer the font dictionaries and streams. * @param writer the writer for this document * @param ref the font indirect reference * @param parms several parameters that depend on the font type * @throws IOException on error * @throws DocumentException error in generating the object */ internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms) { Hashtable longTag = (Hashtable)parms[0]; AddRangeUni(longTag, true, subset); ArrayList tmp = new ArrayList(); foreach (object o in longTag.Values) { tmp.Add(o); } Object[] metrics = tmp.ToArray(); Array.Sort(metrics, this); PdfIndirectReference ind_font = null; PdfObject pobj = null; PdfIndirectObject obj = null; PdfIndirectReference cidset = null; if (writer.PDFXConformance == PdfWriter.PDFA1A || writer.PDFXConformance == PdfWriter.PDFA1B) { PdfStream stream; if (metrics.Length == 0) { stream = new PdfStream(new byte[] { (byte)0x80 }); } else { int top = ((int[])metrics[metrics.Length - 1])[0]; byte[] bt = new byte[top / 8 + 1]; for (int k = 0; k < metrics.Length; ++k) { int v = ((int[])metrics[k])[0]; bt[v / 8] |= rotbits[v % 8]; } stream = new PdfStream(bt); stream.FlateCompress(compressionLevel); } cidset = writer.AddToBody(stream).IndirectReference; } // sivan: cff if (cff) { byte[] b = ReadCffFont(); if (subset || subsetRanges != null) { CFFFontSubset cffs = new CFFFontSubset(new RandomAccessFileOrArray(b), longTag); b = cffs.Process((cffs.GetNames())[0]); } pobj = new StreamFont(b, "CIDFontType0C", compressionLevel); obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } else { byte[] b; if (subset || directoryOffset != 0) { TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), longTag, directoryOffset, false, false); b = sb.Process(); } else { b = GetFullFont(); } int[] lengths = new int[] { b.Length }; pobj = new StreamFont(b, lengths, compressionLevel); obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } String subsetPrefix = ""; if (subset) { subsetPrefix = CreateSubsetPrefix(); } PdfDictionary dic = GetFontDescriptor(ind_font, subsetPrefix, cidset); obj = writer.AddToBody(dic); ind_font = obj.IndirectReference; pobj = GetCIDFontType2(ind_font, subsetPrefix, metrics); obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; pobj = GetToUnicode(metrics); PdfIndirectReference toUnicodeRef = null; if (pobj != null) { obj = writer.AddToBody(pobj); toUnicodeRef = obj.IndirectReference; } pobj = GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef); writer.AddToBody(pobj, piref); }
public void AlterContents() { if (over == null && under == null) return; PdfArray ar = null; PdfObject content = PdfReader.GetPdfObject(pageN.Get(PdfName.CONTENTS), pageN); if (content == null) { ar = new PdfArray(); pageN.Put(PdfName.CONTENTS, ar); } else if (content.IsArray()) { ar = (PdfArray)content; } else if (content.IsStream()) { ar = new PdfArray(); ar.Add(pageN.Get(PdfName.CONTENTS)); pageN.Put(PdfName.CONTENTS, ar); } else { ar = new PdfArray(); pageN.Put(PdfName.CONTENTS, ar); } ByteBuffer out_p = new ByteBuffer(); if (under != null) { out_p.Append(PdfContents.SAVESTATE); ApplyRotation(pageN, out_p); out_p.Append(under.InternalBuffer); out_p.Append(PdfContents.RESTORESTATE); } if (over != null) out_p.Append(PdfContents.SAVESTATE); PdfStream stream = new PdfStream(out_p.ToByteArray()); stream.FlateCompress(cstp.CompressionLevel); PdfIndirectReference ref1 = cstp.AddToBody(stream).IndirectReference; ar.AddFirst(ref1); out_p.Reset(); if (over != null) { out_p.Append(' '); out_p.Append(PdfContents.RESTORESTATE); out_p.Append(PdfContents.SAVESTATE); ApplyRotation(pageN, out_p); out_p.Append(over.InternalBuffer); out_p.Append(PdfContents.RESTORESTATE); stream = new PdfStream(out_p.ToByteArray()); stream.FlateCompress(cstp.CompressionLevel); ar.Add(cstp.AddToBody(stream).IndirectReference); } pageN.Put(PdfName.RESOURCES, pageResources.Resources); }
internal void AlterContents() { foreach (PageStamp ps in pagesToContent.Values) { PdfDictionary pageN = ps.pageN; MarkUsed(pageN); PdfArray ar = null; PdfObject content = PdfReader.GetPdfObject(pageN.Get(PdfName.CONTENTS), pageN); if (content == null) { ar = new PdfArray(); pageN.Put(PdfName.CONTENTS, ar); } else if (content.IsArray()) { ar = (PdfArray)content; MarkUsed(ar); } else if (content.IsStream()) { ar = new PdfArray(); ar.Add(pageN.Get(PdfName.CONTENTS)); pageN.Put(PdfName.CONTENTS, ar); } else { ar = new PdfArray(); pageN.Put(PdfName.CONTENTS, ar); } ByteBuffer out_p = new ByteBuffer(); if (ps.under != null) { out_p.Append(PdfContents.SAVESTATE); ApplyRotation(pageN, out_p); out_p.Append(ps.under.InternalBuffer); out_p.Append(PdfContents.RESTORESTATE); } if (ps.over != null) out_p.Append(PdfContents.SAVESTATE); PdfStream stream = new PdfStream(out_p.ToByteArray()); stream.FlateCompress(compressionLevel); ar.AddFirst(AddToBody(stream).IndirectReference); out_p.Reset(); if (ps.over != null) { out_p.Append(' '); out_p.Append(PdfContents.RESTORESTATE); ByteBuffer buf = ps.over.InternalBuffer; out_p.Append(buf.Buffer, 0, ps.replacePoint); out_p.Append(PdfContents.SAVESTATE); ApplyRotation(pageN, out_p); out_p.Append(buf.Buffer, ps.replacePoint, buf.Size - ps.replacePoint); out_p.Append(PdfContents.RESTORESTATE); stream = new PdfStream(out_p.ToByteArray()); stream.FlateCompress(compressionLevel); ar.Add(AddToBody(stream).IndirectReference); } AlterResources(ps); } }
internal override void WriteFont(PdfWriter writer, PdfIndirectReference piRef, Object[] oParams) { if (this.writer != writer) throw new ArgumentException("Type3 font used with the wrong PdfWriter"); // Get first & lastchar ... int firstChar = 0; while( firstChar < usedSlot.Length && !usedSlot[firstChar] ) firstChar++; if ( firstChar == usedSlot.Length ) { throw new DocumentException( "No glyphs defined for Type3 font" ); } int lastChar = usedSlot.Length - 1; while( lastChar >= firstChar && !usedSlot[lastChar] ) lastChar--; int[] widths = new int[lastChar - firstChar + 1]; int[] invOrd = new int[lastChar - firstChar + 1]; int invOrdIndx = 0, w = 0; for( int u = firstChar; u<=lastChar; u++, w++ ) { if ( usedSlot[u] ) { invOrd[invOrdIndx++] = u; widths[w] = widths3[u]; } } PdfArray diffs = new PdfArray(); PdfDictionary charprocs = new PdfDictionary(); int last = -1; for (int k = 0; k < invOrdIndx; ++k) { int c = invOrd[k]; if (c > last) { last = c; diffs.Add(new PdfNumber(last)); } ++last; int c2 = invOrd[k]; String s = GlyphList.UnicodeToName(c2); if (s == null) s = "a" + c2; PdfName n = new PdfName(s); diffs.Add(n); Type3Glyph glyph = (Type3Glyph)char2glyph[(char)c2]; PdfStream stream = new PdfStream(glyph.ToPdf(null)); stream.FlateCompress(compressionLevel); PdfIndirectReference refp = writer.AddToBody(stream).IndirectReference; charprocs.Put(n, refp); } PdfDictionary font = new PdfDictionary(PdfName.FONT); font.Put(PdfName.SUBTYPE, PdfName.TYPE3); if (colorized) font.Put(PdfName.FONTBBOX, new PdfRectangle(0, 0, 0, 0)); else font.Put(PdfName.FONTBBOX, new PdfRectangle(llx, lly, urx, ury)); font.Put(PdfName.FONTMATRIX, new PdfArray(new float[]{0.001f, 0, 0, 0.001f, 0, 0})); font.Put(PdfName.CHARPROCS, writer.AddToBody(charprocs).IndirectReference); PdfDictionary encoding = new PdfDictionary(); encoding.Put(PdfName.DIFFERENCES, diffs); font.Put(PdfName.ENCODING, writer.AddToBody(encoding).IndirectReference); font.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar)); font.Put(PdfName.LASTCHAR, new PdfNumber(lastChar)); font.Put(PdfName.WIDTHS, writer.AddToBody(new PdfArray(widths)).IndirectReference); if (pageResources.HasResources()) font.Put(PdfName.RESOURCES, writer.AddToBody(pageResources.Resources).IndirectReference); writer.AddToBody(font, piRef); }
/** Creates a JavaScript action. If the JavaScript is smaller than * 50 characters it will be placed as a string, otherwise it will * be placed as a compressed stream. * @param code the JavaScript code * @param writer the writer for this action * @param unicode select JavaScript unicode. Note that the internal * Acrobat JavaScript engine does not support unicode, * so this may or may not work for you * @return the JavaScript action */ public static PdfAction JavaScript(string code, PdfWriter writer, bool unicode) { PdfAction js = new PdfAction(); js.Put(PdfName.S, PdfName.JAVASCRIPT); if (unicode && code.Length < 50) { js.Put(PdfName.JS, new PdfString(code, PdfObject.TEXT_UNICODE)); } else if (!unicode && code.Length < 100) { js.Put(PdfName.JS, new PdfString(code)); } else { try { byte[] b = PdfEncodings.ConvertToBytes(code, unicode ? PdfObject.TEXT_UNICODE : PdfObject.TEXT_PDFDOCENCODING); PdfStream stream = new PdfStream(b); stream.FlateCompress(writer.CompressionLevel); js.Put(PdfName.JS, writer.AddToBody(stream).IndirectReference); } catch { js.Put(PdfName.JS, new PdfString(code)); } } return js; }
public void AlterContents() { if (over == null && under == null) { return; } PdfArray ar = null; PdfObject content = PdfReader.GetPdfObject(pageN.Get(PdfName.CONTENTS), pageN); if (content == null) { ar = new PdfArray(); pageN.Put(PdfName.CONTENTS, ar); } else if (content.IsArray()) { ar = (PdfArray)content; } else if (content.IsStream()) { ar = new PdfArray(); ar.Add(pageN.Get(PdfName.CONTENTS)); pageN.Put(PdfName.CONTENTS, ar); } else { ar = new PdfArray(); pageN.Put(PdfName.CONTENTS, ar); } ByteBuffer out_p = new ByteBuffer(); if (under != null) { out_p.Append(PdfContents.SAVESTATE); ApplyRotation(pageN, out_p); out_p.Append(under.InternalBuffer); out_p.Append(PdfContents.RESTORESTATE); } if (over != null) { out_p.Append(PdfContents.SAVESTATE); } PdfStream stream = new PdfStream(out_p.ToByteArray()); stream.FlateCompress(cstp.CompressionLevel); PdfIndirectReference ref1 = cstp.AddToBody(stream).IndirectReference; ar.AddFirst(ref1); out_p.Reset(); if (over != null) { out_p.Append(' '); out_p.Append(PdfContents.RESTORESTATE); out_p.Append(PdfContents.SAVESTATE); ApplyRotation(pageN, out_p); out_p.Append(over.InternalBuffer); out_p.Append(PdfContents.RESTORESTATE); stream = new PdfStream(out_p.ToByteArray()); stream.FlateCompress(cstp.CompressionLevel); ar.Add(cstp.AddToBody(stream).IndirectReference); } pageN.Put(PdfName.RESOURCES, pageResources.Resources); }
internal override void WriteFont(PdfWriter writer, PdfIndirectReference piRef, Object[] oParams) { if (this.writer != writer) { throw new ArgumentException("Type3 font used with the wrong PdfWriter"); } // Get first & lastchar ... int firstChar = 0; while (firstChar < usedSlot.Length && !usedSlot[firstChar]) { firstChar++; } if (firstChar == usedSlot.Length) { throw new DocumentException("No glyphs defined for Type3 font"); } int lastChar = usedSlot.Length - 1; while (lastChar >= firstChar && !usedSlot[lastChar]) { lastChar--; } int[] widths = new int[lastChar - firstChar + 1]; int[] invOrd = new int[lastChar - firstChar + 1]; int invOrdIndx = 0, w = 0; for (int u = firstChar; u <= lastChar; u++, w++) { if (usedSlot[u]) { invOrd[invOrdIndx++] = u; widths[w] = widths3[u]; } } PdfArray diffs = new PdfArray(); PdfDictionary charprocs = new PdfDictionary(); int last = -1; for (int k = 0; k < invOrdIndx; ++k) { int c = invOrd[k]; if (c > last) { last = c; diffs.Add(new PdfNumber(last)); } ++last; int c2 = invOrd[k]; String s = GlyphList.UnicodeToName(c2); if (s == null) { s = "a" + c2; } PdfName n = new PdfName(s); diffs.Add(n); Type3Glyph glyph = (Type3Glyph)char2glyph[(char)c2]; PdfStream stream = new PdfStream(glyph.ToPdf(null)); stream.FlateCompress(compressionLevel); PdfIndirectReference refp = writer.AddToBody(stream).IndirectReference; charprocs.Put(n, refp); } PdfDictionary font = new PdfDictionary(PdfName.FONT); font.Put(PdfName.SUBTYPE, PdfName.TYPE3); if (colorized) { font.Put(PdfName.FONTBBOX, new PdfRectangle(0, 0, 0, 0)); } else { font.Put(PdfName.FONTBBOX, new PdfRectangle(llx, lly, urx, ury)); } font.Put(PdfName.FONTMATRIX, new PdfArray(new float[] { 0.001f, 0, 0, 0.001f, 0, 0 })); font.Put(PdfName.CHARPROCS, writer.AddToBody(charprocs).IndirectReference); PdfDictionary encoding = new PdfDictionary(); encoding.Put(PdfName.DIFFERENCES, diffs); font.Put(PdfName.ENCODING, writer.AddToBody(encoding).IndirectReference); font.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar)); font.Put(PdfName.LASTCHAR, new PdfNumber(lastChar)); font.Put(PdfName.WIDTHS, writer.AddToBody(new PdfArray(widths)).IndirectReference); if (pageResources.HasResources()) { font.Put(PdfName.RESOURCES, writer.AddToBody(pageResources.Resources).IndirectReference); } writer.AddToBody(font, piRef); }
/** * Gets the stream representing this object. * * @param compressionLevel the compressionLevel * @return the stream representing this template * @since 2.1.3 (replacing the method without param compressionLevel) * @throws IOException */ internal override PdfStream GetFormXObject(int compressionLevel) { PdfStream s = new PdfStream(content.ToByteArray()); s.Put(PdfName.TYPE, PdfName.XOBJECT); s.Put(PdfName.SUBTYPE, PdfName.PS); s.FlateCompress(compressionLevel); return s; }