コード例 #1
0
ファイル: PdfAcroForm.cs プロジェクト: pixelia-es/RazorPDF2
 /**
  * Closes the AcroForm.
  */
 public bool IsValid()
 {
     if (documentFields.Size == 0) return false;
     Put(PdfName.FIELDS, documentFields);
     if (sigFlags != 0)
     Put(PdfName.SIGFLAGS, new PdfNumber(sigFlags));
     if (calculationOrder.Size > 0)
     Put(PdfName.CO, calculationOrder);
     if (fieldTemplates.Count == 0) return true;
     PdfDictionary dic = new PdfDictionary();
     foreach (PdfTemplate template in fieldTemplates.Keys) {
     PdfFormField.MergeResources(dic, (PdfDictionary)template.Resources);
     }
     Put(PdfName.DR, dic);
     Put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g "));
     PdfDictionary fonts = (PdfDictionary)dic.Get(PdfName.FONT);
     if (fonts != null) {
     writer.EliminateFontSubset(fonts);
     }
     return true;
 }
コード例 #2
0
        internal void MergeField(String name, AcroFields.Item item)
        {
            Hashtable       map = fieldTree;
            StringTokenizer tk  = new StringTokenizer(name, ".");

            if (!tk.HasMoreTokens())
            {
                return;
            }
            while (true)
            {
                String s   = tk.NextToken();
                Object obj = map[s];
                if (tk.HasMoreTokens())
                {
                    if (obj == null)
                    {
                        obj    = new Hashtable();
                        map[s] = obj;
                        map    = (Hashtable)obj;
                        continue;
                    }
                    else if (obj is Hashtable)
                    {
                        map = (Hashtable)obj;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    if (obj is Hashtable)
                    {
                        return;
                    }
                    PdfDictionary merged = item.GetMerged(0);
                    if (obj == null)
                    {
                        PdfDictionary field = new PdfDictionary();
                        if (PdfName.SIG.Equals(merged.Get(PdfName.FT)))
                        {
                            hasSignature = true;
                        }
                        foreach (PdfName key in merged.Keys)
                        {
                            if (fieldKeys.ContainsKey(key))
                            {
                                field.Put(key, merged.Get(key));
                            }
                        }
                        ArrayList list = new ArrayList();
                        list.Add(field);
                        CreateWidgets(list, item);
                        map[s] = list;
                    }
                    else
                    {
                        ArrayList     list  = (ArrayList)obj;
                        PdfDictionary field = (PdfDictionary)list[0];
                        PdfName       type1 = (PdfName)field.Get(PdfName.FT);
                        PdfName       type2 = (PdfName)merged.Get(PdfName.FT);
                        if (type1 == null || !type1.Equals(type2))
                        {
                            return;
                        }
                        int       flag1 = 0;
                        PdfObject f1    = field.Get(PdfName.FF);
                        if (f1 != null && f1.IsNumber())
                        {
                            flag1 = ((PdfNumber)f1).IntValue;
                        }
                        int       flag2 = 0;
                        PdfObject f2    = merged.Get(PdfName.FF);
                        if (f2 != null && f2.IsNumber())
                        {
                            flag2 = ((PdfNumber)f2).IntValue;
                        }
                        if (type1.Equals(PdfName.BTN))
                        {
                            if (((flag1 ^ flag2) & PdfFormField.FF_PUSHBUTTON) != 0)
                            {
                                return;
                            }
                            if ((flag1 & PdfFormField.FF_PUSHBUTTON) == 0 && ((flag1 ^ flag2) & PdfFormField.FF_RADIO) != 0)
                            {
                                return;
                            }
                        }
                        else if (type1.Equals(PdfName.CH))
                        {
                            if (((flag1 ^ flag2) & PdfFormField.FF_COMBO) != 0)
                            {
                                return;
                            }
                        }
                        CreateWidgets(list, item);
                    }
                    return;
                }
            }
        }
コード例 #3
0
ファイル: PdfWriter.cs プロジェクト: pixelia-es/RazorPDF2
 private static String GetNameString(PdfDictionary dic, PdfName key)
 {
     PdfObject obj = PdfReader.GetPdfObject(dic.Get(key));
     if (obj == null || !obj.IsString())
         return null;
     return ((PdfString)obj).ToUnicodeString();
 }
コード例 #4
0
ファイル: PageResources.cs プロジェクト: pixelia-es/RazorPDF2
 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);
         }
     }
 }
コード例 #5
0
        internal void Propagate(PdfObject obj, PdfIndirectReference refo, bool restricted)
        {
            if (obj == null)
            {
                return;
            }
            //        if (refo != null)
            //            AddToBody(obj, refo);
            if (obj is PdfIndirectReference)
            {
                return;
            }
            switch (obj.Type)
            {
            case PdfObject.DICTIONARY:
            case PdfObject.STREAM: {
                PdfDictionary dic = (PdfDictionary)obj;
                foreach (PdfName key in dic.Keys)
                {
                    if (restricted && (key.Equals(PdfName.PARENT) || key.Equals(PdfName.KIDS)))
                    {
                        continue;
                    }
                    PdfObject ob = dic.Get(key);
                    if (ob != null && ob.IsIndirect())
                    {
                        PRIndirectReference ind = (PRIndirectReference)ob;
                        if (!SetVisited(ind) && !IsPage(ind))
                        {
                            PdfIndirectReference refi = GetNewReference(ind);
                            Propagate(PdfReader.GetPdfObjectRelease(ind), refi, restricted);
                        }
                    }
                    else
                    {
                        Propagate(ob, null, restricted);
                    }
                }
                break;
            }

            case PdfObject.ARRAY: {
                //PdfArray arr = new PdfArray();
                for (ListIterator it = ((PdfArray)obj).GetListIterator(); it.HasNext();)
                {
                    PdfObject ob = (PdfObject)it.Next();
                    if (ob != null && ob.IsIndirect())
                    {
                        PRIndirectReference ind = (PRIndirectReference)ob;
                        if (!IsVisited(ind) && !IsPage(ind))
                        {
                            PdfIndirectReference refi = GetNewReference(ind);
                            Propagate(PdfReader.GetPdfObjectRelease(ind), refi, restricted);
                        }
                    }
                    else
                    {
                        Propagate(ob, null, restricted);
                    }
                }
                break;
            }

            case PdfObject.INDIRECT: {
                throw new Exception("Reference pointing to reference.");
            }
            }
        }
コード例 #6
0
ファイル: PdfFormField.cs プロジェクト: pixelia-es/RazorPDF2
 internal static void MergeResources(PdfDictionary result, PdfDictionary source, PdfStamperImp writer)
 {
     PdfDictionary dic = null;
     PdfDictionary res = null;
     PdfName target = null;
     for (int k = 0; k < mergeTarget.Length; ++k) {
         target = mergeTarget[k];
         PdfDictionary pdfDict = source.GetAsDict(target);
         if ((dic = pdfDict) != null) {
             if ((res = (PdfDictionary)PdfReader.GetPdfObject(result.Get(target), result)) == null) {
                 res = new PdfDictionary();
             }
             res.MergeDifferent(dic);
             result.Put(target, res);
             if (writer != null)
                 writer.MarkUsed(res);
         }
     }
 }
コード例 #7
0
ファイル: PdfSmartCopy.cs プロジェクト: pixelia-es/RazorPDF2
 private void SerDic(PdfDictionary dic, int level, ByteBuffer bb)
 {
     bb.Append("$D");
     if (level <= 0)
         return;
     Object[] keys = new Object[dic.Size];
     dic.Keys.CopyTo(keys, 0);
     Array.Sort(keys);
     for (int k = 0; k < keys.Length; ++k) {
         SerObject((PdfObject)keys[k], level, bb);
         SerObject(dic.Get((PdfName)keys[k]), level, bb);
     }
 }
コード例 #8
0
        /**
         * Retrieves the page labels from a PDF as an array of {@link PdfPageLabelFormat} objects.
         * @param reader a PdfReader object that has the page labels you want to retrieve
         * @return  a PdfPageLabelEntry array, containing an entry for each format change
         * or <code>null</code> if no page labels are present
         */
        public static PdfPageLabelFormat[] GetPageLabelFormats(PdfReader reader)
        {
            PdfDictionary dict   = reader.Catalog;
            PdfDictionary labels = (PdfDictionary)PdfReader.GetPdfObjectRelease(dict.Get(PdfName.PAGELABELS));

            if (labels == null)
            {
                return(null);
            }
            Hashtable numberTree = PdfNumberTree.ReadTree(labels);

            int[] numbers = new int[numberTree.Count];
            numberTree.Keys.CopyTo(numbers, 0);
            Array.Sort(numbers);
            PdfPageLabelFormat[] formats = new PdfPageLabelFormat[numberTree.Count];
            String prefix;
            int    numberStyle;
            int    pagecount;

            for (int k = 0; k < numbers.Length; ++k)
            {
                int           key = numbers[k];
                PdfDictionary d   = (PdfDictionary)PdfReader.GetPdfObjectRelease((PdfObject)numberTree[key]);
                if (d.Contains(PdfName.ST))
                {
                    pagecount = ((PdfNumber)d.Get(PdfName.ST)).IntValue;
                }
                else
                {
                    pagecount = 1;
                }
                if (d.Contains(PdfName.P))
                {
                    prefix = ((PdfString)d.Get(PdfName.P)).ToUnicodeString();
                }
                else
                {
                    prefix = "";
                }
                if (d.Contains(PdfName.S))
                {
                    char type = ((PdfName)d.Get(PdfName.S)).ToString()[1];
                    switch (type)
                    {
                    case 'R': numberStyle = UPPERCASE_ROMAN_NUMERALS; break;

                    case 'r': numberStyle = LOWERCASE_ROMAN_NUMERALS; break;

                    case 'A': numberStyle = UPPERCASE_LETTERS; break;

                    case 'a': numberStyle = LOWERCASE_LETTERS; break;

                    default: numberStyle = DECIMAL_ARABIC_NUMERALS; break;
                    }
                }
                else
                {
                    numberStyle = EMPTY;
                }
                formats[k] = new PdfPageLabelFormat(key + 1, numberStyle, prefix, pagecount);
            }
            return(formats);
        }
コード例 #9
0
ファイル: PdfCopy.cs プロジェクト: pixelia-es/RazorPDF2
            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);
            }
コード例 #10
0
 public void CompleteInfoDictionary(PdfDictionary info)
 {
     if (IsPdfX() && !IsPdfA1()) {
         if (info.Get(PdfName.GTS_PDFXVERSION) == null) {
             if (IsPdfX1A2001()) {
                 info.Put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-1:2001"));
                 info.Put(new PdfName("GTS_PDFXConformance"), new PdfString("PDF/X-1a:2001"));
             }
             else if (IsPdfX32002())
                 info.Put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-3:2002"));
         }
         if (info.Get(PdfName.TITLE) == null) {
             info.Put(PdfName.TITLE, new PdfString("Pdf document"));
         }
         if (info.Get(PdfName.CREATOR) == null) {
             info.Put(PdfName.CREATOR, new PdfString("Unknown"));
         }
         if (info.Get(PdfName.TRAPPED) == null) {
             info.Put(PdfName.TRAPPED, new PdfName("False"));
         }
     }
 }
コード例 #11
0
        /**
         * Retrieves the page labels from a PDF as an array of String objects.
         * @param reader a PdfReader object that has the page labels you want to retrieve
         * @return  a String array or <code>null</code> if no page labels are present
         */
        public static String[] GetPageLabels(PdfReader reader)
        {
            int n = reader.NumberOfPages;

            PdfDictionary dict   = reader.Catalog;
            PdfDictionary labels = (PdfDictionary)PdfReader.GetPdfObjectRelease(dict.Get(PdfName.PAGELABELS));

            if (labels == null)
            {
                return(null);
            }

            String[]  labelstrings = new String[n];
            Hashtable numberTree   = PdfNumberTree.ReadTree(labels);

            int    pagecount = 1;
            String prefix    = "";
            char   type      = 'D';

            for (int i = 0; i < n; i++)
            {
                if (numberTree.ContainsKey(i))
                {
                    PdfDictionary d = (PdfDictionary)PdfReader.GetPdfObjectRelease((PdfObject)numberTree[i]);
                    if (d.Contains(PdfName.ST))
                    {
                        pagecount = ((PdfNumber)d.Get(PdfName.ST)).IntValue;
                    }
                    else
                    {
                        pagecount = 1;
                    }
                    if (d.Contains(PdfName.P))
                    {
                        prefix = ((PdfString)d.Get(PdfName.P)).ToUnicodeString();
                    }
                    if (d.Contains(PdfName.S))
                    {
                        type = ((PdfName)d.Get(PdfName.S)).ToString()[1];
                    }
                }
                switch (type)
                {
                default:
                    labelstrings[i] = prefix + pagecount;
                    break;

                case 'R':
                    labelstrings[i] = prefix + RomanNumberFactory.GetUpperCaseString(pagecount);
                    break;

                case 'r':
                    labelstrings[i] = prefix + RomanNumberFactory.GetLowerCaseString(pagecount);
                    break;

                case 'A':
                    labelstrings[i] = prefix + RomanAlphabetFactory.GetUpperCaseString(pagecount);
                    break;

                case 'a':
                    labelstrings[i] = prefix + RomanAlphabetFactory.GetLowerCaseString(pagecount);
                    break;
                }
                pagecount++;
            }
            return(labelstrings);
        }
コード例 #12
0
 public void CompleteExtraCatalog(PdfDictionary extraCatalog)
 {
     if (IsPdfX() && !IsPdfA1()) {
         if (extraCatalog.Get(PdfName.OUTPUTINTENTS) == null) {
             PdfDictionary outp = new PdfDictionary(PdfName.OUTPUTINTENT);
             outp.Put(PdfName.OUTPUTCONDITION, new PdfString("SWOP CGATS TR 001-1995"));
             outp.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("CGATS TR 001"));
             outp.Put(PdfName.REGISTRYNAME, new PdfString("http://www.color.org"));
             outp.Put(PdfName.INFO, new PdfString(""));
             outp.Put(PdfName.S, PdfName.GTS_PDFX);
             extraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(outp));
         }
     }
 }
コード例 #13
0
ファイル: PRAcroForm.cs プロジェクト: pixelia-es/RazorPDF2
        /**
        * merge field attributes from two dictionaries
        * @param parent one dictionary
        * @param child the other dictionary
        * @return a merged dictionary
        */
        protected PdfDictionary MergeAttrib(PdfDictionary parent, PdfDictionary child)
        {
            PdfDictionary targ = new PdfDictionary();
            if (parent != null) targ.Merge(parent);

            foreach (PdfName key in child.Keys) {
                if (key.Equals(PdfName.DR) || key.Equals(PdfName.DA) ||
                key.Equals(PdfName.Q)  || key.Equals(PdfName.FF) ||
                key.Equals(PdfName.DV) || key.Equals(PdfName.V)
                || key.Equals(PdfName.FT)
                || key.Equals(PdfName.F)) {
                    targ.Put(key,child.Get(key));
                }
            }
            return targ;
        }
コード例 #14
0
ファイル: PRAcroForm.cs プロジェクト: pixelia-es/RazorPDF2
 /**
 * Read, and comprehend the acroform
 * @param root the docment root
 */
 public void ReadAcroForm(PdfDictionary root)
 {
     if (root == null)
         return;
     hashMap = root.hashMap;
     PushAttrib(root);
     PdfArray fieldlist = (PdfArray)PdfReader.GetPdfObjectRelease(root.Get(PdfName.FIELDS));
     IterateFields(fieldlist, null, null);
 }
コード例 #15
0
ファイル: DocumentFont.cs プロジェクト: pixelia-es/RazorPDF2
        private void DoType1TT()
        {
            PdfObject enc = PdfReader.GetPdfObject(font.Get(PdfName.ENCODING));

            if (enc == null)
            {
                FillEncoding(null);
            }
            else
            {
                if (enc.IsName())
                {
                    FillEncoding((PdfName)enc);
                }
                else
                {
                    PdfDictionary encDic = (PdfDictionary)enc;
                    enc = PdfReader.GetPdfObject(encDic.Get(PdfName.BASEENCODING));
                    if (enc == null)
                    {
                        FillEncoding(null);
                    }
                    else
                    {
                        FillEncoding((PdfName)enc);
                    }
                    PdfArray diffs = encDic.GetAsArray(PdfName.DIFFERENCES);
                    if (diffs != null)
                    {
                        diffmap = new IntHashtable();
                        int currentNumber = 0;
                        for (int k = 0; k < diffs.Size; ++k)
                        {
                            PdfObject obj = diffs[k];
                            if (obj.IsNumber())
                            {
                                currentNumber = ((PdfNumber)obj).IntValue;
                            }
                            else
                            {
                                int[] c = GlyphList.NameToUnicode(PdfName.DecodeName(((PdfName)obj).ToString()));
                                if (c != null && c.Length > 0)
                                {
                                    uni2byte[c[0]] = currentNumber;
                                    diffmap[c[0]]  = currentNumber;
                                }
                                ++currentNumber;
                            }
                        }
                    }
                }
            }
            PdfArray  newWidths = font.GetAsArray(PdfName.WIDTHS);
            PdfNumber first     = font.GetAsNumber(PdfName.FIRSTCHAR);
            PdfNumber last      = font.GetAsNumber(PdfName.LASTCHAR);

            if (BuiltinFonts14.ContainsKey(fontName))
            {
                BaseFont bf;
                bf = BaseFont.CreateFont(fontName, WINANSI, false);
                int[] e = uni2byte.ToOrderedKeys();
                for (int k = 0; k < e.Length; ++k)
                {
                    int n = uni2byte[e[k]];
                    widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k]));
                }
                if (diffmap != null)   //widths for differences must override existing ones
                {
                    e = diffmap.ToOrderedKeys();
                    for (int k = 0; k < e.Length; ++k)
                    {
                        int n = diffmap[e[k]];
                        widths[n] = bf.GetRawWidth(n, GlyphList.UnicodeToName(e[k]));
                    }
                    diffmap = null;
                }
                Ascender    = bf.GetFontDescriptor(ASCENT, 1000);
                CapHeight   = bf.GetFontDescriptor(CAPHEIGHT, 1000);
                Descender   = bf.GetFontDescriptor(DESCENT, 1000);
                ItalicAngle = bf.GetFontDescriptor(ITALICANGLE, 1000);
                llx         = bf.GetFontDescriptor(BBOXLLX, 1000);
                lly         = bf.GetFontDescriptor(BBOXLLY, 1000);
                urx         = bf.GetFontDescriptor(BBOXURX, 1000);
                ury         = bf.GetFontDescriptor(BBOXURY, 1000);
            }
            if (first != null && last != null && newWidths != null)
            {
                int f = first.IntValue;
                for (int k = 0; k < newWidths.Size; ++k)
                {
                    widths[f + k] = newWidths.GetAsNumber(k).IntValue;
                }
            }
            FillFontDesc(font.GetAsDict(PdfName.FONTDESCRIPTOR));
        }
コード例 #16
0
 public static PdfViewerPreferencesImp GetViewerPreferences(PdfDictionary catalog)
 {
     PdfViewerPreferencesImp preferences = new PdfViewerPreferencesImp();
     int prefs = 0;
     PdfName name = null;
     // page layout
     PdfObject obj = PdfReader.GetPdfObjectRelease(catalog.Get(PdfName.PAGELAYOUT));
     if (obj != null && obj.IsName()) {
         name = (PdfName) obj;
         if (name.Equals(PdfName.SINGLEPAGE))
             prefs |= PdfWriter.PageLayoutSinglePage;
         else if (name.Equals(PdfName.ONECOLUMN))
             prefs |= PdfWriter.PageLayoutOneColumn;
         else if (name.Equals(PdfName.TWOCOLUMNLEFT))
             prefs |= PdfWriter.PageLayoutTwoColumnLeft;
         else if (name.Equals(PdfName.TWOCOLUMNRIGHT))
             prefs |= PdfWriter.PageLayoutTwoColumnRight;
         else if (name.Equals(PdfName.TWOPAGELEFT))
             prefs |= PdfWriter.PageLayoutTwoPageLeft;
         else if (name.Equals(PdfName.TWOPAGERIGHT))
             prefs |= PdfWriter.PageLayoutTwoPageRight;
     }
     // page mode
     obj = PdfReader.GetPdfObjectRelease(catalog.Get(PdfName.PAGEMODE));
     if (obj != null && obj.IsName()) {
         name = (PdfName) obj;
         if (name.Equals(PdfName.USENONE))
             prefs |= PdfWriter.PageModeUseNone;
         else if (name.Equals(PdfName.USEOUTLINES))
             prefs |= PdfWriter.PageModeUseOutlines;
         else if (name.Equals(PdfName.USETHUMBS))
             prefs |= PdfWriter.PageModeUseThumbs;
         else if (name.Equals(PdfName.FULLSCREEN))
             prefs |= PdfWriter.PageModeFullScreen;
         else if (name.Equals(PdfName.USEOC))
             prefs |= PdfWriter.PageModeUseOC;
         else if (name.Equals(PdfName.USEATTACHMENTS))
             prefs |= PdfWriter.PageModeUseAttachments;
     }
     // set page layout and page mode preferences
     preferences.ViewerPreferences = prefs;
     // other preferences
     obj = PdfReader.GetPdfObjectRelease(catalog
             .Get(PdfName.VIEWERPREFERENCES));
     if (obj != null && obj.IsDictionary()) {
         PdfDictionary vp = (PdfDictionary) obj;
         for (int i = 0; i < VIEWER_PREFERENCES.Length; i++) {
             obj = PdfReader.GetPdfObjectRelease(vp.Get(VIEWER_PREFERENCES[i]));
             preferences.AddViewerPreference(VIEWER_PREFERENCES[i], obj);
         }
     }
     return preferences;
 }
コード例 #17
0
        /**
         * Gets a <CODE>List</CODE> with the bookmarks. It returns <CODE>null</CODE> if
         * the document doesn't have any bookmarks.
         * @param reader the document
         * @return a <CODE>List</CODE> with the bookmarks or <CODE>null</CODE> if the
         * document doesn't have any
         */
        public static ArrayList GetBookmark(PdfReader reader)
        {
            PdfDictionary catalog = reader.Catalog;
            PdfObject     obj     = PdfReader.GetPdfObjectRelease(catalog.Get(PdfName.OUTLINES));

            if (obj == null || !obj.IsDictionary())
            {
                return(null);
            }
            PdfDictionary outlines = (PdfDictionary)obj;
            IntHashtable  pages    = new IntHashtable();
            int           numPages = reader.NumberOfPages;

            for (int k = 1; k <= numPages; ++k)
            {
                pages[reader.GetPageOrigRef(k).Number] = k;
                reader.ReleasePage(k);
            }
            return(BookmarkDepth(reader, (PdfDictionary)PdfReader.GetPdfObjectRelease(outlines.Get(PdfName.FIRST)), pages));
        }
コード例 #18
0
ファイル: DocumentFont.cs プロジェクト: pixelia-es/RazorPDF2
 private void ProcessType0(PdfDictionary font)
 {
     PdfObject toUniObject = PdfReader.GetPdfObjectRelease(font.Get(PdfName.TOUNICODE));
     PdfArray df = (PdfArray)PdfReader.GetPdfObjectRelease(font.Get(PdfName.DESCENDANTFONTS));
     PdfDictionary cidft = (PdfDictionary)PdfReader.GetPdfObjectRelease(df[0]);
     PdfNumber dwo = (PdfNumber)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.DW));
     int dw = 1000;
     if (dwo != null)
         dw = dwo.IntValue;
     IntHashtable widths = ReadWidths((PdfArray)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.W)));
     PdfDictionary fontDesc = (PdfDictionary)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.FONTDESCRIPTOR));
     FillFontDesc(fontDesc);
     if (toUniObject != null){
         FillMetrics(PdfReader.GetStreamBytes((PRStream)toUniObject), widths, dw);
     }
 }
コード例 #19
0
 protected PdfArray BranchForm(Hashtable level, PdfIndirectReference parent, String fname)
 {
     PdfArray arr = new PdfArray();
     foreach (DictionaryEntry entry in level) {
         String name = (String)entry.Key;
         Object obj = entry.Value;
         PdfIndirectReference ind = PdfIndirectReference;
         PdfDictionary dic = new PdfDictionary();
         if (parent != null)
             dic.Put(PdfName.PARENT, parent);
         dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
         String fname2 = fname + "." + name;
         int coidx = calculationOrder.IndexOf(fname2);
         if (coidx >= 0)
             calculationOrderRefs[coidx] = ind;
         if (obj is Hashtable) {
             dic.Put(PdfName.KIDS, BranchForm((Hashtable)obj, ind, fname2));
             arr.Add(ind);
             AddToBody(dic, ind);
         }
         else {
             ArrayList list = (ArrayList)obj;
             dic.MergeDifferent((PdfDictionary)list[0]);
             if (list.Count == 3) {
                 dic.MergeDifferent((PdfDictionary)list[2]);
                 int page = (int)list[1];
                 PdfDictionary pageDic = (PdfDictionary)pageDics[page - 1];
                 PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
                 if (annots == null) {
                     annots = new PdfArray();
                     pageDic.Put(PdfName.ANNOTS, annots);
                 }
                 PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                 dic.Remove(iTextTag);
                 AdjustTabOrder(annots, ind, nn);
             }
             else {
                 PdfArray kids = new PdfArray();
                 for (int k = 1; k < list.Count; k += 2) {
                     int page = (int)list[k];
                     PdfDictionary pageDic = (PdfDictionary)pageDics[page - 1];
                     PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
                     if (annots == null) {
                         annots = new PdfArray();
                         pageDic.Put(PdfName.ANNOTS, annots);
                     }
                     PdfDictionary widget = new PdfDictionary();
                     widget.Merge((PdfDictionary)list[k + 1]);
                     widget.Put(PdfName.PARENT, ind);
                     PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
                     widget.Remove(iTextTag);
                     PdfIndirectReference wref = AddToBody(widget).IndirectReference;
                     AdjustTabOrder(annots, wref, nn);
                     kids.Add(wref);
                     Propagate(widget, null, false);
                 }
                 dic.Put(PdfName.KIDS, kids);
             }
             arr.Add(ind);
             AddToBody(dic, ind);
             Propagate(dic, null, false);
         }
     }
     return arr;
 }
コード例 #20
0
 private void NodeProcess(PdfDictionary struc, PdfIndirectReference reference)
 {
     PdfObject obj = struc.Get(PdfName.K);
     if (obj != null && obj.IsArray() && !((PdfObject)((PdfArray)obj).ArrayList[0]).IsNumber()) {
         PdfArray ar = (PdfArray)obj;
         ArrayList a = ar.ArrayList;
         for (int k = 0; k < a.Count; ++k) {
             PdfStructureElement e = (PdfStructureElement)a[k];
             a[k] = e.Reference;
             NodeProcess(e, e.Reference);
         }
     }
     if (reference != null)
         writer.AddToBody(struc, reference);
 }
コード例 #21
0
ファイル: PdfCopy.cs プロジェクト: pixelia-es/RazorPDF2
        /**
        * 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;
        }
コード例 #22
0
 private void Init(PdfDictionary parent, PdfName structureType)
 {
     PdfObject kido = parent.Get(PdfName.K);
     PdfArray kids = null;
     if (kido != null && !kido.IsArray())
         throw new ArgumentException("The parent has already another function.");
     if (kido == null) {
         kids = new PdfArray();
         parent.Put(PdfName.K, kids);
     }
     else
         kids = (PdfArray)kido;
     kids.Add(this);
     Put(PdfName.S, structureType);
     reference = top.Writer.PdfIndirectReference;
 }
コード例 #23
0
ファイル: PdfNumberTree.cs プロジェクト: pixelia-es/RazorPDF2
 private static void IterateItems(PdfDictionary dic, Hashtable items)
 {
     PdfArray nn = (PdfArray)PdfReader.GetPdfObjectRelease(dic.Get(PdfName.NUMS));
     if (nn != null) {
         for (int k = 0; k < nn.Size; ++k) {
             PdfNumber s = (PdfNumber)PdfReader.GetPdfObjectRelease(nn[k++]);
             items[s.IntValue] = nn[k];
         }
     }
     else if ((nn = (PdfArray)PdfReader.GetPdfObjectRelease(dic.Get(PdfName.KIDS))) != null) {
         for (int k = 0; k < nn.Size; ++k) {
             PdfDictionary kid = (PdfDictionary)PdfReader.GetPdfObjectRelease(nn[k]);
             IterateItems(kid, items);
         }
     }
 }
コード例 #24
0
ファイル: PdfStamperImp.cs プロジェクト: pixelia-es/RazorPDF2
 internal void AddAnnotation(PdfAnnotation annot, PdfDictionary pageN)
 {
     ArrayList allAnnots = new ArrayList();
     if (annot.IsForm()) {
         fieldsAdded = true;
         AcroFields afdummy = AcroFields;
         PdfFormField field = (PdfFormField)annot;
         if (field.Parent != null)
             return;
         ExpandFields(field, allAnnots);
     }
     else
         allAnnots.Add(annot);
     for (int k = 0; k < allAnnots.Count; ++k) {
         annot = (PdfAnnotation)allAnnots[k];
         if (annot.PlaceInPage > 0)
             pageN = reader.GetPageN(annot.PlaceInPage);
         if (annot.IsForm()) {
             if (!annot.IsUsed()) {
                 Hashtable templates = annot.Templates;
                 if (templates != null) {
                     foreach (object tpl in templates.Keys) {
                         fieldTemplates[tpl] = null;
                     }
                 }
             }
             PdfFormField field = (PdfFormField)annot;
             if (field.Parent == null)
                 AddDocumentField(field.IndirectReference);
         }
         if (annot.IsAnnotation()) {
             PdfObject pdfobj = PdfReader.GetPdfObject(pageN.Get(PdfName.ANNOTS), pageN);
             PdfArray annots = null;
             if (pdfobj == null || !pdfobj.IsArray()) {
                 annots = new PdfArray();
                 pageN.Put(PdfName.ANNOTS, annots);
                 MarkUsed(pageN);
             }
             else
                annots = (PdfArray)pdfobj;
             annots.Add(annot.IndirectReference);
             MarkUsed(annots);
             if (!annot.IsUsed()) {
                 PdfRectangle rect = (PdfRectangle)annot.Get(PdfName.RECT);
                 if (rect != null && (rect.Left != 0 || rect.Right != 0 || rect.Top != 0 || rect.Bottom != 0)) {
                     int rotation = reader.GetPageRotation(pageN);
                     Rectangle pageSize = reader.GetPageSizeWithRotation(pageN);
                     switch (rotation) {
                         case 90:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 pageSize.Top - rect.Bottom,
                                 rect.Left,
                                 pageSize.Top - rect.Top,
                                 rect.Right));
                             break;
                         case 180:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 pageSize.Right - rect.Left,
                                 pageSize.Top - rect.Bottom,
                                 pageSize.Right - rect.Right,
                                 pageSize.Top - rect.Top));
                             break;
                         case 270:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 rect.Bottom,
                                 pageSize.Right - rect.Left,
                                 rect.Top,
                                 pageSize.Right - rect.Right));
                             break;
                     }
                 }
             }
         }
         if (!annot.IsUsed()) {
             annot.SetUsed();
             AddToBody(annot, annot.IndirectReference);
         }
     }
 }
コード例 #25
0
        protected PdfArray BranchForm(Hashtable level, PdfIndirectReference parent, String fname)
        {
            PdfArray arr = new PdfArray();

            foreach (DictionaryEntry entry in level)
            {
                String name = (String)entry.Key;
                Object obj  = entry.Value;
                PdfIndirectReference ind = PdfIndirectReference;
                PdfDictionary        dic = new PdfDictionary();
                if (parent != null)
                {
                    dic.Put(PdfName.PARENT, parent);
                }
                dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
                String fname2 = fname + "." + name;
                int    coidx  = calculationOrder.IndexOf(fname2);
                if (coidx >= 0)
                {
                    calculationOrderRefs[coidx] = ind;
                }
                if (obj is Hashtable)
                {
                    dic.Put(PdfName.KIDS, BranchForm((Hashtable)obj, ind, fname2));
                    arr.Add(ind);
                    AddToBody(dic, ind);
                }
                else
                {
                    ArrayList list = (ArrayList)obj;
                    dic.MergeDifferent((PdfDictionary)list[0]);
                    if (list.Count == 3)
                    {
                        dic.MergeDifferent((PdfDictionary)list[2]);
                        int           page    = (int)list[1];
                        PdfDictionary pageDic = (PdfDictionary)pageDics[page - 1];
                        PdfArray      annots  = pageDic.GetAsArray(PdfName.ANNOTS);
                        if (annots == null)
                        {
                            annots = new PdfArray();
                            pageDic.Put(PdfName.ANNOTS, annots);
                        }
                        PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                        dic.Remove(iTextTag);
                        AdjustTabOrder(annots, ind, nn);
                    }
                    else
                    {
                        PdfArray kids = new PdfArray();
                        for (int k = 1; k < list.Count; k += 2)
                        {
                            int           page    = (int)list[k];
                            PdfDictionary pageDic = (PdfDictionary)pageDics[page - 1];
                            PdfArray      annots  = pageDic.GetAsArray(PdfName.ANNOTS);
                            if (annots == null)
                            {
                                annots = new PdfArray();
                                pageDic.Put(PdfName.ANNOTS, annots);
                            }
                            PdfDictionary widget = new PdfDictionary();
                            widget.Merge((PdfDictionary)list[k + 1]);
                            widget.Put(PdfName.PARENT, ind);
                            PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
                            widget.Remove(iTextTag);
                            PdfIndirectReference wref = AddToBody(widget).IndirectReference;
                            AdjustTabOrder(annots, wref, nn);
                            kids.Add(wref);
                            Propagate(widget, null, false);
                        }
                        dic.Put(PdfName.KIDS, kids);
                    }
                    arr.Add(ind);
                    AddToBody(dic, ind);
                    Propagate(dic, null, false);
                }
            }
            return(arr);
        }
コード例 #26
0
ファイル: BaseField.cs プロジェクト: pixelia-es/RazorPDF2
 /**
 * Moves the field keys from <CODE>from</CODE> to <CODE>to</CODE>. The moved keys
 * are removed from <CODE>from</CODE>.
 * @param from the source
 * @param to the destination. It may be <CODE>null</CODE>
 */
 public static void MoveFields(PdfDictionary from, PdfDictionary to)
 {
     PdfName[] keys = new PdfName[from.Size];
     foreach (PdfName key in keys) {
         if (fieldKeys.ContainsKey(key)) {
             if (to != null)
                 to.Put(key, from.Get(key));
             from.Remove(key);
         }
     }
 }
コード例 #27
0
ファイル: PdfWriter.cs プロジェクト: pixelia-es/RazorPDF2
 internal void EliminateFontSubset(PdfDictionary fonts)
 {
     foreach (FontDetails ft in documentFonts.Values) {
         if (fonts.Get(ft.FontName) != null)
             ft.Subset = false;
     }
 }
コード例 #28
0
 /**
 * This is the last method to be called when using external signatures. The general sequence is:
 * PreClose(), GetDocumentBytes() and Close().
 * <p>
 * <CODE>update</CODE> is a <CODE>PdfDictionary</CODE> that must have exactly the
 * same keys as the ones provided in {@link #preClose(Hashtable)}.
 * @param update a <CODE>PdfDictionary</CODE> with the key/value that will fill the holes defined
 * in {@link #preClose(Hashtable)}
 * @throws DocumentException on error
 * @throws IOException on error
 */
 public void Close(PdfDictionary update)
 {
     try {
         if (!preClosed)
             throw new DocumentException("preClose() must be called first.");
         ByteBuffer bf = new ByteBuffer();
         foreach (PdfName key in update.Keys) {
             PdfObject obj = update.Get(key);
             PdfLiteral lit = (PdfLiteral)exclusionLocations[key];
             if (lit == null)
                 throw new ArgumentException("The key " + key.ToString() + " didn't reserve space in PreClose().");
             bf.Reset();
             obj.ToPdf(null, bf);
             if (bf.Size > lit.PosLength)
                 throw new ArgumentException("The key " + key.ToString() + " is too big. Is " + bf.Size + ", reserved " + lit.PosLength);
             if (tempFile == null)
                 Array.Copy(bf.Buffer, 0, bout, lit.Position, bf.Size);
             else {
                 raf.Seek(lit.Position, SeekOrigin.Begin);
                 raf.Write(bf.Buffer, 0, bf.Size);
             }
         }
         if (update.Size != exclusionLocations.Count)
             throw new ArgumentException("The update dictionary has less keys than required.");
         if (tempFile == null) {
             originalout.Write(bout, 0, boutLen);
         }
         else {
             if (originalout != null) {
                 raf.Seek(0, SeekOrigin.Begin);
                 int length = (int)raf.Length;
                 byte[] buf = new byte[8192];
                 while (length > 0) {
                     int r = raf.Read(buf, 0, Math.Min(buf.Length, length));
                     if (r < 0)
                         throw new EndOfStreamException("Unexpected EOF");
                     originalout.Write(buf, 0, r);
                     length -= r;
                 }
             }
         }
     }
     finally {
         if (tempFile != null) {
             try{raf.Close();}catch{}
             if (originalout != null)
                 try{File.Delete(tempFile);}catch{}
         }
         if (originalout != null)
             try{originalout.Close();}catch{}
     }
 }
コード例 #29
0
ファイル: PdfNameTree.cs プロジェクト: pixelia-es/RazorPDF2
 private static void IterateItems(PdfDictionary dic, Hashtable items)
 {
     PdfArray nn = (PdfArray)PdfReader.GetPdfObjectRelease(dic.Get(PdfName.NAMES));
     if (nn != null) {
         for (int k = 0; k < nn.Size; ++k) {
             PdfString s = (PdfString)PdfReader.GetPdfObjectRelease(nn[k++]);
             items[PdfEncodings.ConvertToString(s.GetBytes(), null)] = nn[k];
         }
     }
     else if ((nn = (PdfArray)PdfReader.GetPdfObjectRelease(dic.Get(PdfName.KIDS))) != null) {
         for (int k = 0; k < nn.Size; ++k) {
             PdfDictionary kid = (PdfDictionary)PdfReader.GetPdfObjectRelease(nn[k]);
             IterateItems(kid, items);
         }
     }
 }
コード例 #30
0
        private static ArrayList BookmarkDepth(PdfReader reader, PdfDictionary outline, IntHashtable pages)
        {
            ArrayList list = new ArrayList();

            while (outline != null)
            {
                Hashtable map   = new Hashtable();
                PdfString title = (PdfString)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.TITLE));
                map["Title"] = title.ToUnicodeString();
                PdfArray color = (PdfArray)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.C));
                if (color != null && color.Size == 3)
                {
                    ByteBuffer outp = new ByteBuffer();
                    outp.Append(color.GetAsNumber(0).FloatValue).Append(' ');
                    outp.Append(color.GetAsNumber(1).FloatValue).Append(' ');
                    outp.Append(color.GetAsNumber(2).FloatValue);
                    map["Color"] = PdfEncodings.ConvertToString(outp.ToByteArray(), null);
                }
                PdfNumber style = (PdfNumber)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.F));
                if (style != null)
                {
                    int    f = style.IntValue;
                    String s = "";
                    if ((f & 1) != 0)
                    {
                        s += "italic ";
                    }
                    if ((f & 2) != 0)
                    {
                        s += "bold ";
                    }
                    s = s.Trim();
                    if (s.Length != 0)
                    {
                        map["Style"] = s;
                    }
                }
                PdfNumber count = (PdfNumber)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.COUNT));
                if (count != null && count.IntValue < 0)
                {
                    map["Open"] = "false";
                }
                try {
                    PdfObject dest = PdfReader.GetPdfObjectRelease(outline.Get(PdfName.DEST));
                    if (dest != null)
                    {
                        MapGotoBookmark(map, dest, pages); //changed by ujihara 2004-06-13
                    }
                    else
                    {
                        PdfDictionary action = (PdfDictionary)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.A));
                        if (action != null)
                        {
                            if (PdfName.GOTO.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S))))
                            {
                                dest = PdfReader.GetPdfObjectRelease(action.Get(PdfName.D));
                                if (dest != null)
                                {
                                    MapGotoBookmark(map, dest, pages);
                                }
                            }
                            else if (PdfName.URI.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S))))
                            {
                                map["Action"] = "URI";
                                map["URI"]    = ((PdfString)PdfReader.GetPdfObjectRelease(action.Get(PdfName.URI))).ToUnicodeString();
                            }
                            else if (PdfName.GOTOR.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S))))
                            {
                                dest = PdfReader.GetPdfObjectRelease(action.Get(PdfName.D));
                                if (dest != null)
                                {
                                    if (dest.IsString())
                                    {
                                        map["Named"] = dest.ToString();
                                    }
                                    else if (dest.IsName())
                                    {
                                        map["NamedN"] = PdfName.DecodeName(dest.ToString());
                                    }
                                    else if (dest.IsArray())
                                    {
                                        PdfArray      arr = (PdfArray)dest;
                                        StringBuilder s   = new StringBuilder();
                                        s.Append(arr[0].ToString());
                                        s.Append(' ').Append(arr[1].ToString());
                                        for (int k = 2; k < arr.Size; ++k)
                                        {
                                            s.Append(' ').Append(arr[k].ToString());
                                        }
                                        map["Page"] = s.ToString();
                                    }
                                }
                                map["Action"] = "GoToR";
                                PdfObject file = PdfReader.GetPdfObjectRelease(action.Get(PdfName.F));
                                if (file != null)
                                {
                                    if (file.IsString())
                                    {
                                        map["File"] = ((PdfString)file).ToUnicodeString();
                                    }
                                    else if (file.IsDictionary())
                                    {
                                        file = PdfReader.GetPdfObject(((PdfDictionary)file).Get(PdfName.F));
                                        if (file.IsString())
                                        {
                                            map["File"] = ((PdfString)file).ToUnicodeString();
                                        }
                                    }
                                }
                                PdfObject newWindow = PdfReader.GetPdfObjectRelease(action.Get(PdfName.NEWWINDOW));
                                if (newWindow != null)
                                {
                                    map["NewWindow"] = newWindow.ToString();
                                }
                            }
                            else if (PdfName.LAUNCH.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S))))
                            {
                                map["Action"] = "Launch";
                                PdfObject file = PdfReader.GetPdfObjectRelease(action.Get(PdfName.F));
                                if (file == null)
                                {
                                    file = PdfReader.GetPdfObjectRelease(action.Get(PdfName.WIN));
                                }
                                if (file != null)
                                {
                                    if (file.IsString())
                                    {
                                        map["File"] = ((PdfString)file).ToUnicodeString();
                                    }
                                    else if (file.IsDictionary())
                                    {
                                        file = PdfReader.GetPdfObjectRelease(((PdfDictionary)file).Get(PdfName.F));
                                        if (file.IsString())
                                        {
                                            map["File"] = ((PdfString)file).ToUnicodeString();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch  {
                    //empty on purpose
                }
                PdfDictionary first = (PdfDictionary)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.FIRST));
                if (first != null)
                {
                    map["Kids"] = BookmarkDepth(reader, first, pages);
                }
                list.Add(map);
                outline = (PdfDictionary)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.NEXT));
            }
            return(list);
        }
コード例 #31
0
ファイル: XmpWriter.cs プロジェクト: pixelia-es/RazorPDF2
 /**
 * @param os
 * @param info
 * @throws IOException
 */
 public XmpWriter(Stream os, PdfDictionary info, int PdfXConformance)
     : this(os)
 {
     if (info != null) {
         DublinCoreSchema dc = new DublinCoreSchema();
         PdfSchema p = new PdfSchema();
         XmpBasicSchema basic = new XmpBasicSchema();
         PdfObject obj;
         foreach (PdfName key in info.Keys) {
             obj = info.Get(key);
             if (obj == null)
                 continue;
             if (PdfName.TITLE.Equals(key)) {
                 dc.AddTitle(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.AUTHOR.Equals(key)) {
                 dc.AddAuthor(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.SUBJECT.Equals(key)) {
                 dc.AddSubject(((PdfString)obj).ToUnicodeString());
                 dc.AddDescription(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.KEYWORDS.Equals(key)) {
                 p.AddKeywords(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.CREATOR.Equals(key)) {
                 basic.AddCreatorTool(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.PRODUCER.Equals(key)) {
                 p.AddProducer(((PdfString)obj).ToUnicodeString());
             }
             if (PdfName.CREATIONDATE.Equals(key)) {
                 basic.AddCreateDate(((PdfDate)obj).GetW3CDate());
             }
             if (PdfName.MODDATE.Equals(key)) {
                 basic.AddModDate(((PdfDate)obj).GetW3CDate());
             }
         }
         if (dc.Count > 0) AddRdfDescription(dc);
         if (p.Count > 0) AddRdfDescription(p);
         if (basic.Count > 0) AddRdfDescription(basic);
         if (PdfXConformance == PdfWriter.PDFA1A || PdfXConformance == PdfWriter.PDFA1B) {
             PdfA1Schema a1 = new PdfA1Schema();
             if (PdfXConformance == PdfWriter.PDFA1A)
                 a1.AddConformance("A");
             else
                 a1.AddConformance("B");
             AddRdfDescription(a1);
         }
     }
 }
コード例 #32
0
 private static ArrayList BookmarkDepth(PdfReader reader, PdfDictionary outline, IntHashtable pages)
 {
     ArrayList list = new ArrayList();
     while (outline != null) {
         Hashtable map = new Hashtable();
         PdfString title = (PdfString)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.TITLE));
         map["Title"] = title.ToUnicodeString();
         PdfArray color = (PdfArray)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.C));
         if (color != null && color.Size == 3) {
             ByteBuffer outp = new ByteBuffer();
             outp.Append(color.GetAsNumber(0).FloatValue).Append(' ');
             outp.Append(color.GetAsNumber(1).FloatValue).Append(' ');
             outp.Append(color.GetAsNumber(2).FloatValue);
             map["Color"] = PdfEncodings.ConvertToString(outp.ToByteArray(), null);
         }
         PdfNumber style = (PdfNumber)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.F));
         if (style != null) {
             int f = style.IntValue;
             String s = "";
             if ((f & 1) != 0)
                 s += "italic ";
             if ((f & 2) != 0)
                 s += "bold ";
             s = s.Trim();
             if (s.Length != 0)
                 map["Style"] = s;
         }
         PdfNumber count = (PdfNumber)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.COUNT));
         if (count != null && count.IntValue < 0)
             map["Open"] = "false";
         try {
             PdfObject dest = PdfReader.GetPdfObjectRelease(outline.Get(PdfName.DEST));
             if (dest != null) {
                 MapGotoBookmark(map, dest, pages); //changed by ujihara 2004-06-13
             }
             else {
                 PdfDictionary action = (PdfDictionary)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.A));
                 if (action != null) {
                     if (PdfName.GOTO.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S)))) {
                         dest = PdfReader.GetPdfObjectRelease(action.Get(PdfName.D));
                         if (dest != null) {
                             MapGotoBookmark(map, dest, pages);
                         }
                     }
                     else if (PdfName.URI.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S)))) {
                         map["Action"] = "URI";
                         map["URI"] = ((PdfString)PdfReader.GetPdfObjectRelease(action.Get(PdfName.URI))).ToUnicodeString();
                     }
                     else if (PdfName.GOTOR.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S)))) {
                         dest = PdfReader.GetPdfObjectRelease(action.Get(PdfName.D));
                         if (dest != null) {
                             if (dest.IsString())
                                 map["Named"] = dest.ToString();
                             else if (dest.IsName())
                                 map["NamedN"] = PdfName.DecodeName(dest.ToString());
                             else if (dest.IsArray()) {
                                 PdfArray arr = (PdfArray)dest;
                                 StringBuilder s = new StringBuilder();
                                 s.Append(arr[0].ToString());
                                 s.Append(' ').Append(arr[1].ToString());
                                 for (int k = 2; k < arr.Size; ++k)
                                     s.Append(' ').Append(arr[k].ToString());
                                 map["Page"] = s.ToString();
                             }
                         }
                         map["Action"] = "GoToR";
                         PdfObject file = PdfReader.GetPdfObjectRelease(action.Get(PdfName.F));
                         if (file != null) {
                             if (file.IsString())
                                 map["File"] = ((PdfString)file).ToUnicodeString();
                             else if (file.IsDictionary()) {
                                 file = PdfReader.GetPdfObject(((PdfDictionary)file).Get(PdfName.F));
                                 if (file.IsString())
                                     map["File"] = ((PdfString)file).ToUnicodeString();
                             }
                         }
                         PdfObject newWindow = PdfReader.GetPdfObjectRelease(action.Get(PdfName.NEWWINDOW));
                         if (newWindow != null)
                             map["NewWindow"] = newWindow.ToString();
                     }
                     else if (PdfName.LAUNCH.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S)))) {
                         map["Action"] = "Launch";
                         PdfObject file = PdfReader.GetPdfObjectRelease(action.Get(PdfName.F));
                         if (file == null)
                             file = PdfReader.GetPdfObjectRelease(action.Get(PdfName.WIN));
                         if (file != null) {
                             if (file.IsString())
                                 map["File"] = ((PdfString)file).ToUnicodeString();
                             else if (file.IsDictionary()) {
                                 file = PdfReader.GetPdfObjectRelease(((PdfDictionary)file).Get(PdfName.F));
                                 if (file.IsString())
                                     map["File"] = ((PdfString)file).ToUnicodeString();
                             }
                         }
                     }
                 }
             }
         }
         catch  {
             //empty on purpose
         }
         PdfDictionary first = (PdfDictionary)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.FIRST));
         if (first != null) {
             map["Kids"] = BookmarkDepth(reader, first, pages);
         }
         list.Add(map);
         outline = (PdfDictionary)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.NEXT));
     }
     return list;
 }