Trabalhar com Documento em PostScript | .NET

Contents
[ Hide Show ]

Criar Documento PS

O Aspose.Page para .NET oferece dois construtores para criar a classe PsDocument. O seguinte excerto de código cria um documento PS de 1 página:

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

Se o documento PS tiver várias páginas, defina a variável multiPaged para true.

Outro construtor permite criar um objeto PsDocument com um número definido de páginas:

 1// Create new PS document with defined number of pages.
 2
 3string outputFileName = "document_out.ps";
 4
 5//Create save options
 6PsSaveOptions options = new PsSaveOptions();
 7//If you want to aassign page size other than A4, set page size in options
 8options.PageSize = PageConstants.GetSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT);
 9//If you want to aassign page margins other empty, set page margins in options
10options.Margins = PageConstants.GetMargins(PageConstants.MARGINS_ZERO);
11//If you plan to use fonts that located in non system folders, set additional fonts folders in options
12options.AdditionalFontsFolders = new string[] { DataDir };
13
14// Create new multipaged PS Document with 2 pages. These two pages are not created. It must be added by OpenPage() method.
15PsDocument document = new PsDocument(OutputDir + outputFileName, options, 2);
16
17//Add the first page
18document.OpenPage();
19//Close current page
20document.ClosePage();
21//Save the document
22document.Save();

Veja como trabalhar com documentos PS em Java.

Vejamos a classe PsSaveOptions que encapsula possíveis opções que ajudam a criar o documento PostScript correcto.

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

O tamanho de página predefinido é “A4” na orientação “Retrato”.

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

As margens padrão são “ZERO” (0, 0, 0, 0).

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

ou:

1options.BackgroundColor = Color.Yellow;

Para Linux, MacOS e outros sistemas operativos não Windows, oferecemos a utilização do nosso pacote NuGet Aspose.Page.Drawing. Utiliza o backend Aspose.Drawing em vez da biblioteca de sistema System.Drawing.

Assim, importe o namespace Aspose.Page.Drawing em vez do System.Drawing. Nos excertos de código acima, será utilizado Aspose.Page.Drawing.Color em vez de System.Drawing.Color. Os nossos exemplos de código no GitHub contêm todas as substituições necessárias.

O valor predefinido é “null”, o que significa sem fundo.

1options.EmbedFontsAs = FontsConstants.EMBED_FONTS_TYPE3

O valor predefinido é “TrueType”.

Pode descarregar exemplos e ficheiros de dados do GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.