IRONSOFTWAREHOME
影片

如何在 C# 中使用虛擬視窗和縮放

Curtis Chau
Curtis Chau
Updated: 2026年7月19日

從PDFFilePrint遷移到IronPDF會將您的.NET PDF工作流從僅列印的Pdfium包裝器轉移到一個可處理建立、操作和列印的綜合PDF程式庫,這一切都在一個統一的API中完成。 本指南提供了一個逐步的遷移路徑,用於將PrinterSettings,同時增加PDF生成和操作功能,而這是PDFFilePrint無法提供的。

為什麼要從PDFFilePrint遷移到IronPDF

了解PDFFilePrint

PDFFilePrint是一個小型開源NuGet套件(由Christian Andersen建立的MIT許可),它包裝了PdfiumViewer和谷歌的Pdfium,以靜默地將現有的PDF或XPS文件發送到列印機驅動。 最新版本是1.0.3,發佈於2020-02-10,針對Windows上的**.NET Framework 4.6.1+**。 雖然對於針對性的列印任務有用,但其功能僅限於文件處理的一個方面——公共介面基本上是app.config / Properties.Settings.Default鍵驅動。

PDFFilePrint的關鍵限制

  1. **僅列印:**不能建立、編輯、合併或修改PDF——FilePrint 類消耗現有的PDF/XPS文件並將它們交給列印器。

  2. **配置文件驅動的API:**列印機名稱、紙張大小、份數和"列印到文件"模式從app.config (Properties.Settings.Default) 讀取,而不是作為強型別的選項物件傳遞。

  3. **僅限Windows + .NET Framework:**針對net461,並引入PdfiumViewer的Win32原生二進制文件。 無.NET Core / .NET 6+目標框架,且無Linux/macOS支持。

  4. **有限的列印旋鈕:**雙面列印、頁面範圍、方向和顏色依賴於列印機驅動預設值——沒有一流的API可用。

  5. **實際上無人維護:**自1.0.3(2020年2月)以來沒有發佈版本,且NuGet列表中沒有鏈結到公共源程式碼庫。

  6. **普通異常介面:**故障從PdfiumViewer / 列印器作為一般異常而不是型別化的錯誤階層浮現。

  7. **無PDF生成:**無法建立PDF——從HTML、網址或圖像到列印頁面,您必須將PDFFilePrint與一個單獨的渲染器配對。

PDFFilePrint與IronPDF比較

方面PDFFilePrintIronPDF
主要重點PDF/XPS列印綜合PDF API
型別Pdfium列印包裝器原生.NET程式庫 + Chromium渲染引擎
整合new FilePrint(...).Print() + app.config直接PdfDocument API
PDF列印
PDF建立是(HTML,網址,圖像)
PDF 操作是(合併,分割,編輯)
跨平台僅Windows(net461)Windows, Linux, macOS, Docker
錯誤處理來自PdfiumViewer的普通異常型別化IronPdfException
IntelliSense最小(小表面)全面
NuGet套件PDFFilePrint 1.0.3(MIT,2020年2月)IronPdf
最新版本1.0.3(2020年2月)活躍版本

對於旨在使用現代.NET(Framework 4.6.2+和.NET 6/7/8/9/10)的團隊,IronPDF提供了跨平台支持和積極開發的綜合基礎,解決了PDFFilePrint的架構限制。


開始之前

前提條件

  1. .NET環境: .NET Framework 4.6.2+ 或 .NET 6/7/8/9/10
  2. NuGet存取: 有能力安裝NuGet套件
  3. IronPDF授權:ironpdf.com獲取您的授權金鑰

NuGet包變更

# Remove PDFFilePrint package
dotnet remove package PDFFilePrint

# Install IronPDF
dotnet add package IronPdf
SHELL

授權配置

// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

識別PDFFilePrint的使用

# Find PDFFilePrint API usages
grep -r "using PDFFilePrint\|new FilePrint" --include="*.cs" .

# Find related app.config keys
grep -r "PrinterName\|PaperName\|PrintToFile\|DefaultPrintToDirectory" \
    --include="*.config" --include="*.settings" .
SHELL

完整API參考

名稱空間變更

// PDFFilePrint
using PDFFilePrint;

//IronPDF— printing flows through System.Drawing.Printing
using IronPdf;
using System.Drawing.Printing;
C#

核心類別映射

PDFFilePrintIronPDF
new FilePrint(path, null) (載入)PdfDocument.FromFile(path)
new ChromePdfRenderer() (無等效——PDFFilePrint無法建立PDF)new ChromePdfRenderer()
FilePrintPdfDocument

PDF生成方法映射

PDFFilePrintIronPDF
(不可用)renderer.RenderHtmlAsPdf(html)
(不可用)renderer.RenderUrlAsPdf(url)
(不可用——僅列印)pdf.SaveAs(path)

PDF載入和列印映射

PDFFilePrintIronPDF
new FilePrint(path, null)PdfDocument.FromFile(path)
fileprint.Print() (靜默,總是)pdf.Print() (靜默) / pdf.Print(true) (對話框)
Properties.Settings.Default.PrinterName = "..." 接著 Print()pdf.GetPrintDocument(new PrinterSettings { PrinterName = "..." }).Print()

列印設置映射(app.config到PrinterSettings)

PDFFilePrint設置 (Settings.Default)IronPDF(System.Drawing.Printing.PrinterSettings)
PrinterNamePrinterName
CopiesCopies
(無靜默標誌——總是靜默)pdf.Print() (靜默) / pdf.Print(true) (顯示對話框)
(驅動預設值)FromPage, ToPage, PrintRange
(驅動預設值)DefaultPageSettings.Landscape
(驅動預設值)Duplex
(驅動預設值)Collate
PaperNameDefaultPageSettings.PaperSize
PrintToFile + DefaultPrintToDirectoryPrintToFile + PrintFileName

PDFFilePrint中不存在的新功能

IronPDF功能說明
PdfDocument.Merge()合併多個PDF
pdf.CopyPages()提取特定頁面
pdf.ApplyWatermark()新增水印
pdf.SecuritySettings密碼保護
pdf.ExtractAllText()提取文字內容
pdf.RasterizeToImageFiles()轉換為圖像
pdf.SignWithDigitalSignature()數位簽名

程式碼遷移範例

範例1:HTML轉PDF轉換

之前(PDFFilePrint):

// NuGet: Install-Package PDFFilePrint
// PDFFilePrint is a print-only wrapper around PdfiumViewer / Pdfium.
// Its FilePrint class only consumes existing PDF/XPS files — there is
// no CreateFromHtml or document-creation method.
using System;

class Program
{
    static void Main()
    {
        throw new NotSupportedException(
            "PDFFilePrint cannot convert HTML to PDF. Render the HTML to a PDF " +
            "with another library, then pass the path to new FilePrint(path, null).Print().");
    }
}

之後(IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        string htmlContent = "<html><body><h1>Hello World</h1></body></html>";
        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        pdf.SaveAs("output.pdf");
    }
}

這裡的根本區別在於範圍。 PDFFilePrint 沒有 HTML 到 PDF 的路徑——其公共介面是一個FilePrint類,將現有的PDF交給列印機。 IronPDF將渲染與文件物件分離:ChromePdfRenderer 處理 HTML 到 PDF 的轉換,並返回 PdfDocument,然後您用 SaveAs() 儲存。

這種分離也讓您在轉換之前配置渲染器上的渲染選項,並在儲存之前操作返回的PdfDocument(新增水印,與其他PDF合併,新增安全性)。 查看HTML到PDF文件以獲取其他渲染選項。

範例2:URL轉PDF轉換

之前(PDFFilePrint):

// NuGet: Install-Package PDFFilePrint
// PDFFilePrint cannot fetch a URL or render HTML — it only sends existing
// PDF/XPS files to a printer. URL-to-PDF requires a separate renderer.
using System;

class Program
{
    static void Main()
    {
        throw new NotSupportedException(
            "PDFFilePrint cannot convert URLs to PDF. Render the URL to a PDF with " +
            "another library first, then call new FilePrint(pdfPath, null).Print().");
    }
}

之後(IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
        pdf.SaveAs("webpage.pdf");
    }
}

PDFFilePrint沒有網址抓取功能。 IronPDF使用ChromePdfRenderer上,該方法利用Chromium引擎來渲染現代CSS、JavaScript和網頁特徵。 了解有關URL到PDF轉換的更多資訊。

範例3:PDF列印

之前(PDFFilePrint):

// NuGet: Install-Package PDFFilePrint
using System;
using PDFFilePrint;

class Program
{
    static void Main()
    {
        // Optional: override the configured printer / copy count at runtime.
        Properties.Settings.Default.PrinterName = "Default Printer";

        var fileprint = new FilePrint("document.pdf", null);
        fileprint.Print();
        Console.WriteLine("PDF sent to printer");
    }
}

之後(IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Drawing.Printing;

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("document.pdf");

        // Silent print to the default printer
        pdf.Print();

        // Or print to a named printer with explicit PrinterSettings:
        // var settings = new PrinterSettings { PrinterName = "HP LaserJet Pro" };
        // pdf.GetPrintDocument(settings).Print();

        Console.WriteLine("PDF sent to printer");
    }
}

此範例顯示了兩個程式庫之間的架構差異。 PDFFilePrint實例化app.config (Properties.Settings.Default) 讀取。 IronPDF使用靜態工廠System.Drawing.Printing.PrinterSettings以獲得顯式控制。

遷移的關鍵改變:

  • new FilePrint(path, null)PdfDocument.FromFile(path)
  • Properties.Settings.Default.PrinterName = "..." + Print()pdf.GetPrintDocument(new PrinterSettings { PrinterName = "..." }).Print()
  • 預設列印機:在pdf.Print()

對於高級列印設置,IronPDF使用System.Drawing.Printing.PrinterSettings。 請查看印刷文件以獲取更多選項。


高級列印設置遷移

對於使用PDFFilePrint的PrinterSettings

// PDFFilePrint approach — settings live in app.config and are read via
// Properties.Settings.Default. To override at runtime you mutate Settings.Default
// before instantiating FilePrint:
//   Properties.Settings.Default.PrinterName = "HP LaserJet";
//   Properties.Settings.Default.Copies = 3;
//   new FilePrint("document.pdf", null).Print();
//
//IronPDFequivalent — pass a System.Drawing.Printing.PrinterSettings per call:
using IronPdf;
using System.Drawing.Printing;

var pdf = PdfDocument.FromFile("document.pdf");

var settings = new PrinterSettings
{
    PrinterName = "HP LaserJet",
    Copies = 3,
    FromPage = 1,
    ToPage = 5,
    PrintRange = PrintRange.SomePages
};

pdf.GetPrintDocument(settings).Print();
C#

靜默模式

// PDFFilePrint is always silent — there is no print-dialog code path.
//IronPDFis silent by default. Pass true explicitly to show the print dialog:
pdf.Print();      // silent
pdf.Print(true);  // shows print dialog
C#

遷移後的新能力

遷移到IronPDF後,您將獲得PDFFilePrint無法提供的功能:

一步建立和列印

using IronPdf;
using System.Drawing.Printing;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Invoice #12345</h1><p>Thank you for your order.</p>");

var settings = new PrinterSettings { PrinterName = "Office Printer" };
pdf.GetPrintDocument(settings).Print();

PDF合併

var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");

水印

var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark("<h1 style='color:red; opacity:0.3;'>CONFIDENTIAL</h1>");
pdf.SaveAs("watermarked.pdf");

密碼保護

var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SecuritySettings.UserPassword = "userpassword";
pdf.SecuritySettings.OwnerPassword = "ownerpassword";
pdf.SaveAs("secured.pdf");

文字提取

var pdf = PdfDocument.FromFile("document.pdf");
string text = pdf.ExtractAllText();

關鍵遷移注意事項

類模式改變

PDFFilePrint使用一個小app.config驅動。 IronPDF將渲染,文件操作和列印分成不同的型別:

// PDFFilePrint: load + silent print (settings come from app.config)
Properties.Settings.Default.PrinterName = "HP LaserJet";
var fileprint = new FilePrint(path, null);
fileprint.Print();

// IronPDF: PdfDocument for load/manipulate, PrinterSettings for print options
var pdf = PdfDocument.FromFile(path);
var settings = new PrinterSettings { PrinterName = "HP LaserJet" };
pdf.GetPrintDocument(settings).Print();

//IronPDFcan also create PDFs from HTML — PDFFilePrint cannot
var renderer = new ChromePdfRenderer();
var newPdf = renderer.RenderHtmlAsPdf(html);
newPdf.SaveAs(path);
C#

方法/設置命名更改

// PDFFilePrint → IronPDF
new FilePrint(path, null)                       → PdfDocument.FromFile(path)
fileprint.Print()                               → pdf.Print()  // silent default
Properties.Settings.Default.PrinterName = "X"new PrinterSettings { PrinterName = "X" }
Properties.Settings.Default.Copies = 3new PrinterSettings { Copies = 3 }
Properties.Settings.Default.PaperName = "A4"    → settings.DefaultPageSettings.PaperSize = ...
// PDFFilePrint has no native HTML/URL/merge/watermark methods — these are IronPDF-only.

異常處理

// PDFFilePrint: failures bubble up from PdfiumViewer as plain exceptions
try {
    new FilePrint(path, null).Print();
}
catch (Exception ex) {
    // 否 granular error type — log the message and inner exception.
}

// IronPDF: typed exception hierarchy
try {
    pdf.Print();
}
catch (IronPdf.Exceptions.IronPdfException ex) {
    // Granular error details
}
C#

不論哪種情況都無外部可執行文件

兩個程式庫都是作為NuGet包進行分發。 沒有捆綁或刪除IronPdf包自給自足的,原生依賴項在恢復時解決。


功能比較總結

功能PDFFilePrintIronPDF
基本列印
靜默列印✓(總是靜默)
多次拷貝✓(通過app.config)
頁碼範圍僅限驅動程式預設
雙面僅限驅動程式預設
從HTML建立
從URL建立
合併PDF
拆分PDF
新增水印
提取文字
密碼保護
數位簽名
跨平台✗(Windows / net461)
原生.NET API✓(小表面)

遷移檢查表

遷移前

  • 定位所有new FilePrint(...)調用點
  • 當前文件app.config設置 (PrinterName, PaperName, Copies, PrintToFile, DefaultPrintToDirectory)
  • 識別跨環境使用的列印機名稱
  • 記錄任何在運行時變更Properties.Settings.Default的程式碼
  • 識別新特徵的機會(HTML/URL渲染、合併、水印、安全)
  • 獲得IronPDF授權金鑰

套件變更

  • 移除PDFFilePrint NuGet包:dotnet remove package PDFFilePrint
  • 安裝IronPdf NuGet包:dotnet add package IronPdf
  • using System.Drawing.Printing;

程式碼變更

  • 在啟動時加入授權金鑰配置
  • PdfDocument.FromFile(path)
  • 將列印機/復印/紙張設置從System.Drawing.Printing.PrinterSettings
  • 使用pdf.GetPrintDocument(settings).Print()進行顯式選項
  • 在先前捕獲一般異常的地方,將try / catch IronPdfException中包裹
  • 對於HTML/URL/合併/水印功能(PDFFilePrint從未提供過),使用PdfDocument操作API

遷移後

  • app.config中刪除PDFFilePrint特定鍵
  • 在所有目標列印機上進行測試列印
  • 如適用,進行跨平台測試(Linux列印需要CUPS)
  • 根據需要新增新功能(水印、安全、合併)
  • 更新文件

請注意: PDFFilePrint是其各自擁有者的註冊商標。 本網站與PDFFilePrint無關,也未經其授權或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供參考,反映撰寫時公開可用的資訊。
Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

相關文章

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費現場演示
Booking Badge

受到全球數百萬工程師的信任

Iron Software的客戶標誌
獲取您的無義務諮詢
填寫以下表格或電子郵件sales@ironsoftware.com
您的詳細資訊將始終保密
受到全球數百萬工程師的信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立