
Overview
Adding text to a PostScript (PS) file is essential for various industries, from publishing to graphic design. It allows for dynamic content updates without altering the entire document. Using Aspose.Page for .NET, developers can seamlessly integrate this functionality into their applications. This powerful PostScript API enables users to edit PostScript files programmatically. Its flexibility and advanced features make it a preferred choice for C# developers looking to enhance their document processing capabilities. So, let’s learn how to add text in PS file using C#.
PostScript API Installation
You can download Aspose.Page for .NET from the official releases page or use the following command in your package manager console:
Install-Package Aspose.Page
How to Add Text in PS File in C# - Code Snippet
Follow these steps to add text to PS file using Aspose.Page for .NET:
- Create output stream for PostScript document.
- Instantiate an instance of the PsSaveOptions class.
- Set custom fonts folder. It will be added to system fonts folders for finding needed font.
- Set the text to write to the PS file and define the font size.
- Create a new PS Document by initializing an object of the PsDocument class.
- Using sysem font (located in system fonts folders) for filling text.
- Call the FillText method to fill text with default or already defined color. In given case it is black.
- Save the document by calling the Save method.
The following C# code snippet demonstrates how to insert text in PostScript file programmatically:
using Aspose.Page.EPS.Device; | |
using Aspose.Page.EPS; | |
using System.Drawing; | |
// Define the working directory path. | |
string dataDir = "files"; | |
// Create output stream for PostScript document. | |
using (Stream outPsStream = new FileStream(dataDir + "AddText_outPS.ps", FileMode.Create)) | |
{ | |
// Instantiate an instance of the PsSaveOptions class. | |
PsSaveOptions options = new PsSaveOptions(); | |
// Set custom fonts folder. It will be added to system fonts folders for finding needed font. | |
options.AdditionalFontsFolders = new string[] { @"{FONT_FOLDER}" }; | |
// Set the text to write to the PS file and define the font size. | |
string str = "This is a text."; | |
int fontSize = 48; | |
// Create a new PS Document by initializing an object of the PsDocument class. | |
PsDocument document = new PsDocument(outPsStream, options, false); | |
// Using sysem font (located in system fonts folders) for filling text. | |
Font font = new Font("Times New Roman", fontSize, FontStyle.Bold); | |
// Call the FillText method to fill text with default or already defined color. In given case it is black. | |
document.FillText(str, font, 50, 100); | |
// Fill text with Blue color. | |
document.FillText(str, font, 50, 150, new SolidBrush(Color.Blue)); | |
// Close current page | |
document.ClosePage(); | |
// Save the document by calling the Save method. | |
document.Save(); | |
} |

Insert Text in PS File using Unicode String
string dataDir = "files"; | |
string FONTS_FOLDER = @"necessary_fonts/"; | |
//Create output stream for PostScript document | |
using (Stream outPsStream = new FileStream(dataDir + "AddTextUsingUnocodeString_outPS.ps", FileMode.Create)) | |
{ | |
//Create save options with A4 size | |
PsSaveOptions options = new PsSaveOptions(); | |
// Set custom fonts folder. It will be added to system fonts folders for finding needed font. | |
options.AdditionalFontsFolders = new string[] { FONTS_FOLDER }; | |
//A text to write to PS file | |
string str = "試してみます。"; | |
int fontSize = 48; | |
// Create new 1-paged PS Document | |
PsDocument document = new PsDocument(outPsStream, options, false); | |
// Using custom font (located in custom fonts folders) for filling text. | |
DrFont drFont = ExternalFontCache.FetchDrFont("Arial Unicode MS", fontSize, FontStyle.Regular); | |
//Fill text with default or already defined color. In given case it is black. | |
document.FillText(str, drFont, 50, 200); | |
//Fill text with Blue color. | |
document.FillText(str, drFont, 50, 250, new SolidBrush(Color.Blue)); | |
//Close current page | |
document.ClosePage(); | |
//Save the document | |
document.Save(); | |
} |
Get a Free License
To explore the full potential of Aspose.Page for .NET, obtain a free trial license from here.
Conclusion
We have gone through how to add text in PS file using Aspose.Page for .NET. This PostScript API offers a seamless way to edit PostScript files, making it an invaluable option for developers. Explore Aspose.Page for .NET today to enhance your document processing capabilities.
Public Resources
Explore additional resources such as documentation and community forums to deepen your understanding of Aspose.Page for .NET. These resources provide valuable insights and support beyond the blog content.
Frequently Asked Questions – FAQs
How can I add text to a PS file using Aspose.Page for .NET?
To add text, load the PS file with PsDocument
, create a PsText
object, add it to the document, and save the changes. Use the provided code snippet as a guide.
Is Aspose.Page for .NET suitable for editing PostScript files?
Yes, Aspose.Page for .NET is ideal for editing PostScript files. It offers a robust PostScript API, ease of integration, and advanced customization options.
Can I try Aspose.Page for .NET before purchasing?
Yes, you can obtain a free trial license from Aspose’s temporary license page. It allows you to explore the library’s features without limitations.