Add text to PS files
C++ API solution to work with texts of PS files
PostScript, a powerful page description language, offers granular control over text placement and formatting. Here are some key nuances to consider when working with text in PostScript:
- PostScript allows you to select fonts using their PostScript names. Common fonts like Times Roman, Helvetica, and Courier are often available by default. To ensure consistent rendering across different systems, you can embed fonts directly into your PostScript file. This is especially important for custom fonts or less common font families.
- Font Size and Style - The
fontsize
operator sets the font size in points. To modify font styles use operators likesetfont
which specifies bold, italic, or other variations. - Text Positioning - The
moveto
operator positions the text cursor to a specific point on the page. While PostScript does not have direct alignment operators, you can achieve alignment by carefully. - Text Rotation and Scaling - The
rotate
operator can be used to rotate text to a specific angle, and thescale
operator can be used to scale text up or down. - Text Rendering - PostScript supports anti-aliasing, which smooths the edges of text for better readability. You can also control the spacing between characters (kerning) and lines (leading) to fine-tune the appearance of text.
Understanding these aspects can help ensure proper font usage and consistent rendering in PostScript-based workflows. But no matter what, - Aspose.Page provides you with the functionality to manage the fonts of PS files easily. With this API you can add texts of different colors and brushes using custom or system fonts. To learn more about how to deal with PS files and how to work with texts of PS files in particular follow the documentation.
To insert texts to PS documents we need:
Aspose.Page for C++ API which is a feature-rich, powerful and easy-to-use document manipulation and conversion C++ API.
Open the NuGet package manager, and search for Aspose.Page.Cpp and install. You may also use the following command from the Package Manager Console.
Package Manager Console Command
PM> Install-Package Aspose.Page.Cpp
Steps to add text to a PS file.
The code snippet below demonstrates how to add text using a Unicode string to a PostScript (PS) document using the Aspose.Page library in C#. To see a fuller version of the example and more examples go to Aspose.Page-for-C++ GitHub project .
- Initialize the dataDir variable with the path to the directory containing the documents.
- Set the variable FONTS_FOLDER to set to the path of the folder containing the necessary fonts.
- Create an output stream for the PostScript document using the FileStream class.
- Specify the save options for the PostScript document using the PsSaveOptions object.
- The AdditionalFontsFolders property of the options object is set to an array containing the path to the FONTS_FOLDER. This allows the system to locate any required fonts in that folder.
- Specify the text and its size.
- Create a new instance of PsDocument with the output stream, options, and false as parameters. This initializes a new PostScript document with the specified options.
- Call the ClosePage() method on the document object, indicating that the current page is completed.
- Use the Save() method to save the changes made to the PS document.
Add images to PS
PS What is PS File Format
PS format is one of the page description language (PDL) formats. It is capable to contain graphic as well as text information on the page. That is why the format was supported by most of the programs for image editing. The postscript file itself is a kind of instruction for printers. It contains information on what and how to print from its page.