コード例 #1
0
ファイル: DocumentCmapFont.cs プロジェクト: havocbcn/crcPdf
        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()));
        }
コード例 #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));
        }
コード例 #3
0
ファイル: DocumentTtfFont.cs プロジェクト: havocbcn/crcPdf
        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));
        }
コード例 #4
0
ファイル: PDFObjects.cs プロジェクト: havocbcn/crcPdf
 internal void AddObject(IndirectObject id)
 {
     objects.Add(id);
     if (id.Number > lastNumber)
     {
         lastNumber = id.Number + 1;
     }
 }
コード例 #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));
        }
コード例 #6
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));
        }
コード例 #7
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));
        }
コード例 #8
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));
        }
コード例 #9
0
ファイル: PDFObjects.cs プロジェクト: havocbcn/crcPdf
        /// <summary>
        /// From an object reference, I want to know the type of this object
        /// For example: 1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj
        /// It will return "Catalog"
        /// If the obj referenced is not a dictionary, for example
        /// 1 0 obj [ 1 2 3 ] endobj
        /// type will be null
        /// </summary>
        public string GetType(IndirectObject obj)
        {
            var dic = obj.Child <DictionaryObject>(0);

            if (dic == null)
            {
                return(null);
            }
            if (dic.Dictionary.ContainsKey("Type"))
            {
                return(GetObject <NameObject>(dic.Dictionary["Type"]).Value);
            }
            return(null);
        }
コード例 #10
0
ファイル: PDFObjects.cs プロジェクト: havocbcn/crcPdf
        internal IndirectObject CreateIndirectObject(Guid guid)
        {
            if (guidToIndirect.ContainsKey(guid))
            {
                return(guidToIndirect[guid]);
            }

            var indirect = new IndirectObject(++lastNumber);

            objects.Add(indirect);
            guidToIndirect.Add(guid, indirect);

            return(indirect);
        }
コード例 #11
0
ファイル: DocumentImageRaw.cs プロジェクト: havocbcn/crcPdf
        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));
        }
コード例 #12
0
ファイル: PDFObjects.cs プロジェクト: havocbcn/crcPdf
        /// <summary>
        /// From an indirect object -1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj-,
        /// construct a Document -DocumentCatalog in the example-
        /// </summary>
        public T GetDocument <T>(IndirectObject obj) where T : DocumentTree
        {
            if (cache.ContainsKey(obj))
            {
                return(cache[obj] as T);
            }

            var a = (T)Activator.CreateInstance(typeof(T));

            cache.Add(obj, a);

            a.Load(this, obj.childs[0]);

            return(a);
        }
コード例 #13
0
ファイル: DocumentOutlines.cs プロジェクト: havocbcn/crcPdf
        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));
        }
コード例 #14
0
ファイル: DocumentPageTree.cs プロジェクト: havocbcn/crcPdf
        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));
        }
コード例 #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));
        }
コード例 #16
0
ファイル: PDFObjects.cs プロジェクト: havocbcn/crcPdf
 internal T GetObject <T>(IndirectObject obj) where T : PdfObject
 => obj.childs[0] as T;
コード例 #17
0
ファイル: DocumentTree.cs プロジェクト: havocbcn/crcPdf
 public virtual void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects) { }
コード例 #18
0
        public override void OnSaveEvent(IndirectObject indirectObject, PDFObjects pdfObjects)
        {
            string text = string.Join(" ", pageOperators);

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