Lavorare con i documenti in PostScript | .NET

Contents
[ Hide Show ]

Crea documento PS

Aspose.Page per .NET offre due costruttori per creare la classe PsDocument. Il seguente frammento di codice crea un documento PS di una pagina:

 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}

Se si prevede che il documento PS sia multipagina, impostare la variabile multiPaged su true.

Un altro costruttore consente di creare un oggetto PsDocument con un numero definito di pagine:

 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}

Vedi Lavorare con i documenti PS in Java.

Diamo un’occhiata alla classe PsSaveOptions che incapsula le possibili opzioni che aiutano a creare il documento PostScript corretto.

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

Il formato di pagina predefinito è “A4” con orientamento “Verticale”.

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

I margini predefiniti sono “ZERO” (0, 0, 0, 0).

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

O:

1options.BackgroundColor = Color.Yellow;

Per Linux, macOS e altri sistemi operativi non Windows, offriamo l’utilizzo del nostro pacchetto Nuget Aspose.Page.Drawing. Utilizza il backend Aspose.Drawing invece della libreria di sistema System.Drawing.

Quindi, importate lo spazio dei nomi Aspose.Page.Drawing invece di quello System.Drawing. Nei frammenti di codice sopra, verrà utilizzato Aspose.Page.Drawing.Color invece di System.Drawing.Color. I nostri esempi di codice su GitHub contengono tutte le sostituzioni necessarie.

Il valore predefinito è “null”, che significa nessuno sfondo.

1options.EmbedFontsAs = FontsConstants.EMBED_FONTS_TYPE3

Il valore predefinito è “TrueType”.

È possibile scaricare esempi e file di dati da GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.