Beispiel #1
0
        /// <summary>
        /// Adds an object to the document.
        /// </summary>
        /// <returns>The added object.</returns>
        private PortableDocumentObject AddObject()
        {
            var obj = new PortableDocumentObject(this.objects.Count + 1);

            this.objects.Add(obj);
            return(obj);
        }
Beispiel #2
0
        /// <summary>
        /// Adds a page specified by width and height.
        /// </summary>
        /// <param name="width">The page width in points.</param>
        /// <param name="height">The page height in points.</param>
        public void AddPage(double width = 595, double height = 842)
        {
            this.PageWidth           = width;
            this.PageHeight          = height;
            this.currentPageContents = this.AddObject();

            var page1 = this.AddObject(PdfWriter.ObjectType.Page);

            page1["/Parent"]    = this.pages;
            page1["/MediaBox"]  = new[] { 0d, 0d, width, height };
            page1["/Contents"]  = this.currentPageContents;
            page1["/Resources"] = this.resources;
            this.pageReferences.Add(page1);
        }
Beispiel #3
0
        /// <summary>
        /// Adds a font.
        /// </summary>
        /// <param name="font">The font.</param>
        /// <returns>The added object.</returns>
        private string AddFont(PortableDocumentFont font)
        {
            //// For the standard 14 fonts, the entries FirstChar, LastChar, Widths, and FontDescriptor must either all be
            //// present or all be absent. Ordinarily, they are absent; specifying them enables a standard font to be overridden

            PortableDocumentObject fd = null;

            if (font.SubType != FontSubType.Type1)
            {
                fd                 = this.AddObject(PdfWriter.ObjectType.FontDescriptor);
                fd["/Ascent"]      = font.Ascent;
                fd["/CapHeight"]   = font.CapHeight;
                fd["/Descent"]     = font.Descent;
                fd["/Flags"]       = font.Flags;
                fd["/FontBBox"]    = font.FontBoundingBox;
                fd["/ItalicAngle"] = font.ItalicAngle;
                fd["/StemV"]       = font.StemV;
                fd["/XHeight"]     = font.XHeight;
                fd["/FontName"]    = "/" + font.FontName;
            }

            var f = this.AddObject(PdfWriter.ObjectType.Font);

            f["/Subtype"]  = "/" + font.SubType;
            f["/Encoding"] = "/" + font.Encoding;
            f["/BaseFont"] = "/" + font.BaseFont;
            if (fd != null)
            {
                f["/FontDescriptor"] = fd;
            }

            if (font.SubType != FontSubType.Type1)
            {
                // Optional for Type 1 fonts
                f["/FirstChar"] = font.FirstChar;
                f["/LastChar"]  = font.FirstChar + font.Widths.Length - 1;
                f["/Widths"]    = font.Widths;
            }

            int    i      = this.fonts.Count + 1;
            string fontId = "/F" + i;

            this.fonts.Add(fontId, f);
            return(fontId);
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PortableDocument" /> class.
        /// </summary>
        public PortableDocument()
        {
            this.metadata = this.AddObject();
            this.metadata["/CreationDate"] = DateTime.Now;

            this.catalog           = this.AddObject(PdfWriter.ObjectType.Catalog);
            this.pages             = this.AddObject(PdfWriter.ObjectType.Pages);
            this.catalog["/Pages"] = this.pages;

            this.fonts     = new Dictionary <string, object>();
            this.xobjects  = new Dictionary <string, object>();
            this.extgstate = new Dictionary <string, object>();
            this.resources = this.AddObject();

            // See chapter 10.1 - ProcSet is obsolete from version 1.4?
            this.resources["/ProcSet"] = new[] { "/PDF", "/Text", "/ImageB", "/ImageC", "/ImageI" };

            this.resources["/Font"]      = this.fonts;
            this.resources["/XObject"]   = this.xobjects;
            this.resources["/ExtGState"] = this.extgstate;

            this.currentFont     = StandardFonts.Helvetica.GetFont(false, false);
            this.currentFontSize = 12;
        }