Esempio n. 1
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdf)
        {
            //	/CIDInit		/ProcSet findresource begin 12
            //
            //  /CIDSystemInfo
            //		/Registry   A string identifying the issuer of the character collection.
            //					For information about assigning a registry identifier, contact the Adobe
            //					Solutions Network or consult the ASN Web site (see the Bibliography).
            //		/Ordering	A string that uniquely names the character collection within the specified registry.
            //		/Supplement	The supplement number of the character collection. An original character collection
            //					has a supplement number of  0. Whenever additional CIDs are assigned in a character
            //					collection, the supplement number shall be increased. Supplements shall not alter
            //					the ordering of existing CIDs in the character collection. This value shall not be
            //					used in determining compatibility between character collections.
            StringBuilder sb = new StringBuilder();

            sb.Append(@"/CIDInit/ProcSet findresource begin 12 dict begin begincmap/CIDSystemInfo <</Registry (QWERT)/Ordering (ASDFG)/Supplement 0>> def /CMapName /QWERT def/CMapType 2 def 1 begincodespacerange
<00> <FF>
endcodespacerange" + "\n");

            sb.Append(font.hashChar.Count + " beginbfchar\n");
            foreach (int i in font.hashChar)
            {
                sb.Append("<" + font.GetGlyphId(i).ToString("X2") + "> <" + i.ToString("X4") + ">\n");
            }

            sb.Append("endbfchar\nendcmap\nCMapName currentdict /CMap defineresource pop\nend end\n");

            indirectObject.SetChild(new DictionaryObject(sb.ToString()));
        }
Esempio n. 2
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("FontDescriptor") },
                { "StemV", new IntegerObject(font.StemV) },
                { "Flags", new IntegerObject((int)font.Flags) },
                { "FontName", new NameObject(font.Name) },
                { "FontBBox", new ArrayObject(new List <PdfObject> {
                        new IntegerObject(font.boundingBox[0]),
                        new IntegerObject(font.boundingBox[1]),
                        new IntegerObject(font.boundingBox[2]),
                        new IntegerObject(font.boundingBox[3])
                    }) },
                { "ItalicAngle", new IntegerObject(font.ItalicAngle) },
                { "Ascent", new IntegerObject(font.Ascendent) },
                { "Descent", new IntegerObject(font.Descendent) },
                { "CapHeight", new IntegerObject(font.CapHeight) },
            };

            if (font.Leading > 0)
            {
                entries.Add("Leading", new IntegerObject(font.Leading));
            }

            if (font.IsEmbedded)
            {
                var fontContent = new DocumentFontContent(font.FontByteArray);
                entries.Add("FontFile2", fontContent.IndirectReferenceObject(pdfObjects));
            }

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Esempio n. 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"]);
            }

            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);
            }
        }
Esempio n. 4
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var widths = new List <PdfObject>();

            for (int i = FirstChar; i < LastChar + 1; i++)
            {
                if (!hashChar.Contains(i))
                {
                    widths.Add(new IntegerObject(0));
                }
                else if (!dctCharCodeToGlyphID.ContainsKey(i))
                {
                    widths.Add(new IntegerObject(this.Width));
                }
                else
                {
                    widths.Add(new IntegerObject(Glypth[dctCharCodeToGlyphID[i]].width));
                }
            }

            var entries = new Dictionary <string, PdfObject> {
                { "Encoding", new NameObject("WinAnsiEncoding") },
                { "Type", new NameObject("Font") },
                { "Subtype", new NameObject("TrueType") },
                { "BaseFont", new NameObject(Name) },
                { "FirstChar", new IntegerObject(FirstChar) },
                { "LastChar", new IntegerObject(LastChar) },
                { "Widths", new ArrayObject(widths) },
                { "FontDescriptor", descriptor.IndirectReferenceObject(pdfObjects) },
            };

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Esempio n. 5
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdf)
        {
            var entries = new Dictionary <string, PdfObject> {
                { "Length", new IntegerObject(font.Length) },
                { "Length1", new IntegerObject(font.Length) }
            };

            indirectObject.SetChild(new DictionaryObject(entries, font));
        }
Esempio n. 6
0
        public override void Load(PDFObjects pdf, PdfObject pdfObject)
        {
            var dic = pdf.GetObject <DictionaryObject>(pdfObject);

            if (dic.Stream != null)
            {
                this.pageOperators = new PageOperator(dic.Stream).ReadObjects();
            }
        }
Esempio n. 7
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var resourceEntries = new Dictionary <string, PdfObject>();

            if (fonts.Count > 0)
            {
                var dicFonts = new Dictionary <string, PdfObject>();

                foreach (var font in fonts)
                {
                    dicFonts.Add(font.Value, font.Key.IndirectReferenceObject(pdfObjects));
                }

                resourceEntries.Add("Font", new DictionaryObject(dicFonts));
            }

            if (images.Count > 0)
            {
                var dicImages = new Dictionary <string, PdfObject>();

                foreach (var img in images)
                {
                    dicImages.Add(img.Value, img.Key.IndirectReferenceObject(pdfObjects));
                }

                resourceEntries.Add("XObject", new DictionaryObject(dicImages));
            }

            if (procsets.Count > 0)
            {
                List <PdfObject> lstObjects = new List <PdfObject>();
                foreach (var procSet in procsets)
                {
                    lstObjects.Add(new NameObject(procSet));
                }
                resourceEntries.Add("ProcSet", new ArrayObject(lstObjects));
            }

            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Page") },
                { "Parent", parent.IndirectReferenceObject(pdfObjects) },
                { "Contents", contents.IndirectReferenceObject(pdfObjects) }
            };

            if (resourceEntries.Count > 0)
            {
                entries.Add("Resources", new DictionaryObject(resourceEntries));
            }

            if (MediaBox != null)
            {
                entries.Add("MediaBox", new ArrayObject(MediaBox.ToArrayObject()));
            }

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Esempio n. 8
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdf)
        {
            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Font") },
                { "Subtype", new NameObject("Type1") },
                { "BaseFont", new NameObject(this.Name) },
                { "Encoding", new NameObject("WinAnsiEncoding") }
            };

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Esempio n. 9
0
        public IndirectReferenceObject IndirectReferenceObject(PDFObjects pdfObjects) 
        {        
            var indirectObject = pdfObjects.CacheGuid(guid);
            if (indirectObject != null) {
                return indirectObject;
            }

            indirectObject = pdfObjects.CreateIndirectObject(guid);        
            OnSaveEvent(indirectObject, pdfObjects);                
            return indirectObject;         
        }    
Esempio n. 10
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"]);
            }
        }
Esempio n. 11
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("XObject") },
                { "Subtype", new NameObject("Image") },
                { "Length", new IntegerObject(image.Length) },
                { "Width", new IntegerObject(this.Width) },
                { "Height", new IntegerObject(this.Height) },
                { "BitsPerComponent", new IntegerObject(this.BitsPerComponent) },
                { "ColorSpace", (this.Components == 3 ? new NameObject("DeviceRGB") : new NameObject("DeviceGray")) }
            };

            indirectObject.SetChild(new DictionaryObject(entries, image));
        }
Esempio n. 12
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var dic = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Catalog") },
                { "Pages", pageTree.IndirectReferenceObject(pdfObjects) }
            };

            if (Outlines != null)
            {
                dic.Add("Outlines", outlines.IndirectReferenceObject(pdfObjects));
            }

            indirectObject.SetChild(new DictionaryObject(dic));
        }
Esempio n. 13
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            var entries = new Dictionary <string, PdfObject>()
            {
                { "Count", new IntegerObject(Count) }
            };

            if (Parent == null)
            {
                entries.Add("Type", new NameObject("Outlines"));
            }
            if (Parent != null)
            {
                entries.Add("Parent", Parent.IndirectReferenceObject(pdfObjects));
                entries.Add("Dest", new ArrayObject(new List <PdfObject>()
                {
                    Page.IndirectReferenceObject(pdfObjects),
                    new NameObject("XYZ"),
                    GetRealOrNullObject(X),
                    GetRealOrNullObject(Y),
                    GetRealOrNullObject(Zoom)
                }));
            }
            if (First != null)
            {
                entries.Add("First", First.IndirectReferenceObject(pdfObjects));
            }
            if (Last != null)
            {
                entries.Add("Last", Last.IndirectReferenceObject(pdfObjects));
            }
            if (Prev != null)
            {
                entries.Add("Prev", Prev.IndirectReferenceObject(pdfObjects));
            }
            if (Next != null)
            {
                entries.Add("Next", Next.IndirectReferenceObject(pdfObjects));
            }
            if (Title != null)
            {
                entries.Add("Title", new StringObject(Title));
            }

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Esempio n. 14
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            List <PdfObject> kids = new List <PdfObject>();

            kids.AddRange(pageTreeSons.Select(p => p.IndirectReferenceObject(pdfObjects)));
            kids.AddRange(pageSons.Select(p => p.IndirectReferenceObject(pdfObjects)));

            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Pages") },
                { "Kids", new ArrayObject(kids) },
                { "Count", new IntegerObject(kids.Count) },
            };

            if (MediaBox != null)
            {
                entries.Add("MediaBox", new ArrayObject(MediaBox.ToArrayObject()));
            }

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Esempio n. 15
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            // a good guide: http://www.4real.gr/technical-documents-ttf-subset.html
            SubsetTTFFont = Subset(TTFFont);

            File.WriteAllBytes("file.ttf", SubsetTTFFont);

            var widths = new List <PdfObject>();

            widths.Add(new IntegerObject(this.Width));
            foreach (int i in hashChar)
            {
                if (!dctCharCodeToGlyphID.ContainsKey(i))
                {
                    widths.Add(new IntegerObject(this.Width));
                }
                else
                {
                    widths.Add(new IntegerObject(Glypth[dctCharCodeToGlyphID[i]].width));
                }
            }

            var descriptor = new DocumentTtfDescriptorFont(this);
            var cmap       = new DocumentCmapFont(this);

            var entries = new Dictionary <string, PdfObject> {
                { "Type", new NameObject("Font") },
                { "Subtype", new NameObject("TrueType") },
                { "BaseFont", new NameObject(Name) },
                { "FirstChar", new IntegerObject(0) },
                { "LastChar", new IntegerObject(hashChar.Count) },
                { "Widths", new ArrayObject(widths) },
                { "FontDescriptor", descriptor.IndirectReferenceObject(pdfObjects) },
                { "ToUnicode", cmap.IndirectReferenceObject(pdfObjects) },
            };

            indirectObject.SetChild(new DictionaryObject(entries));
        }
Esempio n. 16
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}");
                }
            }
        }
Esempio n. 17
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"]);
        }
Esempio n. 18
0
        public DocumentFontContent(PDFObjects pdf, PdfObject pdfObject)
        {
            var dic = pdf.GetObject <DictionaryObject>(pdfObject);

            font = dic.Stream;
        }
Esempio n. 19
0
 public virtual void Load(PDFObjects pdf, PdfObject pdfObject) { }
Esempio n. 20
0
 public virtual void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects) { }
Esempio n. 21
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            string text = string.Join(" ", pageOperators);

            indirectObject.SetChild(new DictionaryObject(text));
        }