Example #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"]);
            }

            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"]);
        }
Example #2
0
 public DocumentPage(DocumentPageTree parent)
 {
     this.parent   = parent;
     this.contents = new DocumentText();
 }