Работа с документом в PostScript | .NET

Создать документ PS

Aspose.Page для .NET предлагает два конструктора для создания класса PsDocument. Следующий фрагмент кода создает одностраничный документ PS:

 1//Create output stream for PostScript document
 2using (Stream outPsStream = new FileStream(dir + "document.ps", FileMode.Create))
 3{
 4    //Create save options
 5    PsSaveOptions options = new PsSaveOptions();
 6    //If you want to assign page size other than A4, set page size in options
 7    options.PageSize = PageConstants.GetSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT);
 8    //If you want to assign page margins other than empty, set page margins in options
 9    options.Margins = PageConstants.GetMargins(PageConstants.MARGINS_ZERO);
10    //If you plan to use fonts that are located in non system folders, set additional fonts folders in options
11    options.AdditionalFontsFolders = new string[] { dir };
12
13    //Set variable that indicates if resulting PostScript document will be multipaged
14    bool multiPaged = false;
15
16    // Create new multipaged PS Document with one page opened
17    PsDocument document = new PsDocument(outPsStream, options, multiPaged);
18
19    //Close current page
20    document.ClosePage();
21    //Save the document
22    document.Save();
23}

Если документ PS планируется сделать многостраничным, установите для переменной multiPaged значение true.

Другой конструктор позволяет создать объект PsDocument с определенным количеством страниц:

 1//Create output stream for PostScript document
 2using (Stream outPsStream = new FileStream(dir + "document.ps", FileMode.Create))
 3{
 4    //Create save options
 5    PsSaveOptions options = new PsSaveOptions();
 6    
 7    // Create new multipaged PS Document with 2 pages. These two pages are not created. It must be added by AddPage() method.
 8    PsDocument document = new PsDocument(outPsStream, options, 2);
 9    
10    //Adding pages and it's content
11    
12    //Save the document
13    document.Save();
14}

См. работу с документом PS в Java.

Давайте посмотрим на класс PsSaveOptions, который инкапсулирует возможные параметры, помогающие создать правильный документ PostScript.

1options.PageSize = PageConstants.GetSize(PageConstants.SIZE_International, PageConstants.ORIENTATION_PORTRAIT);

Размер страницы по умолчанию — «А4» в «Портретной» ориентации.

1options.Margins = PageConstants.GetMargins(PageConstants.MARGINS_SMALL); // 20 points for each margin

Поля по умолчанию — «НОЛЬ» (0, 0, 0, 0).

1options.BackgroundColor = Color.FromArgb(211, 8, 48);

или:

1options.BackgroundColor = Color.Yellow;

Для Linux, MacOS и других операционных систем, отличных от Windows, мы предлагаем использовать наш пакет Nuget Aspose.Page.Drawing. Он использует серверную часть Aspose.Drawing вместо системной библиотеки System.Drawing.

Поэтому импортируйте пространство имен Aspose.Page.Drawing вместо System.Drawing. В приведенных выше фрагментах кода вместо System.Drawing.Color будет использоваться Aspose.Page.Drawing.Color. Наши примеры кода на GitHub содержат все необходимые замены.

Значение по умолчанию — «ноль», что означает отсутствие фона.

1options.EmbedFontsAs = FontsConstants.EMBED_FONTS_TYPE3

Значение по умолчанию — «TrueType».

Вы можете загрузить примеры и файлы данных с сайта GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.