/** * 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(); } } } }
/** Adds the indirect reference of the destination page. * * @param page an indirect reference * @return true if the page reference was added */ public bool AddPage(PdfIndirectReference page) { if (!status) { AddFirst(page); status = true; return true; } return false; }
internal PdfObject[] AddSimpleProperty(Object prop, PdfIndirectReference refi) { if (!documentProperties.ContainsKey(prop)) { if (prop is IPdfOCG) PdfXConformanceImp.CheckPDFXConformance(this, PdfXConformanceImp.PDFXKEY_LAYER, null); documentProperties[prop] = new PdfObject[]{new PdfName("Pr" + (documentProperties.Count + 1)), refi}; } return (PdfObject[])documentProperties[prop]; }
/** * Adds a <CODE>PdfObject</CODE> to the body given an already existing * PdfIndirectReference. * <P> * This methods creates a <CODE>PdfIndirectObject</CODE> with the number given by * <CODE>ref</CODE>, containing the given <CODE>PdfObject</CODE>. * It also adds a <CODE>PdfCrossReference</CODE> for this object * to an <CODE>ArrayList</CODE> that will be used to build the * Cross-reference Table. * * @param object a <CODE>PdfObject</CODE> * @param ref a <CODE>PdfIndirectReference</CODE> * @return a <CODE>PdfIndirectObject</CODE> * @throws IOException */ internal PdfIndirectObject Add(PdfObject objecta, PdfIndirectReference refa) { return Add(objecta, refa.Number); }
/**Creates a Rendition action * @param file * @param fs * @param mimeType * @param ref * @return a Media Clip action * @throws IOException */ public static PdfAction Rendition(String file, PdfFileSpecification fs, String mimeType, PdfIndirectReference refi) { PdfAction js = new PdfAction(); js.Put(PdfName.S, PdfName.RENDITION); js.Put(PdfName.R, new PdfRendition(file, fs, mimeType)); js.Put(new PdfName("OP"), new PdfNumber(0)); js.Put(new PdfName("AN"), refi); return(js); }
/** * Adds an object to the PDF body. * @param object * @param ref * @param inObjStm * @return a PdfIndirectObject * @throws IOException */ public PdfIndirectObject AddToBody(PdfObject objecta, PdfIndirectReference refa, bool inObjStm) { PdfIndirectObject iobj = body.Add(objecta, refa, inObjStm); return iobj; }
// constructor /** * Constructs a <CODE>PdfImage</CODE>-object. * * @param image the <CODE>Image</CODE>-object * @param name the <CODE>PdfName</CODE> for this image * @throws BadPdfFormatException on error */ public PdfImage(Image image, String name, PdfIndirectReference maskRef) { this.name = new PdfName(name); Put(PdfName.TYPE, PdfName.XOBJECT); Put(PdfName.SUBTYPE, PdfName.IMAGE); Put(PdfName.WIDTH, new PdfNumber(image.Width)); Put(PdfName.HEIGHT, new PdfNumber(image.Height)); if (image.Layer != null) { Put(PdfName.OC, image.Layer.Ref); } if (image.IsMask() && (image.Bpc == 1 || image.Bpc > 0xff)) { Put(PdfName.IMAGEMASK, PdfBoolean.PDFTRUE); } if (maskRef != null) { if (image.Smask) { Put(PdfName.SMASK, maskRef); } else { Put(PdfName.MASK, maskRef); } } if (image.IsMask() && image.Inverted) { Put(PdfName.DECODE, new PdfLiteral("[1 0]")); } if (image.Interpolation) { Put(PdfName.INTERPOLATE, PdfBoolean.PDFTRUE); } Stream isp = null; try { // Raw Image data if (image.IsImgRaw()) { // will also have the CCITT parameters int colorspace = image.Colorspace; int[] transparency = image.Transparency; if (transparency != null && !image.IsMask() && maskRef == null) { String s = "["; for (int k = 0; k < transparency.Length; ++k) { s += transparency[k] + " "; } s += "]"; Put(PdfName.MASK, new PdfLiteral(s)); } bytes = image.RawData; Put(PdfName.LENGTH, new PdfNumber(bytes.Length)); int bpc = image.Bpc; if (bpc > 0xff) { if (!image.IsMask()) { Put(PdfName.COLORSPACE, PdfName.DEVICEGRAY); } Put(PdfName.BITSPERCOMPONENT, new PdfNumber(1)); Put(PdfName.FILTER, PdfName.CCITTFAXDECODE); int k = bpc - Image.CCITTG3_1D; PdfDictionary decodeparms = new PdfDictionary(); if (k != 0) { decodeparms.Put(PdfName.K, new PdfNumber(k)); } if ((colorspace & Image.CCITT_BLACKIS1) != 0) { decodeparms.Put(PdfName.BLACKIS1, PdfBoolean.PDFTRUE); } if ((colorspace & Image.CCITT_ENCODEDBYTEALIGN) != 0) { decodeparms.Put(PdfName.ENCODEDBYTEALIGN, PdfBoolean.PDFTRUE); } if ((colorspace & Image.CCITT_ENDOFLINE) != 0) { decodeparms.Put(PdfName.ENDOFLINE, PdfBoolean.PDFTRUE); } if ((colorspace & Image.CCITT_ENDOFBLOCK) != 0) { decodeparms.Put(PdfName.ENDOFBLOCK, PdfBoolean.PDFFALSE); } decodeparms.Put(PdfName.COLUMNS, new PdfNumber(image.Width)); decodeparms.Put(PdfName.ROWS, new PdfNumber(image.Height)); Put(PdfName.DECODEPARMS, decodeparms); } else { switch (colorspace) { case 1: Put(PdfName.COLORSPACE, PdfName.DEVICEGRAY); if (image.Inverted) { Put(PdfName.DECODE, new PdfLiteral("[1 0]")); } break; case 3: Put(PdfName.COLORSPACE, PdfName.DEVICERGB); if (image.Inverted) { Put(PdfName.DECODE, new PdfLiteral("[1 0 1 0 1 0]")); } break; case 4: default: Put(PdfName.COLORSPACE, PdfName.DEVICECMYK); if (image.Inverted) { Put(PdfName.DECODE, new PdfLiteral("[1 0 1 0 1 0 1 0]")); } break; } PdfDictionary additional = image.Additional; if (additional != null) { Merge(additional); } if (image.IsMask() && (image.Bpc == 1 || image.Bpc > 8)) { Remove(PdfName.COLORSPACE); } Put(PdfName.BITSPERCOMPONENT, new PdfNumber(image.Bpc)); if (image.Deflated) { Put(PdfName.FILTER, PdfName.FLATEDECODE); } else { FlateCompress(image.CompressionLevel); } } return; } // GIF, JPEG or PNG String errorID; if (image.RawData == null) { isp = WebRequest.Create(image.Url).GetResponse().GetResponseStream(); errorID = image.Url.ToString(); } else { isp = new MemoryStream(image.RawData); errorID = "Byte array"; } switch (image.Type) { case Image.JPEG: Put(PdfName.FILTER, PdfName.DCTDECODE); switch (image.Colorspace) { case 1: Put(PdfName.COLORSPACE, PdfName.DEVICEGRAY); break; case 3: Put(PdfName.COLORSPACE, PdfName.DEVICERGB); break; default: Put(PdfName.COLORSPACE, PdfName.DEVICECMYK); if (image.Inverted) { Put(PdfName.DECODE, new PdfLiteral("[1 0 1 0 1 0 1 0]")); } break; } Put(PdfName.BITSPERCOMPONENT, new PdfNumber(8)); if (image.RawData != null) { bytes = image.RawData; Put(PdfName.LENGTH, new PdfNumber(bytes.Length)); return; } streamBytes = new MemoryStream(); TransferBytes(isp, streamBytes, -1); break; case Image.JPEG2000: Put(PdfName.FILTER, PdfName.JPXDECODE); if (image.Colorspace > 0) { switch (image.Colorspace) { case 1: Put(PdfName.COLORSPACE, PdfName.DEVICEGRAY); break; case 3: Put(PdfName.COLORSPACE, PdfName.DEVICERGB); break; default: Put(PdfName.COLORSPACE, PdfName.DEVICECMYK); break; } Put(PdfName.BITSPERCOMPONENT, new PdfNumber(image.Bpc)); } if (image.RawData != null) { bytes = image.RawData; Put(PdfName.LENGTH, new PdfNumber(bytes.Length)); return; } streamBytes = new MemoryStream(); TransferBytes(isp, streamBytes, -1); break; case Image.JBIG2: Put(PdfName.FILTER, PdfName.JBIG2DECODE); Put(PdfName.COLORSPACE, PdfName.DEVICEGRAY); Put(PdfName.BITSPERCOMPONENT, new PdfNumber(1)); if (image.RawData != null) { bytes = image.RawData; Put(PdfName.LENGTH, new PdfNumber(bytes.Length)); return; } streamBytes = new MemoryStream(); TransferBytes(isp, streamBytes, -1); break; default: throw new IOException(errorID + " is an unknown Image format."); } Put(PdfName.LENGTH, new PdfNumber(streamBytes.Length)); } finally { if (isp != null) { try{ isp.Close(); } catch { // empty on purpose } } } }
/** * Creates a name tree. * @param items the item of the name tree. The key is a <CODE>String</CODE> * and the value is a <CODE>PdfObject</CODE>. Note that although the * keys are strings only the lower byte is used and no check is made for chars * with the same lower byte and different upper byte. This will generate a wrong * tree name. * @param writer the writer * @throws IOException on error * @return the dictionary with the name tree. This dictionary is the one * generally pointed to by the key /Dests, for example */ public static PdfDictionary WriteTree(Hashtable items, PdfWriter writer) { if (items.Count == 0) return null; String[] names = new String[items.Count]; items.Keys.CopyTo(names, 0); Array.Sort(names); if (names.Length <= leafSize) { PdfDictionary dic = new PdfDictionary(); PdfArray ar = new PdfArray(); for (int k = 0; k < names.Length; ++k) { ar.Add(new PdfString(names[k], null)); ar.Add((PdfObject)items[names[k]]); } dic.Put(PdfName.NAMES, ar); return dic; } int skip = leafSize; PdfIndirectReference[] kids = new PdfIndirectReference[(names.Length + leafSize - 1) / leafSize]; for (int k = 0; k < kids.Length; ++k) { int offset = k * leafSize; int end = Math.Min(offset + leafSize, names.Length); PdfDictionary dic = new PdfDictionary(); PdfArray arr = new PdfArray(); arr.Add(new PdfString(names[offset], null)); arr.Add(new PdfString(names[end - 1], null)); dic.Put(PdfName.LIMITS, arr); arr = new PdfArray(); for (; offset < end; ++offset) { arr.Add(new PdfString(names[offset], null)); arr.Add((PdfObject)items[names[offset]]); } dic.Put(PdfName.NAMES, arr); kids[k] = writer.AddToBody(dic).IndirectReference; } int top = kids.Length; while (true) { if (top <= leafSize) { PdfArray arr = new PdfArray(); for (int k = 0; k < top; ++k) arr.Add(kids[k]); PdfDictionary dic = new PdfDictionary(); dic.Put(PdfName.KIDS, arr); return dic; } skip *= leafSize; int tt = (names.Length + skip - 1 )/ skip; for (int k = 0; k < tt; ++k) { int offset = k * leafSize; int end = Math.Min(offset + leafSize, top); PdfDictionary dic = new PdfDictionary(); PdfArray arr = new PdfArray(); arr.Add(new PdfString(names[k * skip], null)); arr.Add(new PdfString(names[Math.Min((k + 1) * skip, names.Length) - 1], null)); dic.Put(PdfName.LIMITS, arr); arr = new PdfArray(); for (; offset < end; ++offset) { arr.Add(kids[offset]); } dic.Put(PdfName.KIDS, arr); kids[k] = writer.AddToBody(dic).IndirectReference; } top = tt; } }
/** Outputs to the writer the font dictionaries and streams. * @param writer the writer for this document * @param ref the font indirect reference * @param params 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 refi, Object[] param) { }
/** * Creates a file specification with the file embedded. The file may * come from the file system or from a byte array. * @param writer the <CODE>PdfWriter</CODE> * @param filePath the file path * @param fileDisplay the file information that is presented to the user * @param fileStore the byte array with the file. If it is not <CODE>null</CODE> * it takes precedence over <CODE>filePath</CODE> * @param mimeType the optional mimeType * @param fileParameter the optional extra file parameters such as the creation or modification date * @param compressionLevel the level of compression * @throws IOException on error * @return the file specification * @since 2.1.3 */ public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel) { PdfFileSpecification fs = new PdfFileSpecification(); fs.writer = writer; fs.Put(PdfName.F, new PdfString(fileDisplay)); PdfEFStream stream; Stream inp = null; PdfIndirectReference refi; PdfIndirectReference refFileLength; try { refFileLength = writer.PdfIndirectReference; if (fileStore == null) { if (File.Exists(filePath)) { inp = new FileStream(filePath, FileMode.Open, FileAccess.Read); } else { if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://")) { WebRequest w = WebRequest.Create(filePath); inp = w.GetResponse().GetResponseStream(); } else { inp = BaseFont.GetResourceStream(filePath); if (inp == null) { throw new IOException(filePath + " not found as file or resource."); } } } stream = new PdfEFStream(inp, writer); } else { stream = new PdfEFStream(fileStore); } stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE); stream.FlateCompress(compressionLevel); stream.Put(PdfName.PARAMS, refFileLength); if (mimeType != null) { stream.Put(PdfName.SUBTYPE, new PdfName(mimeType)); } refi = writer.AddToBody(stream).IndirectReference; if (fileStore == null) { stream.WriteLength(); } PdfDictionary param = new PdfDictionary(); if (fileParameter != null) { param.Merge(fileParameter); } param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength)); writer.AddToBody(param, refFileLength); } finally { if (inp != null) { try{ inp.Close(); }catch {} } } PdfDictionary f = new PdfDictionary(); f.Put(PdfName.F, refi); fs.Put(PdfName.EF, f); return(fs); }
// methods /** * Adds an indirect reference pointing to a <CODE>PdfContents</CODE>-object. * * @param contents an indirect reference to a <CODE>PdfContents</CODE>-object */ internal void Add(PdfIndirectReference contents) { Put(PdfName.CONTENTS, contents); }
/** Generates the font dictionary for this font. * @return the PdfDictionary containing the font dictionary * @param firstChar the first valid character * @param lastChar the last valid character * @param shortTag a 256 bytes long <CODE>byte</CODE> array where each unused byte is represented by 0 * @param fontDescriptor the indirect reference to a PdfDictionary containing the font descriptor or <CODE>null</CODE> */ private PdfDictionary GetFontBaseType(PdfIndirectReference fontDescriptor, int firstChar, int lastChar, byte[] shortTag) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.Put(PdfName.SUBTYPE, PdfName.TYPE1); dic.Put(PdfName.BASEFONT, new PdfName(FontName)); bool stdEncoding = encoding.Equals(CP1252) || encoding.Equals(MACROMAN); if (!fontSpecific || specialMap != null) { for (int k = firstChar; k <= lastChar; ++k) { if (!differences[k].Equals(notdef)) { firstChar = k; break; } } if (stdEncoding) { dic.Put(PdfName.ENCODING, encoding.Equals(CP1252) ? PdfName.WIN_ANSI_ENCODING : PdfName.MAC_ROMAN_ENCODING); } else { PdfDictionary enc = new PdfDictionary(PdfName.ENCODING); PdfArray dif = new PdfArray(); bool gap = true; for (int k = firstChar; k <= lastChar; ++k) { if (shortTag[k] != 0) { if (gap) { dif.Add(new PdfNumber(k)); gap = false; } dif.Add(new PdfName(differences[k])); } else { gap = true; } } enc.Put(PdfName.DIFFERENCES, dif); dic.Put(PdfName.ENCODING, enc); } } if (specialMap != null || forceWidthsOutput || !(builtinFont && (fontSpecific || stdEncoding))) { dic.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar)); dic.Put(PdfName.LASTCHAR, new PdfNumber(lastChar)); PdfArray wd = new PdfArray(); for (int k = firstChar; k <= lastChar; ++k) { if (shortTag[k] == 0) { wd.Add(new PdfNumber(0)); } else { wd.Add(new PdfNumber(widths[k])); } } dic.Put(PdfName.WIDTHS, wd); } if (!builtinFont && fontDescriptor != null) { dic.Put(PdfName.FONTDESCRIPTOR, fontDescriptor); } return(dic); }
/** * Creates a number tree. * @param items the item of the number tree. The key is an <CODE>Integer</CODE> * and the value is a <CODE>PdfObject</CODE>. * @param writer the writer * @throws IOException on error * @return the dictionary with the number tree. */ public static PdfDictionary WriteTree(Hashtable items, PdfWriter writer) { if (items.Count == 0) { return(null); } int[] numbers = new int[items.Count]; items.Keys.CopyTo(numbers, 0); Array.Sort(numbers); if (numbers.Length <= leafSize) { PdfDictionary dic = new PdfDictionary(); PdfArray ar = new PdfArray(); for (int k = 0; k < numbers.Length; ++k) { ar.Add(new PdfNumber(numbers[k])); ar.Add((PdfObject)items[numbers[k]]); } dic.Put(PdfName.NUMS, ar); return(dic); } int skip = leafSize; PdfIndirectReference[] kids = new PdfIndirectReference[(numbers.Length + leafSize - 1) / leafSize]; for (int k = 0; k < kids.Length; ++k) { int offset = k * leafSize; int end = Math.Min(offset + leafSize, numbers.Length); PdfDictionary dic = new PdfDictionary(); PdfArray arr = new PdfArray(); arr.Add(new PdfNumber(numbers[offset])); arr.Add(new PdfNumber(numbers[end - 1])); dic.Put(PdfName.LIMITS, arr); arr = new PdfArray(); for (; offset < end; ++offset) { arr.Add(new PdfNumber(numbers[offset])); arr.Add((PdfObject)items[numbers[offset]]); } dic.Put(PdfName.NUMS, arr); kids[k] = writer.AddToBody(dic).IndirectReference; } int top = kids.Length; while (true) { if (top <= leafSize) { PdfArray arr = new PdfArray(); for (int k = 0; k < top; ++k) { arr.Add(kids[k]); } PdfDictionary dic = new PdfDictionary(); dic.Put(PdfName.KIDS, arr); return(dic); } skip *= leafSize; int tt = (numbers.Length + skip - 1) / skip; for (int k = 0; k < tt; ++k) { int offset = k * leafSize; int end = Math.Min(offset + leafSize, top); PdfDictionary dic = new PdfDictionary(); PdfArray arr = new PdfArray(); arr.Add(new PdfNumber(numbers[k * skip])); arr.Add(new PdfNumber(numbers[Math.Min((k + 1) * skip, numbers.Length) - 1])); dic.Put(PdfName.LIMITS, arr); arr = new PdfArray(); for (; offset < end; ++offset) { arr.Add(kids[offset]); } dic.Put(PdfName.KIDS, arr); kids[k] = writer.AddToBody(dic).IndirectReference; } top = tt; } }
/// <summary> /// Constructs an Image object duplicate. /// </summary> /// <param name="image">another Image object.</param> public Image(Image image) : base(image) { this.type = image.type; this.url = image.url; this.alignment = image.alignment; this.alt = image.alt; this.absoluteX = image.absoluteX; this.absoluteY = image.absoluteY; this.plainWidth = image.plainWidth; this.plainHeight = image.plainHeight; this.scaledWidth = image.scaledWidth; this.scaledHeight = image.scaledHeight; this.rotationRadians = image.rotationRadians; this.indentationLeft = image.indentationLeft; this.indentationRight = image.indentationRight; this.colorspace = image.colorspace; this.rawData = image.rawData; this.template = image.template; this.bpc = image.bpc; this.transparency = image.transparency; this.mySerialId = image.mySerialId; this.invert = image.invert; this.dpiX = image.dpiX; this.dpiY = image.dpiY; this.mask = image.mask; this.imageMask = image.imageMask; this.interpolation = image.interpolation; this.annotation = image.annotation; this.profile = image.profile; this.deflated = image.deflated; this.additional = image.additional; this.smask = image.smask; this.XYRatio = image.XYRatio; this.originalData = image.originalData; this.originalType = image.originalType; this.spacingAfter = image.spacingAfter; this.spacingBefore = image.spacingBefore; this.widthPercentage = image.widthPercentage; this.layer = image.layer; this.initialRotation = image.initialRotation; this.directReference = image.directReference; }
internal PdfAppearance(PdfIndirectReference iref) { thisReference = iref; }
private PdfDictionary GetCIDFont(PdfIndirectReference fontDescriptor, IntHashtable cjkTag) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.Put(PdfName.SUBTYPE, PdfName.CIDFONTTYPE0); dic.Put(PdfName.BASEFONT, new PdfName(fontName + style)); dic.Put(PdfName.FONTDESCRIPTOR, fontDescriptor); int[] keys = cjkTag.ToOrderedKeys(); string w = ConvertToHCIDMetrics(keys, hMetrics); if (w != null) dic.Put(PdfName.W, new PdfLiteral(w)); if (vertical) { w = ConvertToVCIDMetrics(keys, vMetrics, hMetrics); if (w != null) dic.Put(PdfName.W2, new PdfLiteral(w)); } else dic.Put(PdfName.DW, new PdfNumber(1000)); PdfDictionary cdic = new PdfDictionary(); cdic.Put(PdfName.REGISTRY, new PdfString((string)fontDesc["Registry"], null)); cdic.Put(PdfName.ORDERING, new PdfString((string)fontDesc["Ordering"], null)); cdic.Put(PdfName.SUPPLEMENT, new PdfLiteral((string)fontDesc["Supplement"])); dic.Put(PdfName.CIDSYSTEMINFO, cdic); return dic; }
internal PdfName AddXObject(PdfName name, PdfIndirectReference reference) { name = TranslateName(name); xObjectDictionary.Put(name, reference); return name; }
/** * Adds documentFields. */ public void AddDocumentField(PdfIndirectReference piref) { documentFields.Add(piref); }
/** Outputs to the writer the font dictionaries and streams. * @param writer the writer for this document * @param ref the font indirect reference * @param params 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) { int firstChar = (int)parms[0]; int lastChar = (int)parms[1]; byte[] shortTag = (byte[])parms[2]; bool subsetp = (bool)parms[3] && subset; if (!subsetp) { firstChar = 0; lastChar = shortTag.Length - 1; for (int k = 0; k < shortTag.Length; ++k) shortTag[k] = 1; } PdfIndirectReference ind_font = null; PdfObject pobj = null; PdfIndirectObject obj = null; string subsetPrefix = ""; if (embedded) { if (cff) { pobj = new StreamFont(ReadCffFont(), "Type1C", compressionLevel); obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } else { if (subsetp) subsetPrefix = CreateSubsetPrefix(); Hashtable glyphs = new Hashtable(); for (int k = firstChar; k <= lastChar; ++k) { if (shortTag[k] != 0) { int[] metrics = null; if (specialMap != null) { int[] cd = GlyphList.NameToUnicode(differences[k]); if (cd != null) metrics = GetMetricsTT(cd[0]); } else { if (fontSpecific) metrics = GetMetricsTT(k); else metrics = GetMetricsTT(unicodeDifferences[k]); } if (metrics != null) glyphs[metrics[0]] = null; } } AddRangeUni(glyphs, false, subsetp); byte[] b = null; if (subsetp || directoryOffset != 0 || subsetRanges != null) { TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), glyphs, directoryOffset, true, !subsetp); 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; } } pobj = GetFontDescriptor(ind_font, subsetPrefix, null); if (pobj != null){ obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } pobj = GetFontBaseType(ind_font, subsetPrefix, firstChar, lastChar, shortTag); writer.AddToBody(pobj, piref); }
/** * Adds an image to the document but not to the page resources. It is used with * templates and <CODE>Document.Add(Image)</CODE>. * @param image the <CODE>Image</CODE> to add * @param fixedRef the reference to used. It may be <CODE>null</CODE>, * a <CODE>PdfIndirectReference</CODE> or a <CODE>PRIndirectReference</CODE>. * @return the name of the image added * @throws PdfException on error * @throws DocumentException on error */ public PdfName AddDirectImageSimple(Image image, PdfIndirectReference fixedRef) { PdfName name; // if the images is already added, just retrieve the name if (images.ContainsKey(image.MySerialId)) { name = (PdfName) images[image.MySerialId]; } // if it's a new image, add it to the document else { if (image.IsImgTemplate()) { name = new PdfName("img" + images.Count); if (image is ImgWMF){ ImgWMF wmf = (ImgWMF)image; wmf.ReadWMF(PdfTemplate.CreateTemplate(this, 0, 0)); } } else { PdfIndirectReference dref = image.DirectReference; if (dref != null) { PdfName rname = new PdfName("img" + images.Count); images[image.MySerialId] = rname; imageDictionary.Put(rname, dref); return rname; } Image maskImage = image.ImageMask; PdfIndirectReference maskRef = null; if (maskImage != null) { PdfName mname = (PdfName)images[maskImage.MySerialId]; maskRef = GetImageReference(mname); } PdfImage i = new PdfImage(image, "img" + images.Count, maskRef); if (image is ImgJBIG2) { byte[] globals = ((ImgJBIG2) image).GlobalBytes; if (globals != null) { PdfDictionary decodeparms = new PdfDictionary(); decodeparms.Put(PdfName.JBIG2GLOBALS, GetReferenceJBIG2Globals(globals)); i.Put(PdfName.DECODEPARMS, decodeparms); } } if (image.HasICCProfile()) { PdfICCBased icc = new PdfICCBased(image.TagICC, image.CompressionLevel); PdfIndirectReference iccRef = Add(icc); PdfArray iccArray = new PdfArray(); iccArray.Add(PdfName.ICCBASED); iccArray.Add(iccRef); PdfArray colorspace = i.GetAsArray(PdfName.COLORSPACE); if (colorspace != null) { if (colorspace.Size > 1 && PdfName.INDEXED.Equals(colorspace[0])) colorspace[1] = iccArray; else i.Put(PdfName.COLORSPACE, iccArray); } else i.Put(PdfName.COLORSPACE, iccArray); } Add(i, fixedRef); name = i.Name; } images[image.MySerialId] = name; } return name; }
/** Generates the font dictionary for this font. * @return the PdfDictionary containing the font dictionary * @param subsetPrefix the subset prefx * @param firstChar the first valid character * @param lastChar the last valid character * @param shortTag a 256 bytes long <CODE>byte</CODE> array where each unused byte is represented by 0 * @param fontDescriptor the indirect reference to a PdfDictionary containing the font descriptor or <CODE>null</CODE> * @throws DocumentException if there is an error */ protected PdfDictionary GetFontBaseType(PdfIndirectReference fontDescriptor, string subsetPrefix, int firstChar, int lastChar, byte[] shortTag) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); if (cff) { dic.Put(PdfName.SUBTYPE, PdfName.TYPE1); dic.Put(PdfName.BASEFONT, new PdfName(fontName + style)); } else { dic.Put(PdfName.SUBTYPE, PdfName.TRUETYPE); dic.Put(PdfName.BASEFONT, new PdfName(subsetPrefix + fontName + style)); } dic.Put(PdfName.BASEFONT, new PdfName(subsetPrefix + fontName + style)); if (!fontSpecific) { for (int k = firstChar; k <= lastChar; ++k) { if (!differences[k].Equals(notdef)) { firstChar = k; break; } } if (encoding.Equals(CP1252) || encoding.Equals(MACROMAN)) dic.Put(PdfName.ENCODING, encoding.Equals(CP1252) ? PdfName.WIN_ANSI_ENCODING : PdfName.MAC_ROMAN_ENCODING); else { PdfDictionary enc = new PdfDictionary(PdfName.ENCODING); PdfArray dif = new PdfArray(); bool gap = true; for (int k = firstChar; k <= lastChar; ++k) { if (shortTag[k] != 0) { if (gap) { dif.Add(new PdfNumber(k)); gap = false; } dif.Add(new PdfName(differences[k])); } else gap = true; } enc.Put(PdfName.DIFFERENCES, dif); dic.Put(PdfName.ENCODING, enc); } } dic.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar)); dic.Put(PdfName.LASTCHAR, new PdfNumber(lastChar)); PdfArray wd = new PdfArray(); for (int k = firstChar; k <= lastChar; ++k) { if (shortTag[k] == 0) wd.Add(new PdfNumber(0)); else wd.Add(new PdfNumber(widths[k])); } dic.Put(PdfName.WIDTHS, wd); if (fontDescriptor != null) dic.Put(PdfName.FONTDESCRIPTOR, fontDescriptor); return dic; }
/** * Writes a <CODE>PdfImage</CODE> to the outputstream. * * @param pdfImage the image to be added * @return a <CODE>PdfIndirectReference</CODE> to the encapsulated image * @throws PdfException when a document isn't open yet, or has been closed */ internal virtual PdfIndirectReference Add(PdfImage pdfImage, PdfIndirectReference fixedRef) { if (! imageDictionary.Contains(pdfImage.Name)) { PdfXConformanceImp.CheckPDFXConformance(this, PdfXConformanceImp.PDFXKEY_IMAGE, pdfImage); if (fixedRef is PRIndirectReference) { PRIndirectReference r2 = (PRIndirectReference)fixedRef; fixedRef = new PdfIndirectReference(0, GetNewObjectNumber(r2.Reader, r2.Number, r2.Generation)); } if (fixedRef == null) fixedRef = AddToBody(pdfImage).IndirectReference; else AddToBody(pdfImage, fixedRef); imageDictionary.Put(pdfImage.Name, fixedRef); return fixedRef; } return (PdfIndirectReference)imageDictionary.Get(pdfImage.Name); }
/** Generates the font descriptor for this font. * @return the PdfDictionary containing the font descriptor or <CODE>null</CODE> * @param subsetPrefix the subset prefix * @param fontStream the indirect reference to a PdfStream containing the font or <CODE>null</CODE> * @throws DocumentException if there is an error */ protected PdfDictionary GetFontDescriptor(PdfIndirectReference fontStream, string subsetPrefix, PdfIndirectReference cidset) { PdfDictionary dic = new PdfDictionary(PdfName.FONTDESCRIPTOR); dic.Put(PdfName.ASCENT, new PdfNumber((int)os_2.sTypoAscender * 1000 / head.unitsPerEm)); dic.Put(PdfName.CAPHEIGHT, new PdfNumber((int)os_2.sCapHeight * 1000 / head.unitsPerEm)); dic.Put(PdfName.DESCENT, new PdfNumber((int)os_2.sTypoDescender * 1000 / head.unitsPerEm)); dic.Put(PdfName.FONTBBOX, new PdfRectangle( (int)head.xMin * 1000 / head.unitsPerEm, (int)head.yMin * 1000 / head.unitsPerEm, (int)head.xMax * 1000 / head.unitsPerEm, (int)head.yMax * 1000 / head.unitsPerEm)); if (cidset != null) dic.Put(PdfName.CIDSET, cidset); if (cff) { if (encoding.StartsWith("Identity-")) dic.Put(PdfName.FONTNAME, new PdfName(subsetPrefix + fontName+"-"+encoding)); else dic.Put(PdfName.FONTNAME, new PdfName(subsetPrefix + fontName + style)); } else dic.Put(PdfName.FONTNAME, new PdfName(subsetPrefix + fontName + style)); dic.Put(PdfName.ITALICANGLE, new PdfNumber(italicAngle)); dic.Put(PdfName.STEMV, new PdfNumber(80)); if (fontStream != null) { if (cff) dic.Put(PdfName.FONTFILE3, fontStream); else dic.Put(PdfName.FONTFILE2, fontStream); } int flags = 0; if (isFixedPitch) flags |= 1; flags |= fontSpecific ? 4 : 32; if ((head.macStyle & 2) != 0) flags |= 64; if ((head.macStyle & 1) != 0) flags |= 262144; dic.Put(PdfName.FLAGS, new PdfNumber(flags)); return dic; }
// PDF Catalog /* * The Catalog is also called the root object of the document. * Whereas the Cross-Reference maps the objects number with the * byte offset so that the viewer can find the objects, the * Catalog tells the viewer the numbers of the objects needed * to render the document. */ protected virtual PdfDictionary GetCatalog(PdfIndirectReference rootObj) { PdfDictionary catalog = pdf.GetCatalog(rootObj); // [F12] tagged PDF if (tagged) { this.StructureTreeRoot.BuildTree(); catalog.Put(PdfName.STRUCTTREEROOT, structureTreeRoot.Reference); PdfDictionary mi = new PdfDictionary(); mi.Put(PdfName.MARKED, PdfBoolean.PDFTRUE); if (userProperties) mi.Put(PdfName.USERPROPERTIES, PdfBoolean.PDFTRUE); catalog.Put(PdfName.MARKINFO, mi); } // [F13] OCG if (documentOCG.Count != 0) { FillOCProperties(false); catalog.Put(PdfName.OCPROPERTIES, vOCProperties); } return catalog; }
/** Generates the font descriptor for this font or <CODE>null</CODE> if it is * one of the 14 built in fonts. * @param fontStream the indirect reference to a PdfStream containing the font or <CODE>null</CODE> * @return the PdfDictionary containing the font descriptor or <CODE>null</CODE> */ public PdfDictionary GetFontDescriptor(PdfIndirectReference fontStream) { if (builtinFont) return null; PdfDictionary dic = new PdfDictionary(PdfName.FONTDESCRIPTOR); dic.Put(PdfName.ASCENT, new PdfNumber(Ascender)); dic.Put(PdfName.CAPHEIGHT, new PdfNumber(CapHeight)); dic.Put(PdfName.DESCENT, new PdfNumber(Descender)); dic.Put(PdfName.FONTBBOX, new PdfRectangle(llx, lly, urx, ury)); dic.Put(PdfName.FONTNAME, new PdfName(FontName)); dic.Put(PdfName.ITALICANGLE, new PdfNumber(ItalicAngle)); dic.Put(PdfName.STEMV, new PdfNumber(StdVW)); if (fontStream != null) dic.Put(PdfName.FONTFILE, fontStream); int flags = 0; if (IsFixedPitch) flags |= 1; flags |= fontSpecific ? 4 : 32; if (ItalicAngle < 0) flags |= 64; if (FontName.IndexOf("Caps") >= 0 || FontName.EndsWith("SC")) flags |= 131072; if (Weight.Equals("Bold")) flags |= 262144; dic.Put(PdfName.FLAGS, new PdfNumber(flags)); return dic; }
internal PdfIndirectObject Add(PdfObject objecta, PdfIndirectReference refa, bool inObjStm) { return Add(objecta, refa.Number, inObjStm); }
/** 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) { int firstChar = (int)parms[0]; int lastChar = (int)parms[1]; byte[] shortTag = (byte[])parms[2]; bool subsetp = (bool)parms[3] && subset; if (!subsetp) { firstChar = 0; lastChar = shortTag.Length - 1; for (int k = 0; k < shortTag.Length; ++k) shortTag[k] = 1; } PdfIndirectReference ind_font = null; PdfObject pobj = null; PdfIndirectObject obj = null; pobj = GetFullFontStream(); if (pobj != null){ obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } pobj = GetFontDescriptor(ind_font); if (pobj != null){ obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } pobj = GetFontBaseType(ind_font, firstChar, lastChar, shortTag); writer.AddToBody(pobj, piref); }
// constructors /** * Constructs a PDF-Trailer. * * @param size the number of entries in the <CODE>PdfCrossReferenceTable</CODE> * @param offset offset of the <CODE>PdfCrossReferenceTable</CODE> * @param root an indirect reference to the root of the PDF document * @param info an indirect reference to the info object of the PDF document * @param encryption * @param fileID * @param prevxref */ internal PdfTrailer(int size, int offset, PdfIndirectReference root, PdfIndirectReference info, PdfIndirectReference encryption, PdfObject fileID, int prevxref) { this.offset = offset; Put(PdfName.SIZE, new PdfNumber(size)); Put(PdfName.ROOT, root); if (info != null) { Put(PdfName.INFO, info); } if (encryption != null) Put(PdfName.ENCRYPT, encryption); if (fileID != null) Put(PdfName.ID, fileID); if (prevxref > 0) Put(PdfName.PREV, new PdfNumber(prevxref)); }
/** Generates the font dictionary for this font. * @return the PdfDictionary containing the font dictionary * @param firstChar the first valid character * @param lastChar the last valid character * @param shortTag a 256 bytes long <CODE>byte</CODE> array where each unused byte is represented by 0 * @param fontDescriptor the indirect reference to a PdfDictionary containing the font descriptor or <CODE>null</CODE> */ private PdfDictionary GetFontBaseType(PdfIndirectReference fontDescriptor, int firstChar, int lastChar, byte[] shortTag) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.Put(PdfName.SUBTYPE, PdfName.TYPE1); dic.Put(PdfName.BASEFONT, new PdfName(FontName)); bool stdEncoding = encoding.Equals(CP1252) || encoding.Equals(MACROMAN); if (!fontSpecific || specialMap != null) { for (int k = firstChar; k <= lastChar; ++k) { if (!differences[k].Equals(notdef)) { firstChar = k; break; } } if (stdEncoding) dic.Put(PdfName.ENCODING, encoding.Equals(CP1252) ? PdfName.WIN_ANSI_ENCODING : PdfName.MAC_ROMAN_ENCODING); else { PdfDictionary enc = new PdfDictionary(PdfName.ENCODING); PdfArray dif = new PdfArray(); bool gap = true; for (int k = firstChar; k <= lastChar; ++k) { if (shortTag[k] != 0) { if (gap) { dif.Add(new PdfNumber(k)); gap = false; } dif.Add(new PdfName(differences[k])); } else gap = true; } enc.Put(PdfName.DIFFERENCES, dif); dic.Put(PdfName.ENCODING, enc); } } if (specialMap != null || forceWidthsOutput || !(builtinFont && (fontSpecific || stdEncoding))) { dic.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar)); dic.Put(PdfName.LASTCHAR, new PdfNumber(lastChar)); PdfArray wd = new PdfArray(); for (int k = firstChar; k <= lastChar; ++k) { if (shortTag[k] == 0) wd.Add(new PdfNumber(0)); else wd.Add(new PdfNumber(widths[k])); } dic.Put(PdfName.WIDTHS, wd); } if (!builtinFont && fontDescriptor != null) dic.Put(PdfName.FONTDESCRIPTOR, fontDescriptor); return dic; }
/** * Add a widget ref to this Item * * @since 2.1.5 * @param widgRef */ internal void AddWidgetRef(PdfIndirectReference widgRef) { widget_refs.Add(widgRef); }
/** 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); }
internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms) { IntHashtable cjkTag = (IntHashtable)parms[0]; PdfIndirectReference ind_font = null; PdfObject pobj = null; PdfIndirectObject obj = null; pobj = GetFontDescriptor(); if (pobj != null){ obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } pobj = GetCIDFont(ind_font, cjkTag); if (pobj != null){ obj = writer.AddToBody(pobj); ind_font = obj.IndirectReference; } pobj = GetFontBaseType(ind_font); writer.AddToBody(pobj, piref); }
/** Generates the CIDFontTyte2 dictionary. * @param fontDescriptor the indirect reference to the font descriptor * @param subsetPrefix the subset prefix * @param metrics the horizontal width metrics * @return a stream */ private PdfDictionary GetCIDFontType2(PdfIndirectReference fontDescriptor, string subsetPrefix, Object[] metrics) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); // sivan; cff if (cff) { dic.Put(PdfName.SUBTYPE, PdfName.CIDFONTTYPE0); dic.Put(PdfName.BASEFONT, new PdfName(subsetPrefix + fontName+"-"+encoding)); } else { dic.Put(PdfName.SUBTYPE, PdfName.CIDFONTTYPE2); dic.Put(PdfName.BASEFONT, new PdfName(subsetPrefix + fontName)); } dic.Put(PdfName.FONTDESCRIPTOR, fontDescriptor); if (!cff) dic.Put(PdfName.CIDTOGIDMAP,PdfName.IDENTITY); PdfDictionary cdic = new PdfDictionary(); cdic.Put(PdfName.REGISTRY, new PdfString("Adobe")); cdic.Put(PdfName.ORDERING, new PdfString("Identity")); cdic.Put(PdfName.SUPPLEMENT, new PdfNumber(0)); dic.Put(PdfName.CIDSYSTEMINFO, cdic); if (!vertical) { dic.Put(PdfName.DW, new PdfNumber(1000)); StringBuilder buf = new StringBuilder("["); int lastNumber = -10; bool firstTime = true; for (int k = 0; k < metrics.Length; ++k) { int[] metric = (int[])metrics[k]; if (metric[1] == 1000) continue; int m = metric[0]; if (m == lastNumber + 1) { buf.Append(' ').Append(metric[1]); } else { if (!firstTime) { buf.Append(']'); } firstTime = false; buf.Append(m).Append('[').Append(metric[1]); } lastNumber = m; } if (buf.Length > 1) { buf.Append("]]"); dic.Put(PdfName.W, new PdfLiteral(buf.ToString())); } } return dic; }
private PdfDictionary GetFontBaseType(PdfIndirectReference CIDFont) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.Put(PdfName.SUBTYPE, PdfName.TYPE0); string name = fontName; if (style.Length > 0) name += "-" + style.Substring(1); name += "-" + CMap; dic.Put(PdfName.BASEFONT, new PdfName(name)); dic.Put(PdfName.ENCODING, new PdfName(CMap)); dic.Put(PdfName.DESCENDANTFONTS, new PdfArray(CIDFont)); return dic; }
/** Generates the font dictionary. * @param descendant the descendant dictionary * @param subsetPrefix the subset prefix * @param toUnicode the ToUnicode stream * @return the stream */ private PdfDictionary GetFontBaseType(PdfIndirectReference descendant, string subsetPrefix, PdfIndirectReference toUnicode) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.Put(PdfName.SUBTYPE, PdfName.TYPE0); // The PDF Reference manual advises to add -encoding to CID font names if (cff) dic.Put(PdfName.BASEFONT, new PdfName(subsetPrefix + fontName+"-"+encoding)); else dic.Put(PdfName.BASEFONT, new PdfName(subsetPrefix + fontName)); dic.Put(PdfName.ENCODING, new PdfName(encoding)); dic.Put(PdfName.DESCENDANTFONTS, new PdfArray(descendant)); if (toUnicode != null) dic.Put(PdfName.TOUNICODE, toUnicode); return dic; }
/** Each font used in a document has an instance of this class. * This class stores the characters used in the document and other * specifics unique to the current working document. * @param fontName the font name * @param indirectReference the indirect reference to the font * @param baseFont the <CODE>BaseFont</CODE> */ internal FontDetails(PdfName fontName, PdfIndirectReference indirectReference, BaseFont baseFont) { this.fontName = fontName; this.indirectReference = indirectReference; this.baseFont = baseFont; fontType = baseFont.FontType; switch (fontType) { case BaseFont.FONT_TYPE_T1: case BaseFont.FONT_TYPE_TT: shortTag = new byte[256]; break; case BaseFont.FONT_TYPE_CJK: cjkTag = new IntHashtable(); cjkFont = (CJKFont)baseFont; break; case BaseFont.FONT_TYPE_TTUNI: longTag = new Hashtable(); ttu = (TrueTypeFontUnicode)baseFont; symbolic = baseFont.IsFontSpecific(); break; } }
/** * Creates a file specification with the file embedded. The file may * come from the file system or from a byte array. * @param writer the <CODE>PdfWriter</CODE> * @param filePath the file path * @param fileDisplay the file information that is presented to the user * @param fileStore the byte array with the file. If it is not <CODE>null</CODE> * it takes precedence over <CODE>filePath</CODE> * @param mimeType the optional mimeType * @param fileParameter the optional extra file parameters such as the creation or modification date * @param compressionLevel the level of compression * @throws IOException on error * @return the file specification * @since 2.1.3 */ public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel) { PdfFileSpecification fs = new PdfFileSpecification(); fs.writer = writer; fs.Put(PdfName.F, new PdfString(fileDisplay)); PdfEFStream stream; Stream inp = null; PdfIndirectReference refi; PdfIndirectReference refFileLength; try { refFileLength = writer.PdfIndirectReference; if (fileStore == null) { if (File.Exists(filePath)) { inp = new FileStream(filePath, FileMode.Open, FileAccess.Read); } else { if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://")) { WebRequest w = WebRequest.Create(filePath); inp = w.GetResponse().GetResponseStream(); } else { inp = BaseFont.GetResourceStream(filePath); if (inp == null) throw new IOException(filePath + " not found as file or resource."); } } stream = new PdfEFStream(inp, writer); } else stream = new PdfEFStream(fileStore); stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE); stream.FlateCompress(compressionLevel); stream.Put(PdfName.PARAMS, refFileLength); if (mimeType != null) stream.Put(PdfName.SUBTYPE, new PdfName(mimeType)); refi = writer.AddToBody(stream).IndirectReference; if (fileStore == null) { stream.WriteLength(); } PdfDictionary param = new PdfDictionary(); if (fileParameter != null) param.Merge(fileParameter); param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength)); writer.AddToBody(param, refFileLength); } finally { if (inp != null) try{inp.Close();}catch{} } PdfDictionary f = new PdfDictionary(); f.Put(PdfName.F, refi); fs.Put(PdfName.EF, f); return fs; }
/** * Creates an efficient stream. No temporary array is ever created. The <CODE>InputStream</CODE> * is totally consumed but is not closed. The general usage is: * <p> * <pre> * InputStream in = ...; * PdfStream stream = new PdfStream(in, writer); * stream.FlateCompress(); * writer.AddToBody(stream); * stream.WriteLength(); * in.Close(); * </pre> * @param inputStream the data to write to this stream * @param writer the <CODE>PdfWriter</CODE> for this stream */ public PdfStream(Stream inputStream, PdfWriter writer) { type = STREAM; this.inputStream = inputStream; this.writer = writer; iref = writer.PdfIndirectReference; Put(PdfName.LENGTH, iref); }
/** * Constructs a new <CODE>PdfAction</CODE> of Subtype GoTo. * @param destination the destination to go to */ internal PdfAction(PdfIndirectReference destination) { Put(PdfName.S, PdfName.GOTO); Put(PdfName.D, destination); }