예제 #1
0
        /// <summary>
        /// Creates new page and adds it to the page tree
        /// </summary>
        /// <returns></returns>
        public PdfPage CreatePage(PdfSize size)
        {
            var page = new PdfPage(this, size);
              m_Pages.Add(page);

              return page;
        }
예제 #2
0
파일: PdfWriter.cs 프로젝트: itadapter/nfx
        /// <summary>
        /// Writes PDF page into file stream
        /// </summary>
        /// <param name="page">PDF page</param>
        internal void Write(PdfPage page)
        {
            var resourcesBuilder = new StringBuilder();
              var elements = string.Join(Constants.SPACE.ToString(), page.Elements.Select(p => p.GetReference()));
              var images = string.Join(Constants.SPACE.ToString(), page.Elements.OfType<ImageElement>().Select(p => p.GetCoupledReference()));
              var fonts = string.Join(Constants.SPACE, page.Fonts.Select(p => FONTS_REFERENCE_FORMAT.Args(p.GetResourceReference(), p.GetReference())));

              if (fonts.Length > 0)
            resourcesBuilder.AppendFormat(" /Font <<{0}>> ", fonts);
              if (images.Length > 0)
            resourcesBuilder.AppendFormat(" /XObject <<{0}>> ", images);

              var w = TextAdapter.FormatFloat(page.Width);
              var h = TextAdapter.FormatFloat(page.Height);

              writeBeginObject(page.ObjectId);
              writeBeginDictionary();
              writeDictionaryEntry("/Type", "/Page");
              writeDictionaryEntry("/UserUnit", TextAdapter.FormatFloat(page.UserUnit));
              writeDictionaryEntry("/Parent", page.Parent.GetReference());
              writeDictionaryEntry("/Resources", DICTIONARY_PDF_FORMAT.Args(resourcesBuilder));
              writeDictionaryEntry("/MediaBox", BOX_PDF_FORMAT.Args(w, h));
              writeDictionaryEntry("/CropBox", BOX_PDF_FORMAT.Args(w, h));
              writeDictionaryEntry("/Rotate", 0);
              writeDictionaryEntry("/ProcSet", PROC_SET_STRING);
              if (elements.Length > 0)
              {
            writeDictionaryEntry("/Contents", ARRAY_PDF_FORMAT.Args(elements));
              }
              writeEndDictionary();
              writeEndObject();
        }