示例#1
0
        public override void Load(PDFObjects pdf, PdfObject pdfObject)
        {
            var dic = pdf.GetObject <DictionaryObject>(pdfObject);

            if (dic.Dictionary.ContainsKey("Parent"))
            {
                parent = pdf.GetDocument <DocumentPageTree>(dic.Dictionary["Parent"]);
            }

            var dicKids = pdf.GetObject <ArrayObject>(dic.Dictionary["Kids"]);

            foreach (var kid in dicKids.Childs <IndirectReferenceObject>())
            {
                if (pdf.GetType(kid) == "Pages")
                {
                    pageTreeSons.Add(pdf.GetDocument <DocumentPageTree>(kid));
                }
                else
                {
                    pageSons.Add(pdf.GetDocument <DocumentPage>(kid));
                }
            }

            if (dic.Dictionary.ContainsKey("MediaBox"))
            {
                var mediaBox = pdf.GetObject <ArrayObject>(dic.Dictionary["MediaBox"]);

                MediaBox = new Rectangle(
                    pdf.GetObject <RealObject>(mediaBox.childs[0]).Value,
                    pdf.GetObject <RealObject>(mediaBox.childs[1]).Value,
                    pdf.GetObject <RealObject>(mediaBox.childs[2]).Value,
                    pdf.GetObject <RealObject>(mediaBox.childs[3]).Value);
            }
        }
示例#2
0
        public override void Load(PDFObjects pdf, PdfObject pdfObject)
        {
            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
            var dictionary = pdf.GetObject <DictionaryObject>(pdfObject);

            pageTree = pdf.GetDocument <DocumentPageTree>(dictionary.Dictionary["Pages"]);

            if (dictionary.Dictionary.ContainsKey("Outlines"))
            {
                outlines = pdf.GetDocument <DocumentOutlines>(dictionary.Dictionary["Outlines"]);
            }
        }
示例#3
0
        public override void Load(PDFObjects pdf, PdfObject pdfObject)
        {
            var dic = pdf.GetObject <DictionaryObject>(pdfObject);

            if (dic.Dictionary.ContainsKey("Parent"))
            {
                parent = pdf.GetDocument <DocumentPageTree>(dic.Dictionary["Parent"]);
            }

            if (dic.Dictionary.ContainsKey("MediaBox"))
            {
                var mediaBox = pdf.GetObject <ArrayObject>(dic.Dictionary["MediaBox"]);

                MediaBox = new Rectangle(
                    pdf.GetObject <RealObject>(mediaBox.childs[0]).Value,
                    pdf.GetObject <RealObject>(mediaBox.childs[1]).Value,
                    pdf.GetObject <RealObject>(mediaBox.childs[2]).Value,
                    pdf.GetObject <RealObject>(mediaBox.childs[3]).Value);
            }

            if (dic.Dictionary.ContainsKey("Resources"))
            {
                var resources = pdf.GetObject <DictionaryObject>(dic.Dictionary["Resources"]);

                foreach (var resource in resources.Dictionary)
                {
                    switch (resource.Key)
                    {
                    case "Font":
                        foreach (var font in pdf.GetObject <DictionaryObject>(resource.Value).Dictionary)
                        {
                            var documentFont = FontFactory.GetFont(pdf, font.Value);
                            fonts.Add(documentFont, font.Key);
                            reverseFonts.Add(font.Key, documentFont);
                        }
                        break;

                    case "XObject":
                        foreach (var image in pdf.GetObject <DictionaryObject>(resource.Value).Dictionary)
                        {
                            var documentImage = ImageFactory.GetImage(pdf, image.Value);
                            images.Add(documentImage, image.Key);
                            reverseImages.Add(image.Key, documentImage);
                        }
                        break;

                    case "ProcSet":
                        //14.2 Procedure Sets
                        var arrayobject = pdf.GetObject <ArrayObject>(resource.Value);
                        foreach (var item in arrayobject.Childs <NameObject>())
                        {
                            procsets.Add(item.Value);
                        }
                        break;

                    default:
                        // TODO
                        throw new PdfException(PdfExceptionCodes.INVALID_RESOURCE, $"Not supported resource found {resource.Key}");
                    }
                }
            }

            contents = pdf.GetDocument <DocumentText>(dic.Dictionary["Contents"]);
        }
示例#4
0
        public override void Load(PDFObjects pdf, PdfObject pdfObject)
        {
            var contents = pdf.GetObject <DictionaryObject>(pdfObject);

            foreach (var value in contents.Dictionary)
            {
                switch (value.Key)
                {
                case "Type":
                    break;

                case "First":
                    First = pdf.GetDocument <DocumentOutlines>(value.Value);
                    break;

                case "Last":
                    Last = pdf.GetDocument <DocumentOutlines>(value.Value);
                    break;

                case "Prev":
                    Prev = pdf.GetDocument <DocumentOutlines>(value.Value);
                    break;

                case "Next":
                    Next = pdf.GetDocument <DocumentOutlines>(value.Value);
                    break;

                case "Parent":
                    Parent = pdf.GetDocument <DocumentOutlines>(value.Value);
                    break;

                case "Count":
                    Count = pdf.GetObject <IntegerObject>(value.Value).IntValue;
                    break;

                case "Title":
                    Title = pdf.GetObject <StringObject>(value.Value).Value;
                    break;

                case "Dest":
                    var dest = pdf.GetObject <ArrayObject>(value.Value);

                    Page = pdf.GetDocument <DocumentPage>(dest.childs[0]);

                    switch (pdf.GetObject <NameObject>(dest.childs[1]).Value)
                    {
                    case "XYZ":
                        X    = GetRealOrNullObject(dest.childs[2]);
                        Y    = GetRealOrNullObject(dest.childs[3]);
                        Zoom = GetRealOrNullObject(dest.childs[4]);
                        break;

                    default:
                        throw new PdfException(PdfExceptionCodes.UNKNOWN_ENTRY, $"Outlines contain an unknown Dest entry: {pdf.GetObject<NameObject>(dest.childs[1]).Value}");
                    }

                    break;

                default:
                    throw new PdfException(PdfExceptionCodes.UNKNOWN_ENTRY, $"Outlines contain an unknown entry: {value.Key}");
                }
            }
        }