Travailler avec un document dans PS | .NET

Contents
[ Hide Show ]

Créer un document PS

Aspose.Page pour .NET propose deux constructeurs afin de créer la classe PsDocument. L’extrait de code suivant crée un document PS d’une page :

 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();

Si le document PS prévoit d’être multipage, définissez la variable multiPaged sur true.

Un autre constructeur permet de créer un objet PsDocument avec un nombre défini de pages :

 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();

Voir travailler avec un document PS dans Java.

Regardons la classe PsSaveOptions qui encapsule les options possibles aidant à créer le bon document PostScript.

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

Le format de page par défaut est « A4 » en orientation « Portrait ».

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

Les marges par défaut sont “ZÉRO” (0, 0, 0, 0).

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

ou:

1options.BackgroundColor = Color.Yellow;

Pour Linux, MacOS et autres systèmes d’exploitation non Windows, nous proposons d’utiliser notre package Nuget Aspose.Page.Drawing. Il utilise le backend Aspose.Drawing au lieu de la bibliothèque système System.Drawing.

Importez donc l’espace de noms Aspose.Page.Drawing au lieu de celui de System.Drawing. Dans les extraits de code ci-dessus, Aspose.Page.Drawing.Color sera utilisé à la place de System.Drawing.Color. Nos exemples de code sur GitHub contiennent toutes les substitutions nécessaires.

La valeur par défaut est “null”, ce qui signifie aucun arrière-plan.

1options.EmbedFontsAs = FontsConstants.EMBED_FONTS_TYPE3

La valeur par défaut est « TrueType ».

Vous pouvez télécharger des exemples et des fichiers de données à partir de GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.