介紹IronWord:用於Word文件編輯的C# DOCX程式庫

如果您曾經需要將您的應用程式更新到較新版的 .NET,您可能對 .NET Upgrade Assistant 並不陌生。 這個來自 Microsoft 的強大工具使升級專案的過程變得簡單而直接——至少對於 Microsoft 的程式庫和框架來說是這樣。 對於外部服務,更新到新版本仍然是一個手動且耗時的過程。
不過,現在不再是這樣了! .NET Upgrade Assistant 本身剛剛進行了一次重大升級。 上個月,Microsoft 宣布了對其工具的第三方 API 和套件地圖支持,允許開發者分享自己的地圖,並在更新到新框架時更容易替換過時的第三方 API 和套件。
第三方 API 支持的加入提供了一個標準化的方法來整合 API,而套件地圖則如同其名稱所示——它映射了應用程式中使用的所有套件,使更新依賴項變得更簡單,並改善專案的整體穩定性。
更換程式庫從未如此簡單
在此更新之前,如果您的應用程式依賴外部服務,升級到較新版的 .NET 或更換框架是困難的。 這意味著需要手動尋找等效的 API 和套件——這還沒算上更新所有型別和方法的麻煩。 正如 Microsoft 在公告文章中解釋的那樣:
讓我們以 Xamarin.Forms.Color 為例。 不僅需要將命名空間從 Xamarin.Forms 更新為 Microsoft.Maui.Graphics,還需要將 R、G 或 B 等屬性更改為 Red、Green 或 Blue,而像 AliceBlue 這樣的靜態色彩屬性現在屬於一個叫做 Colors 的新型別。
現在開發者可以像 Microsoft 對其程式庫所做的那樣建立自己的地圖,這些麻煩已成為過去。不僅是針對更新程式庫而言,.NET Upgrade Assistant 現在還可以用來完全更換程式庫。
將 Iron Software 產品整合到您的應用程式中一直很簡單,但從其他程式庫切換到 Iron Software 並不是那麼直接。 但是現在,有了自定義映射和 API 支持,升級應用程式以搭載全新程式庫比以往任何時候都更容易。 讓我們來看看這段程式碼,如何在 IronPDF 和 PDFSharp 中建立一個簡單的 PDF:
IronPDF
// Import the required namespace from IronPDF
using IronPdf;
// Initialize the HtmlToPdf object
var htmlToPdf = new HtmlToPdf();
// Render the HTML content to PDF
var pdf = htmlToPdf.RenderHtmlAsPdf("<html><body><h1>Hello, IronPDF!</h1></body></html>");
// Save the generated PDF to a file
pdf.SaveAs("ironpdf_example.pdf");// Import the required namespace from IronPDF
using IronPdf;
// Initialize the HtmlToPdf object
var htmlToPdf = new HtmlToPdf();
// Render the HTML content to PDF
var pdf = htmlToPdf.RenderHtmlAsPdf("<html><body><h1>Hello, IronPDF!</h1></body></html>");
// Save the generated PDF to a file
pdf.SaveAs("ironpdf_example.pdf");' Import the required namespace from IronPDF
Imports IronPdf
' Initialize the HtmlToPdf object
Private htmlToPdf = New HtmlToPdf()
' Render the HTML content to PDF
Private pdf = htmlToPdf.RenderHtmlAsPdf("<html><body><h1>Hello, IronPDF!</h1></body></html>")
' Save the generated PDF to a file
pdf.SaveAs("ironpdf_example.pdf")PDFSharp
// Import the necessary namespaces from PDFsharp
using PdfSharp.Pdf;
// Define the main class that contains the program's entry point
class Program
{
// Main method: the entry point of the program
static void Main()
{
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Add a page to the document
PdfPage page = document.AddPage();
// Obtain a graphics object to draw on the page
XGraphics gfx = XGraphics.FromPdfPage(page);
// Draw "Hello, PDFsharp!" on the page
gfx.DrawString("Hello, PDFsharp!", new XFont("Arial", 12), XBrushes.Black,
new XRect(10, 10, page.Width, page.Height), XStringFormats.TopLeft);
// Save the document to a file
document.Save("output.pdf");
// Close the document to free resources
document.Close();
}
}// Import the necessary namespaces from PDFsharp
using PdfSharp.Pdf;
// Define the main class that contains the program's entry point
class Program
{
// Main method: the entry point of the program
static void Main()
{
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Add a page to the document
PdfPage page = document.AddPage();
// Obtain a graphics object to draw on the page
XGraphics gfx = XGraphics.FromPdfPage(page);
// Draw "Hello, PDFsharp!" on the page
gfx.DrawString("Hello, PDFsharp!", new XFont("Arial", 12), XBrushes.Black,
new XRect(10, 10, page.Width, page.Height), XStringFormats.TopLeft);
// Save the document to a file
document.Save("output.pdf");
// Close the document to free resources
document.Close();
}
}' Import the necessary namespaces from PDFsharp
Imports PdfSharp.Pdf
' Define the main class that contains the program's entry point
Friend Class Program
' Main method: the entry point of the program
Shared Sub Main()
' Create a new PDF document
Dim document As New PdfDocument()
' Add a page to the document
Dim page As PdfPage = document.AddPage()
' Obtain a graphics object to draw on the page
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
' Draw "Hello, PDFsharp!" on the page
gfx.DrawString("Hello, PDFsharp!", New XFont("Arial", 12), XBrushes.Black, New XRect(10, 10, page.Width, page.Height), XStringFormats.TopLeft)
' Save the document to a file
document.Save("output.pdf")
' Close the document to free resources
document.Close()
End Sub
End Class正如您所見,更換程式庫可能需要對程式碼進行大量更改,這需要花費時間、精力,並可能使應用程式變得不穩定。 但現在,我們可以半自動化對命名空間、型別和方法的更改,讓您輕鬆升級專案。
Iron Software 和 .NET 密不可分
隨著這次對 .NET Upgrade Assistant 的新更新,它使第三方開發者能夠緊跟技術前沿——使他們的應用程式與 .NET Core 及其他框架的最新版本保持同步。 在 Iron Software,我們的產品始終將相容性放在首位。 支持多年前的 .NET Core、Standard 和 Framework 版本,我們始終提供行業領先的軟體,無論我們的客戶使用什麼設置。 但現在,您可以在不損及穩定性或功能性的情況下升級應用程式到更新版本——我們將始終與您同行。
我們對這次 .NET Upgrade Assistant 的更新感到非常興奮。 如果您是希望使用此工具來更新支持 Iron Software 的應用程式的開發者,請與我們聯繫以便我們提供協助!對於其他人來說,請持續關注將改善您的工作流程和專案的套件地圖。
Iron Software 產品的價格低僅 $2,998 即可獲得終身許可(包括一年的免費支持,因此我們可以幫助您通過這些新工具更新您的應用程式)。 您可以從我們的 30 天免費試用開始,我們的軟體也完全免費供開發用途使用——讓您真正了解它的能力。 如需更大的節省,查看 Iron Suite,您可以用兩套工具的價格獲得全部九套 Iron Software 工具。 開心編程!
