
ภาพรวม
การเพิ่มข้อความในไฟล์ PostScript (PS) เป็นสิ่งสำคัญสำหรับหลากหลายอุตสาหกรรม ตั้งแต่การเผยแพร่ไปจนถึงการออกแบบกราฟิก มันช่วยให้สามารถอัปเดตเนื้อหาต่างๆ ได้โดยไม่ต้องเปลี่ยนแปลงเอกสารทั้งฉบับ โดยใช้ Aspose.Page สำหรับ .NET นักพัฒนาสามารถรวมฟังก์ชันนี้เข้ากับแอปพลิเคชันของตนได้อย่างราบรื่น API PostScript ที่ทรงพลังนี้ช่วยให้ผู้ใช้สามารถแก้ไขไฟล์ PostScript โดยอัตโนมัติ ความยืดหยุ่นและฟีเจอร์ขั้นสูงทำให้มันเป็นทางเลือกที่ชื่นชอบสำหรับนักพัฒนา C# ที่ต้องการเพิ่มขีดความสามารถในการประมวลผลเอกสารของตน ดังนั้น มาศึกษาวิธีการเพิ่มข้อความในไฟล์ PS โดยใช้ C# กันเถอะ
การติดตั้ง PostScript API
คุณสามารถดาวน์โหลด Aspose.Page สำหรับ .NET ได้จาก หน้าเปิดตัวอย่างทางการ หรือใช้คำสั่งต่อไปนี้ในคอนโซลของผู้จัดการแพ็คเกจของคุณ:
Install-Package Aspose.Page
วิธีการเพิ่มข้อความในไฟล์ PS ใน C# - ตัวอย่างโค้ด
ทำตามขั้นตอนเหล่านี้เพื่อ เพิ่มข้อความลงในไฟล์ PS โดยใช้ Aspose.Page สำหรับ .NET:
- สร้างสตรีมเอาต์พุตสำหรับเอกสาร PostScript
- สร้างอินสแตนซ์ของคลาส PsSaveOptions.
- ตั้งค่าโฟลเดอร์ฟอนต์ที่กำหนดเอง จะถูกเพิ่มไปยังโฟลเดอร์ฟอนต์ของระบบเพื่อค้นหาฟอนต์ที่ต้องการ
- ตั้งค่าข้อความที่จะเขียนลงในไฟล์ PS และกำหนดขนาดฟอนต์
- สร้างเอกสาร PS ใหม่โดยการสร้างอ็อบเจ็กต์ของคลาส PsDocument
- ใช้ฟอนต์ของระบบ (ที่อยู่ในโฟลเดอร์ฟอนต์ของระบบ) เพื่อเติมข้อความ
- เรียกใช้เมธอด FillText เพื่อเติมข้อความด้วยสีเริ่มต้นหรือสีที่ได้กำหนดไว้แล้ว ในกรณีนี้คือสีดำ
- บันทึกเอกสารโดยเรียกใช้เมธอด Save
ตัวอย่างโค้ด C# ต่อไปนี้แสดงวิธีการแทรกข้อความในไฟล์ PostScript โดยอัตโนมัติ:
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(); | |
} |

แทรกข้อความในไฟล์ PS โดยใช้สตริง Unicode
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(); | |
} |
รับใบอนุญาตฟรี
เพื่อสำรวจศักยภาพเต็มรูปแบบของ Aspose.Page สำหรับ .NET, ขอรับใบอนุญาตทดลองฟรีจาก ที่นี่.
สรุป
เราได้เรียนรู้เกี่ยวกับวิธีการเพิ่มข้อความในไฟล์ PS โดยใช้ Aspose.Page สำหรับ .NET API PostScript นี้เสนอวิธีที่ราบรื่นในการแก้ไขไฟล์ PostScript ทำให้เป็นตัวเลือกที่มีคุณค่าสำหรับนักพัฒนา สำรวจ Aspose.Page สำหรับ .NET วันนี้เพื่อเพิ่มขีดความสามารถในการประมวลผลเอกสารของคุณ
แหล่งข้อมูลสาธารณะ
สำรวจแหล่งข้อมูลเพิ่มเติมเช่นเอกสารและฟอรัมชุมชนเพื่อเพิ่มความเข้าใจของคุณเกี่ยวกับ Aspose.Page สำหรับ .NET. แหล่งข้อมูลเหล่านี้ให้ข้อมูลเชิงลึกและการสนับสนุนที่มีค่าเกินเนื้อหาบล็อก
คำถามที่พบบ่อย – FAQs
ฉันจะเพิ่มข้อความในไฟล์ PS โดยใช้ Aspose.Page สำหรับ .NET ได้อย่างไร?
เพื่อเพิ่มข้อความ ให้โหลดไฟล์ PS ด้วย PsDocument
สร้างอ็อบเจ็กต์ PsText
เพิ่มมันลงในเอกสารและบันทึกการเปลี่ยนแปลง ใช้ ตัวอย่างโค้ด ที่ให้ไว้เป็นแนวทาง
Aspose.Page สำหรับ .NET เหมาะสำหรับการแก้ไขไฟล์ PostScript หรือไม่?
ใช่, Aspose.Page สำหรับ .NET เหมาะสำหรับการแก้ไขไฟล์ PostScript มันมี API PostScript ที่แข็งแกร่ง ความสะดวกในการรวมเข้าด้วยกัน และตัวเลือกการปรับแต่งขั้นสูง
ฉันสามารถทดลองใช้ Aspose.Page สำหรับ .NET ก่อนการซื้อได้หรือไม่?
ใช่ คุณสามารถขอรับใบอนุญาตทดลองฟรีจาก หน้าใบอนุญาตชั่วคราวของ Aspose ซึ่งช่วยให้คุณสำรวจฟีเจอร์ของไลบรารีได้โดยไม่มีข้อจำกัด