src/providers/Azos.Media/PDF/PdfWriter.cs
/// <summary>
/// Writes PDF page into file stream
/// </summary>
/// <param name="page">PDF page</param>
Writes PDF page into file stream
Writes PDF page into file stream
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();
    }
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 ( " " , fonts ) ; if ( images . Length > 0 ) resourcesBuilder . AppendFormat ( " " , images ) ; var w = TextAdapter . FormatFloat ( page . Width ) ; var h = TextAdapter . FormatFloat ( page . Height ) ; writeBeginObject ( page . ObjectId ) ; writeBeginDictionary ( ) ; writeDictionaryEntry ( " " , " " ) ; writeDictionaryEntry ( " " , TextAdapter . FormatFloat ( page . UserUnit ) ) ; writeDictionaryEntry ( " " , page . Parent . GetReference ( ) ) ; writeDictionaryEntry ( " " , DICTIONARY_PDF_FORMAT . Args ( resourcesBuilder ) ) ; writeDictionaryEntry ( " " , BOX_PDF_FORMAT . Args ( w , h ) ) ; writeDictionaryEntry ( " " , BOX_PDF_FORMAT . Args ( w , h ) ) ; writeDictionaryEntry ( " " , 0 ) ; writeDictionaryEntry ( " " , PROC_SET_STRING ) ; if ( elements . Length > 0 ) { writeDictionaryEntry ( " " , ARRAY_PDF_FORMAT . Args ( elements ) ) ; } writeEndDictionary ( ) ; writeEndObject ( ) ; }
Writes PDF page into file stream
Writes PDF page into file stream
page
PdfPage
None