internal PdfMediaClipData(String file, PdfFileSpecification fs, String mimeType) { Put(PdfName.TYPE,new PdfName("MediaClip")); Put(PdfName.S, new PdfName("MCD")); Put(PdfName.N, new PdfString("Media clip for "+file)); Put(new PdfName("CT"), new PdfString(mimeType)); PdfDictionary dic = new PdfDictionary(); dic.Put(new PdfName("TF"), new PdfString("TEMPACCESS")); Put(new PdfName("P"), dic); Put(PdfName.D, fs.Reference); }
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; }
/** Adds or replaces a page label. * @param page the real page to start the numbering. First page is 1 * @param numberStyle the numbering style such as LOWERCASE_ROMAN_NUMERALS * @param text the text to prefix the number. Can be <CODE>null</CODE> or empty * @param firstPage the first logical page number */ public void AddPageLabel(int page, int numberStyle, string text, int firstPage) { if (page < 1 || firstPage < 1) throw new ArgumentException("In a page label the page numbers must be greater or equal to 1."); PdfDictionary dic = new PdfDictionary(); if (numberStyle >= 0 && numberStyle < numberingStyle.Length) dic.Put(PdfName.S, numberingStyle[numberStyle]); if (text != null) dic.Put(PdfName.P, new PdfString(text, PdfObject.TEXT_UNICODE)); if (firstPage != 1) dic.Put(PdfName.ST, new PdfNumber(firstPage)); map[page - 1] = 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; }
protected internal void WriteOutlines(PdfDictionary catalog, bool namedAsNames) { if (newBookmarks == null || newBookmarks.Count == 0) return; PdfDictionary top = new PdfDictionary(); PdfIndirectReference topRef = this.PdfIndirectReference; Object[] kids = SimpleBookmark.IterateOutlines(this, topRef, newBookmarks, namedAsNames); top.Put(PdfName.FIRST, (PdfIndirectReference)kids[0]); top.Put(PdfName.LAST, (PdfIndirectReference)kids[1]); top.Put(PdfName.COUNT, new PdfNumber((int)kids[2])); AddToBody(top, topRef); catalog.Put(PdfName.OUTLINES, topRef); }
// [C11] Output intents /** * Sets the values of the output intent dictionary. Null values are allowed to * suppress any key. * @param outputConditionIdentifier a value * @param outputCondition a value * @param registryName a value * @param info a value * @param destOutputProfile a value * @throws IOException on error */ public void SetOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, ICC_Profile colorProfile) { PdfDictionary outa = ExtraCatalog; //force the creation outa = new PdfDictionary(PdfName.OUTPUTINTENT); if (outputCondition != null) outa.Put(PdfName.OUTPUTCONDITION, new PdfString(outputCondition, PdfObject.TEXT_UNICODE)); if (outputConditionIdentifier != null) outa.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString(outputConditionIdentifier, PdfObject.TEXT_UNICODE)); if (registryName != null) outa.Put(PdfName.REGISTRYNAME, new PdfString(registryName, PdfObject.TEXT_UNICODE)); if (info != null) outa.Put(PdfName.INFO, new PdfString(info, PdfObject.TEXT_UNICODE)); if (colorProfile != null) { PdfStream stream = new PdfICCBased(colorProfile, compressionLevel); outa.Put(PdfName.DESTOUTPUTPROFILE, AddToBody(stream).IndirectReference); } PdfName intentSubtype; if (pdfxConformance.IsPdfA1() || "PDFA/1".Equals(outputCondition)) { intentSubtype = PdfName.GTS_PDFA1; } else { intentSubtype = PdfName.GTS_PDFX; } outa.Put(PdfName.S, intentSubtype); extraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(outa)); }
/** * 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; }
/** * 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; }
internal void SetOriginalResources(PdfDictionary resources, int[] newNamePtr) { if (newNamePtr != null) namePtr = newNamePtr; forbiddenNames = new Hashtable(); usedNames = new Hashtable(); if (resources == null) return; originalResources = new PdfDictionary(); originalResources.Merge(resources); foreach (PdfName key in resources.Keys) { PdfObject sub = PdfReader.GetPdfObject(resources.Get(key)); if (sub != null && sub.IsDictionary()) { PdfDictionary dic = (PdfDictionary)sub; foreach (PdfName name in dic.Keys) { forbiddenNames[name] = null; } PdfDictionary dic2 = new PdfDictionary(); dic2.Merge(dic); originalResources.Put(key, dic2); } } }
/** * Reads next frame image */ protected void ReadImage() { ix = ReadShort(); // (sub)image position & size iy = ReadShort(); iw = ReadShort(); ih = ReadShort(); int packed = inp.ReadByte(); lctFlag = (packed & 0x80) != 0; // 1 - local color table flag interlace = (packed & 0x40) != 0; // 2 - interlace flag // 3 - sort flag // 4-5 - reserved lctSize = 2 << (packed & 7); // 6-8 - local color table size m_bpc = NewBpc(m_gbpc); if (lctFlag) { m_curr_table = ReadColorTable((packed & 7) + 1); // read table m_bpc = NewBpc((packed & 7) + 1); } else { m_curr_table = m_global_table; } if (transparency && transIndex >= m_curr_table.Length / 3) transparency = false; if (transparency && m_bpc == 1) { // Acrobat 5.05 doesn't like this combination byte[] tp = new byte[12]; Array.Copy(m_curr_table, 0, tp, 0, 6); m_curr_table = tp; m_bpc = 2; } bool skipZero = DecodeImageData(); // decode pixel data if (!skipZero) Skip(); Image img = null; img = new ImgRaw(iw, ih, 1, m_bpc, m_out); PdfArray colorspace = new PdfArray(); colorspace.Add(PdfName.INDEXED); colorspace.Add(PdfName.DEVICERGB); int len = m_curr_table.Length; colorspace.Add(new PdfNumber(len / 3 - 1)); colorspace.Add(new PdfString(m_curr_table)); PdfDictionary ad = new PdfDictionary(); ad.Put(PdfName.COLORSPACE, colorspace); img.Additional = ad; if (transparency) { img.Transparency = new int[]{transIndex, transIndex}; } img.OriginalType = Image.ORIGINAL_GIF; img.OriginalData = fromData; img.Url = fromUrl; GifFrame gf = new GifFrame(); gf.image = img; gf.ix = ix; gf.iy = iy; frames.Add(gf); // add image to frame list //ResetFrame(); }
private void AddFieldResources(PdfDictionary catalog) { if (fieldArray == null) return; PdfDictionary acroForm = new PdfDictionary(); catalog.Put(PdfName.ACROFORM, acroForm); acroForm.Put(PdfName.FIELDS, fieldArray); acroForm.Put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g ")); if (fieldTemplates.Count == 0) return; PdfDictionary dr = new PdfDictionary(); acroForm.Put(PdfName.DR, dr); foreach (PdfTemplate template in fieldTemplates.Keys) { PdfFormField.MergeResources(dr, (PdfDictionary)template.Resources); } PdfDictionary fonts = dr.GetAsDict(PdfName.FONT); if (fonts == null) { fonts = new PdfDictionary(); dr.Put(PdfName.FONT, fonts); } if (!fonts.Contains(PdfName.HELV)) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.Put(PdfName.BASEFONT, PdfName.HELVETICA); dic.Put(PdfName.ENCODING, PdfName.WIN_ANSI_ENCODING); dic.Put(PdfName.NAME, PdfName.HELV); dic.Put(PdfName.SUBTYPE, PdfName.TYPE1); fonts.Put(PdfName.HELV, AddToBody(dic).IndirectReference); } if (!fonts.Contains(PdfName.ZADB)) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.Put(PdfName.BASEFONT, PdfName.ZAPFDINGBATS); dic.Put(PdfName.NAME, PdfName.ZADB); dic.Put(PdfName.SUBTYPE, PdfName.TYPE1); fonts.Put(PdfName.ZADB, AddToBody(dic).IndirectReference); } }
/** * Translate a PRDictionary to a PdfDictionary. Also translate all of the * objects contained in it. */ protected PdfDictionary CopyDictionary(PdfDictionary inp) { PdfDictionary outp = new PdfDictionary(); PdfObject type = PdfReader.GetPdfObjectRelease(inp.Get(PdfName.TYPE)); foreach (PdfName key in inp.Keys) { PdfObject value = inp.Get(key); if (type != null && PdfName.PAGE.Equals(type)) { if (!key.Equals(PdfName.B) && !key.Equals(PdfName.PARENT)) outp.Put(key, CopyObject(value)); } else outp.Put(key, CopyObject(value)); } return outp; }
/** * 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); }
/** 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); }
/** Adds the version to the Catalog dictionary. */ public void AddToCatalog(PdfDictionary catalog) { if(catalog_version != null) { catalog.Put(PdfName.VERSION, catalog_version); } if (extensions != null) { catalog.Put(PdfName.EXTENSIONS, extensions); } }
/** * 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; } }
/** * Creates a screen PdfAnnotation * @param writer * @param rect * @param clipTitle * @param fs * @param mimeType * @param playOnDisplay * @return a screen PdfAnnotation * @throws IOException */ public static PdfAnnotation CreateScreen(PdfWriter writer, Rectangle rect, String clipTitle, PdfFileSpecification fs, String mimeType, bool playOnDisplay) { PdfAnnotation ann = new PdfAnnotation(writer, rect); ann.Put(PdfName.SUBTYPE, PdfName.SCREEN); ann.Put (PdfName.F, new PdfNumber(FLAGS_PRINT)); ann.Put(PdfName.TYPE, PdfName.ANNOT); ann.SetPage(); PdfIndirectReference refi = ann.IndirectReference; PdfAction action = PdfAction.Rendition(clipTitle,fs,mimeType, refi); PdfIndirectReference actionRef = writer.AddToBody(action).IndirectReference; // for play on display add trigger event if (playOnDisplay) { PdfDictionary aa = new PdfDictionary(); aa.Put(new PdfName("PV"), actionRef); ann.Put(PdfName.AA, aa); } ann.Put(PdfName.A, actionRef); return ann; }
public static PdfDictionary OutputNamedDestinationAsNames(Hashtable names, PdfWriter writer) { PdfDictionary dic = new PdfDictionary(); foreach (String key in names.Keys) { try { String value = (String)names[key]; PdfArray ar = CreateDestinationArray(value, writer); PdfName kn = new PdfName(key); dic.Put(kn, ar); } catch { // empty on purpose } } return dic; }
public void SetMKIconFit(PdfName scale, PdfName scalingType, float leftoverLeft, float leftoverBottom, bool fitInBounds) { PdfDictionary dic = new PdfDictionary(); if (!scale.Equals(PdfName.A)) dic.Put(PdfName.SW, scale); if (!scalingType.Equals(PdfName.P)) dic.Put(PdfName.S, scalingType); if (leftoverLeft != 0.5f || leftoverBottom != 0.5f) { PdfArray array = new PdfArray(new PdfNumber(leftoverLeft)); array.Add(new PdfNumber(leftoverBottom)); dic.Put(PdfName.A, array); } if (fitInBounds) dic.Put(PdfName.FB, PdfBoolean.PDFTRUE); MK.Put(PdfName.IF, dic); }
/** * Signals that the <CODE>Document</CODE> has been opened and that * <CODE>Elements</CODE> can be added. * <P> * When this method is called, the PDF-document header is * written to the outputstream. */ public override void Open() { base.Open(); pdf_version.WriteHeader(os); body = new PdfBody(this); if (pdfxConformance.IsPdfX32002()) { PdfDictionary sec = new PdfDictionary(); sec.Put(PdfName.GAMMA, new PdfArray(new float[]{2.2f,2.2f,2.2f})); sec.Put(PdfName.MATRIX, new PdfArray(new float[]{0.4124f,0.2126f,0.0193f,0.3576f,0.7152f,0.1192f,0.1805f,0.0722f,0.9505f})); sec.Put(PdfName.WHITEPOINT, new PdfArray(new float[]{0.9505f,1f,1.089f})); PdfArray arr = new PdfArray(PdfName.CALRGB); arr.Add(sec); SetDefaultColorspace(PdfName.DEFAULTRGB, AddToBody(arr).IndirectReference); } }
/** 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; }
/** * Adds some <CODE>PdfContents</CODE> to this Writer. * <P> * The document has to be open before you can begin to add content * to the body of the document. * * @return a <CODE>PdfIndirectReference</CODE> * @param page the <CODE>PdfPage</CODE> to add * @param contents the <CODE>PdfContents</CODE> of the page * @throws PdfException on error */ internal virtual PdfIndirectReference Add(PdfPage page, PdfContents contents) { if (!open) { throw new PdfException("The document isn't open."); } PdfIndirectObject objecta; objecta = AddToBody(contents); page.Add(objecta.IndirectReference); if (group != null) { page.Put(PdfName.GROUP, group); group = null; } else if (rgbTransparencyBlending) { PdfDictionary pp = new PdfDictionary(); pp.Put(PdfName.TYPE, PdfName.GROUP); pp.Put(PdfName.S, PdfName.TRANSPARENCY); pp.Put(PdfName.CS, PdfName.DEVICERGB); page.Put(PdfName.GROUP, pp); } root.AddPage(page); currentPageNumber++; return null; }
/** 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; }
protected void FillOCProperties(bool erase) { if (vOCProperties == null) vOCProperties = new PdfOCProperties(); if (erase) { vOCProperties.Remove(PdfName.OCGS); vOCProperties.Remove(PdfName.D); } if (vOCProperties.Get(PdfName.OCGS) == null) { PdfArray gr = new PdfArray(); foreach (PdfLayer layer in documentOCG.Keys) { gr.Add(layer.Ref); } vOCProperties.Put(PdfName.OCGS, gr); } if (vOCProperties.Get(PdfName.D) != null) return; ArrayList docOrder = new ArrayList(documentOCGorder); for (ListIterator it = new ListIterator(docOrder); it.HasNext();) { PdfLayer layer = (PdfLayer)it.Next(); if (layer.Parent != null) it.Remove(); } PdfArray order = new PdfArray(); foreach (PdfLayer layer in docOrder) { GetOCGOrder(order, layer); } PdfDictionary d = new PdfDictionary(); vOCProperties.Put(PdfName.D, d); d.Put(PdfName.ORDER, order); PdfArray grx = new PdfArray(); foreach (PdfLayer layer in documentOCG.Keys) { if (!layer.On) grx.Add(layer.Ref); } if (grx.Size > 0) d.Put(PdfName.OFF, grx); if (OCGRadioGroup.Size > 0) d.Put(PdfName.RBGROUPS, OCGRadioGroup); if (OCGLocked.Size > 0) d.Put(PdfName.LOCKED, OCGLocked); AddASEvent(PdfName.VIEW, PdfName.ZOOM); AddASEvent(PdfName.VIEW, PdfName.VIEW); AddASEvent(PdfName.PRINT, PdfName.PRINT); AddASEvent(PdfName.EXPORT, PdfName.EXPORT); d.Put(PdfName.LISTMODE, PdfName.VISIBLEPAGES); }
/** 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; }
private void AddASEvent(PdfName eventa, PdfName category) { PdfArray arr = new PdfArray(); foreach (PdfLayer layer in documentOCG.Keys) { PdfDictionary usage = (PdfDictionary)layer.Get(PdfName.USAGE); if (usage != null && usage.Get(category) != null) arr.Add(layer.Ref); } if (arr.Size == 0) return; PdfDictionary d = (PdfDictionary)vOCProperties.Get(PdfName.D); PdfArray arras = (PdfArray)d.Get(PdfName.AS); if (arras == null) { arras = new PdfArray(); d.Put(PdfName.AS, arras); } PdfDictionary asa = new PdfDictionary(); asa.Put(PdfName.EVENT, eventa); asa.Put(PdfName.CATEGORY, new PdfArray(category)); asa.Put(PdfName.OCGS, arr); arras.Add(asa); }
/** 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; }
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; }
/** 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 GetFontDescriptor() { PdfDictionary dic = new PdfDictionary(PdfName.FONTDESCRIPTOR); dic.Put(PdfName.ASCENT, new PdfLiteral((String)fontDesc["Ascent"])); dic.Put(PdfName.CAPHEIGHT, new PdfLiteral((String)fontDesc["CapHeight"])); dic.Put(PdfName.DESCENT, new PdfLiteral((String)fontDesc["Descent"])); dic.Put(PdfName.FLAGS, new PdfLiteral((String)fontDesc["Flags"])); dic.Put(PdfName.FONTBBOX, new PdfLiteral((String)fontDesc["FontBBox"])); dic.Put(PdfName.FONTNAME, new PdfName(fontName + style)); dic.Put(PdfName.ITALICANGLE, new PdfLiteral((String)fontDesc["ItalicAngle"])); dic.Put(PdfName.STEMV, new PdfLiteral((String)fontDesc["StemV"])); PdfDictionary pdic = new PdfDictionary(); pdic.Put(PdfName.PANOSE, new PdfString((String)fontDesc["Panose"], null)); dic.Put(PdfName.STYLE, pdic); 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; }
/** * 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; } }
public PdfDictionary GetEncryptionDictionary() { PdfDictionary dic = new PdfDictionary(); if (publicKeyHandler.GetRecipientsSize() > 0) { PdfArray recipients = null; dic.Put(PdfName.FILTER, PdfName.PUBSEC); dic.Put(PdfName.R, new PdfNumber(revision)); recipients = publicKeyHandler.GetEncodedRecipients(); if (revision == STANDARD_ENCRYPTION_40) { dic.Put(PdfName.V, new PdfNumber(1)); dic.Put(PdfName.SUBFILTER, PdfName.ADBE_PKCS7_S4); dic.Put(PdfName.RECIPIENTS, recipients); } else if (revision == STANDARD_ENCRYPTION_128 && encryptMetadata) { dic.Put(PdfName.V, new PdfNumber(2)); dic.Put(PdfName.LENGTH, new PdfNumber(128)); dic.Put(PdfName.SUBFILTER, PdfName.ADBE_PKCS7_S4); dic.Put(PdfName.RECIPIENTS, recipients); } else { dic.Put(PdfName.R, new PdfNumber(AES_128)); dic.Put(PdfName.V, new PdfNumber(4)); dic.Put(PdfName.SUBFILTER, PdfName.ADBE_PKCS7_S5); PdfDictionary stdcf = new PdfDictionary(); stdcf.Put(PdfName.RECIPIENTS, recipients); if (!encryptMetadata) stdcf.Put(PdfName.ENCRYPTMETADATA, PdfBoolean.PDFFALSE); if (revision == AES_128) stdcf.Put(PdfName.CFM, PdfName.AESV2); else stdcf.Put(PdfName.CFM, PdfName.V2); PdfDictionary cf = new PdfDictionary(); cf.Put(PdfName.DEFAULTCRYPTFILTER, stdcf); dic.Put(PdfName.CF, cf); if (embeddedFilesOnly) { dic.Put(PdfName.EFF, PdfName.DEFAULTCRYPTFILTER); dic.Put(PdfName.STRF, PdfName.IDENTITY); dic.Put(PdfName.STMF, PdfName.IDENTITY); } else { dic.Put(PdfName.STRF, PdfName.DEFAULTCRYPTFILTER); dic.Put(PdfName.STMF, PdfName.DEFAULTCRYPTFILTER); } } SHA1 sh = new SHA1CryptoServiceProvider(); byte[] encodedRecipient = null; byte[] seed = publicKeyHandler.GetSeed(); sh.TransformBlock(seed, 0, seed.Length, seed, 0); for (int i=0; i<publicKeyHandler.GetRecipientsSize(); i++) { encodedRecipient = publicKeyHandler.GetEncodedRecipient(i); sh.TransformBlock(encodedRecipient, 0, encodedRecipient.Length, encodedRecipient, 0); } if (!encryptMetadata) sh.TransformBlock(metadataPad, 0, metadataPad.Length, metadataPad, 0); sh.TransformFinalBlock(seed, 0, 0); byte[] mdResult = sh.Hash; SetupByEncryptionKey(mdResult, keyLength); } else { dic.Put(PdfName.FILTER, PdfName.STANDARD); dic.Put(PdfName.O, new PdfLiteral(PdfContentByte.EscapeString(ownerKey))); dic.Put(PdfName.U, new PdfLiteral(PdfContentByte.EscapeString(userKey))); dic.Put(PdfName.P, new PdfNumber(permissions)); dic.Put(PdfName.R, new PdfNumber(revision)); if (revision == STANDARD_ENCRYPTION_40) { dic.Put(PdfName.V, new PdfNumber(1)); } else if (revision == STANDARD_ENCRYPTION_128 && encryptMetadata) { dic.Put(PdfName.V, new PdfNumber(2)); dic.Put(PdfName.LENGTH, new PdfNumber(128)); } else { if (!encryptMetadata) dic.Put(PdfName.ENCRYPTMETADATA, PdfBoolean.PDFFALSE); dic.Put(PdfName.R, new PdfNumber(AES_128)); dic.Put(PdfName.V, new PdfNumber(4)); dic.Put(PdfName.LENGTH, new PdfNumber(128)); PdfDictionary stdcf = new PdfDictionary(); stdcf.Put(PdfName.LENGTH, new PdfNumber(16)); if (embeddedFilesOnly) { stdcf.Put(PdfName.AUTHEVENT, PdfName.EFOPEN); dic.Put(PdfName.EFF, PdfName.STDCF); dic.Put(PdfName.STRF, PdfName.IDENTITY); dic.Put(PdfName.STMF, PdfName.IDENTITY); } else { stdcf.Put(PdfName.AUTHEVENT, PdfName.DOCOPEN); dic.Put(PdfName.STRF, PdfName.STDCF); dic.Put(PdfName.STMF, PdfName.STDCF); } if (revision == AES_128) stdcf.Put(PdfName.CFM, PdfName.AESV2); else stdcf.Put(PdfName.CFM, PdfName.V2); PdfDictionary cf = new PdfDictionary(); cf.Put(PdfName.STDCF, stdcf); dic.Put(PdfName.CF, cf); } } return dic; }