Робота з документом у файлі PS | Java

Створіть документ PS

Aspose.Page для Java пропонує два конструктори для створення класу PsDocument. Наступний фрагмент коду створює односторінковий документ PS:

 1//Create output stream for PostScript document
 2FileOutputStream outPsStream = new FileOutputStream(dataDir + "document.ps");
 3//Create save options with A4 size
 4PsSaveOptions options = new PsSaveOptions();
 5
 6//If you want to aassign page size other than A4, set page size in options
 7options.setPageSize(PageConstants.getSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT));
 8//If you want to aassign page margins other than empty, set page margins in options
 9options.setMargins(PageConstants.getMargins(PageConstants.MARGINS_ZERO));
10//If you plan to use fonts that located in non system folders, set additional fonts folders in options
11options.setAdditionalFontsFolders(new String[] { FONTS_FOLDER });
12
13//Set variable that indicates if resulting PostScript document will be multipaged
14boolean multiPaged = false;
15
16// Create new multipaged PS Document with one page opened
17PsDocument document = new PsDocument(outPsStream, options, multiPaged);
18
19//Close current page
20document.closePage();
21//Save the document
22document.save();

Якщо документ PS планується зробити багатосторінковим, установіть для змінної multiPaged значення true.

Інший конструктор дозволяє створити об’єкт PsDocument із заданою кількістю сторінок:

 1//Create save options with A4 size
 2PsSaveOptions options = new PsSaveOptions();
 3//Create output stream for PostScript document
 4FileOutputStream outPsStream = new FileOutputStream(dataDir + "CreateDocument_outPS.ps");
 5
 6// Create new multipaged PS Document with 2 pages. These two pages are not created. It must be added by addPage() method.
 7PsDocument document = new PsDocument(outPsStream, options, 2);
 8
 9//Close current page
10document.closePage();
11//Save the document
12document.save();

Дивіться роботу з документом PS у .NET.

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

1options.setPageSize(PageConstants.getSize(PageConstants.SIZE_International, PageConstants.ORIENTATION_PORTRAIT));

Розмір сторінки за замовчуванням – «A4» у «Книжковій» орієнтації.

1options.setMargins(PageConstants.getMargins(PageConstants.MARGINS_SMALL)); // 20 points for each margin

Поля за замовчуванням — «НУЛЬ» (0, 0, 0, 0).

1options.setBackgroundColor(new Color(211, 8, 48));

або:

1options.setBackgroundColor(Color.YELLOW);

Значення за замовчуванням — «null», що означає відсутність фону.

1options.setEmbedFontsAs(FontsConstants.EMBED_FONTS_TYPE3);

Значення за замовчуванням - “TrueType”.

Ви можете завантажити приклади і файли даних з GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.