
Jak korzystać z wirtualnego okna podglądu i Zoom w języku C#
Migracja zPDFFilePrintdo IronPDF przenosi twój przebieg PDF .NET z opakowania Pdfium wyłącznie do drukowania do kompleksowej biblioteki PDF, która obsługuje tworzenie, manipulację i drukowanie w ramach jednego ujednoliconego API. Ten przewodnik zapewnia szczegółową ścieżkę migracji, która zastępuje ustawienia druku napędzane przez app.config z obiektami silnie typowanymi PrinterSettings, jednocześnie dodając możliwości generowania i manipulowania PDF, którychPDFFilePrintnie oferuje.
Dlaczego warto przejść zPDFFilePrintna IronPDF
Zrozumienie PDFFilePrint
PDFFilePrint to mały pakiet NuGet open source (MIT, autorstwa Christiana Andersena) opakowujący PdfiumViewer i Google Pdfium, aby cicho wysłać istniejący plik PDF lub XPS do sterownika drukarki. Najnowsze wydanie to 1.0.3, opublikowane 2020-02-10, skierowane na .NET Framework 4.6.1+ na Windows. Chociaż przydatne do zadań drukowania ukierunkowanych, jego funkcjonalność ogranicza się do jednego aspektu obsługi dokumentów - publiczny interfejs jest zasadniczo new FilePrint(path, null).Print() napędzany przez klucze app.config / Properties.Settings.Default.
Istotne ograniczenia PDFFilePrint
-
Tylko drukowanie: Nie można tworzyć, edytować, scalać ani modyfikować plików PDF - klasa
FilePrintzużywa istniejące pliki PDF/XPS i przekazuje je do kolejki. -
API napędzane plikami konfiguracyjnymi: Nazwa drukarki, rozmiar papieru, liczba kopii i tryb "drukuj do pliku" są odczytywane z
app.config(Properties.Settings.Default), a nie przekazywane jako obiekt opcji silnie typowanych. -
Tylko Windows + .NET Framework: Celuje w
net461i pobiera natywne binaria Win32 z PdfiumViewer. Brak wsparcia .NET Core / .NET 6+ i brak wsparcia Linux/macOS. -
Ograniczone pokrętła drukowania: Duplex, zakres strony, orientacja i kolor polegają na domyślnych ustawieniach sterownika drukarki - brak dla nich pierwszoklasowego API.
-
Skutecznie nie są aktualizowane: Brak wydania od wersji 1.0.3 (luty 2020) i brak publicznego repozytorium źródeł powiązanego z wykazem NuGet.
-
Zwykła powierzchnia wyjątków: Awaria wywołana z PdfiumViewer / bufora jako ogólne wyjątki, a nie jako hierarchia błędów typowana.
-
Brak generowania PDF-ów: Nie potrafi tworzyć PDF-ów - aby przejść od HTML, URL lub obrazów do strony drukowanej, należy połączyćPDFFilePrintz oddzielnym rendererem.
PorównaniePDFFilePrinti IronPDF
| Aspekt | PDFFilePrint | IronPDF |
|---|---|---|
| Główny cel | Drukowanie PDF/XPS | Kompleksowe API PDF |
| Typ | Opakowanie do drukowania Pdfium | Natywna biblioteka .NET + renderer Chromium |
| Integracja | new FilePrint(...).Print() + app.config | Bezpośrednie API PdfDocument |
| Drukowanie plików PDF | Tak | Tak |
| Tworzenie plików PDF | Nie | Tak (HTML, URL, obrazy) |
| Manipulacja plikami PDF | Nie | Tak (łączenie, dzielenie, edytowanie) |
| Wielopłatformowe | Tylko Windows (net461) | Windows, Linux, macOS, Docker |
| Obsługa błędów | Zwykłe wyjątki z PdfiumViewer | Silnie typowane IronPdfException |
| IntelliSense | Minimalna (mała powierzchnia) | Pełna |
| Pakiet NuGet | PDFFilePrint 1.0.3 (MIT, luty 2020) | IronPdf |
| Ostatnie wydanie | 1.0.3 (luty 2020) | Aktywne wydania |
Dla zespołów celujących we współczesny .NET (Framework 4.6.2+ oraz .NET 6/7/8/9/10),IronPDF daje kompleksową bazę z obsługą wieloplatformową i aktywnym rozwojem, zajmując miejsce przez ograniczenia architektoniczne PDFFilePrint.
Zanim zaczniesz
Wymagania wstępne
- Srodowisko .NET: .NET Framework 4.6.2+ lub .NET 6/7/8/9/10
- Dostęp do NuGet: Możliwość instalowania pakietów NuGet
- Licencja IronPDF: Uzyskaj klucz licencyjny na stronie ironpdf.com
Zmiany w pakiecie NuGet
# RemovePDFFilePrintpackage
dotnet remove package PDFFilePrint
# Install IronPDF
dotnet add package IronPdf
Konfiguracja licencji
// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";' Add at application startup (Program.vb or Startup.vb)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"' Add at application startup (Program.vb or Startup.vb)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"Zidentyfikuj użycie PDFFilePrint
# FindPDFFilePrintAPI usages
grep -r "using PDFFilePrint\|new FilePrint" --include="*.cs" .
# Find related app.config keys
grep -r "PrinterName\|PaperName\|PrintToFile\|DefaultPrintToDirectory" \
--include="*.config" --include="*.settings" .
Kompletna dokumentacija API
Zmiany w przestrzeni nazw
// PDFFilePrint
using PDFFilePrint;
//IronPDF— printing flows through System.Drawing.Printing
using IronPdf;
using System.Drawing.Printing;// PDFFilePrint
using PDFFilePrint;
//IronPDF— printing flows through System.Drawing.Printing
using IronPdf;
using System.Drawing.Printing;' PDFFilePrint
Imports PDFFilePrint
'IronPDF— printing flows through System.Drawing.Printing
Imports IronPdf
Imports System.Drawing.Printing' PDFFilePrint
Imports PDFFilePrint
'IronPDF— printing flows through System.Drawing.Printing
Imports IronPdf
Imports System.Drawing.PrintingMapowania klas podstawowych
| PDFFilePrint | IronPDF |
|---|---|
new FilePrint(path, null) (load) | PdfDocument.FromFile(path) |
new ChromePdfRenderer() (brak odpowiednika - PDFFilePrintnie może tworzyć plików PDF) | new ChromePdfRenderer() |
FilePrint | PdfDocument |
Mapowania metod generowania plików PDF
| PDFFilePrint | IronPDF |
|---|---|
| (niedostępne) | renderer.RenderHtmlAsPdf(html) |
| (niedostępne) | renderer.RenderUrlAsPdf(url) |
| (niedostępny - tylko drukowanie) | pdf.SaveAs(path) |
Mapowania ładowania i drukowania plików PDF
| PDFFilePrint | IronPDF |
|---|---|
new FilePrint(path, null) | PdfDocument.FromFile(path) |
fileprint.Print() (niezauważalnie, zawsze) | pdf.Print() (niezauważalnie) / pdf.Print(true) (dialog) |
Properties.Settings.Default.PrinterName = "..." potem Print() | pdf.GetPrintDocument(new PrinterSettings { PrinterName = "..." }).Print() |
Mapowanie ustawień drukowania (app.config do PrinterSettings)
UstawieniePDFFilePrint(Settings.Default) | IronPDF(System.Drawing.Printing.PrinterSettings) |
|---|---|
PrinterName | PrinterName |
Copies | Copies |
| (brak flagi ciszy - zawsze cicha) | pdf.Print() (niezauważalnie) / pdf.Print(true) (pokaż dialog) |
| (domyślny sterownik) | FromPage, ToPage, PrintRange |
| (domyślny sterownik) | DefaultPageSettings.Landscape |
| (domyślny sterownik) | Duplex |
| (domyślny sterownik) | Collate |
PaperName | DefaultPageSettings.PaperSize |
PrintToFile + DefaultPrintToDirectory | PrintToFile + PrintFileName |
Nowe funkcje niedostępne w PDFFilePrint
| Funkcja IronPDF | Opis |
|---|---|
PdfDocument.Merge() | Łączenie wielu plików PDF |
pdf.CopyPages() | Wyodrębnij konkretne strony |
pdf.ApplyWatermark() | Dodaj znaki wodne |
pdf.SecuritySettings | Ochrona hasłem |
pdf.ExtractAllText() | Wyodrębnij treść tekstową |
pdf.RasterizeToImageFiles() | Konwertuj na obrazy |
pdf.SignWithDigitalSignature() | Podpisy cyfrowe |
Przykłady migracji kodu
Przykład 1: Konwersja HTML do PDF
Przed (PDFFilePrint):
// NuGet: Install-Package PDFFilePrint
//PDFFilePrintis 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().");
}
}// NuGet: Install-Package PDFFilePrint
//PDFFilePrintis 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().");
}
}Imports System
Class Program
Shared Sub 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().")
End Sub
End ClassImports System
Class Program
Shared Sub 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().")
End Sub
End ClassPo (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");
}
}// 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");
}
}Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim htmlContent As String = "<html><body><h1>Hello World</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("output.pdf")
End Sub
End ClassImports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim htmlContent As String = "<html><body><h1>Hello World</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("output.pdf")
End Sub
End ClassPodstawowa różnica tutaj to zakres.PDFFilePrintnie ma ścieżki HTML-do-PDF - publiczny interfejs jest klasą FilePrint, która przekazuje istniejący PDF do drukarki.IronPDF oddziela renderowanie od obiektu dokumentu: ChromePdfRenderer obsługuje konwersję HTML do PDF i zwraca PdfDocument, który następnie zapisujesz za pomocą SaveAs().
To rozdzielenie pozwala również na konfigurację opcji renderowania w rendererze przed konwersją, oraz manipulację zwróconym PdfDocument (dodawanie znaków wodnych, scalanie z innymi plikami PDF, dodawanie zabezpieczeń) przed zapisaniem. Dodatkowe opcje renderowania można znaleźć w dokumentacji dotyczącej konwersji HTML do PDF.
Przykład 2: Konwersja adresów URL do formatu PDF
Przed (PDFFilePrint):
// NuGet: Install-Package PDFFilePrint
//PDFFilePrintcannot 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().");
}
}// NuGet: Install-Package PDFFilePrint
//PDFFilePrintcannot 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().");
}
}Imports System
Module Program
Sub 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().")
End Sub
End ModuleImports System
Module Program
Sub 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().")
End Sub
End ModulePo (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");
}
}// 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");
}
}Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://www.example.com")
pdf.SaveAs("webpage.pdf")
End Sub
End ClassImports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://www.example.com")
pdf.SaveAs("webpage.pdf")
End Sub
End ClassPDFFilePrint nie ma możliwości pobierania URL.IronPDF używa dedykowanej metody RenderUrlAsPdf() w ChromePdfRenderer, która wykorzystuje silnik Chromium do renderowania nowoczesnych funkcji CSS, JavaScript i internetowych. Dowiedz się więcej o konwersji adresów URL do formatu PDF.
Przykład 3: Drukowanie plików PDF
Przed (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");
}
}// 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");
}
}Imports System
Imports PDFFilePrint
Module Program
Sub Main()
' Optional: override the configured printer / copy count at runtime.
Properties.Settings.[Default].PrinterName = "Default Printer"
Dim fileprint = New FilePrint("document.pdf", Nothing)
fileprint.Print()
Console.WriteLine("PDF sent to printer")
End Sub
End ModuleImports System
Imports PDFFilePrint
Module Program
Sub Main()
' Optional: override the configured printer / copy count at runtime.
Properties.Settings.[Default].PrinterName = "Default Printer"
Dim fileprint = New FilePrint("document.pdf", Nothing)
fileprint.Print()
Console.WriteLine("PDF sent to printer")
End Sub
End ModulePo (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");
}
}// 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");
}
}Imports IronPdf
Imports System
Imports System.Drawing.Printing
Module Program
Sub Main()
Dim pdf = PdfDocument.FromFile("document.pdf")
' Silent print to the default printer
pdf.Print()
' Or print to a named printer with explicit PrinterSettings:
' Dim settings As New PrinterSettings With {.PrinterName = "HP LaserJet Pro"}
' pdf.GetPrintDocument(settings).Print()
Console.WriteLine("PDF sent to printer")
End Sub
End ModuleImports IronPdf
Imports System
Imports System.Drawing.Printing
Module Program
Sub Main()
Dim pdf = PdfDocument.FromFile("document.pdf")
' Silent print to the default printer
pdf.Print()
' Or print to a named printer with explicit PrinterSettings:
' Dim settings As New PrinterSettings With {.PrinterName = "HP LaserJet Pro"}
' pdf.GetPrintDocument(settings).Print()
Console.WriteLine("PDF sent to printer")
End Sub
End ModuleTen przykład pokazuje różnicę architektoniczną między dwiema bibliotekami.PDFFilePrintinstancjuje new FilePrint(path, null) i wywołuje Print(), z nazwą drukarki i liczbą kopii odczytywanych z app.config (Properties.Settings.Default).IronPDF używa statycznej fabryki PdfDocument.FromFile() do ładowania, a następnie Print(), który korzysta z domyślnej drukarki - lub przekazujesz System.Drawing.Printing.PrinterSettings poprzez GetPrintDocument(settings).Print() do jawnej kontroli.
Najważniejsze zmiany związane z migracją:
new FilePrint(path, null)→PdfDocument.FromFile(path)Properties.Settings.Default.PrinterName = "..."+Print()→pdf.GetPrintDocument(new PrinterSettings { PrinterName = "..." }).Print()- Domyślna drukarka: pozostaw
PrinterNamepuste wSettings.Default→ wywołajpdf.Print()
W celu zaawansowanych ustawień druku,IronPDF używa System.Drawing.Printing.PrinterSettings. Zobacz dokumentację drukowania dla dodatkowych opcji.
Migracja zaawansowanych ustawień drukowania
Dla aplikacji używających kluczy app.config PDFFilePrint, oto jak przejść do silnie typowanych PrinterSettings w IronPDF:
//PDFFilePrintapproach — 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();
//
//IronPDF equivalent — 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();//PDFFilePrintapproach — 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();
//
//IronPDF equivalent — 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();Imports IronPdf
Imports System.Drawing.Printing
Dim pdf = PdfDocument.FromFile("document.pdf")
Dim settings = New PrinterSettings With {
.PrinterName = "HP LaserJet",
.Copies = 3,
.FromPage = 1,
.ToPage = 5,
.PrintRange = PrintRange.SomePages
}
pdf.GetPrintDocument(settings).Print()Imports IronPdf
Imports System.Drawing.Printing
Dim pdf = PdfDocument.FromFile("document.pdf")
Dim settings = New PrinterSettings With {
.PrinterName = "HP LaserJet",
.Copies = 3,
.FromPage = 1,
.ToPage = 5,
.PrintRange = PrintRange.SomePages
}
pdf.GetPrintDocument(settings).Print()Cichy tryb
//PDFFilePrintis always silent — there is no print-dialog code path.
//IronPDF is silent by default. Pass true explicitly to show the print dialog:
pdf.Print(); // silent
pdf.Print(true); // shows print dialog//PDFFilePrintis always silent — there is no print-dialog code path.
//IronPDF is silent by default. Pass true explicitly to show the print dialog:
pdf.Print(); // silent
pdf.Print(true); // shows print dialog'PDFFilePrint is always silent — there is no print-dialog code path.
'IronPDF is silent by default. Pass true explicitly to show the print dialog:
pdf.Print() ' silent
pdf.Print(True) ' shows print dialog'PDFFilePrint is always silent — there is no print-dialog code path.
'IronPDF is silent by default. Pass true explicitly to show the print dialog:
pdf.Print() ' silent
pdf.Print(True) ' shows print dialogNowe możliwości po migracji
Po migracji do IronPDF zyskujesz możliwości, których nie zapewnia PDFFilePrint:
Twórz i drukuj w jednym kroku
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();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();Imports IronPdf
Imports System.Drawing.Printing
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Invoice #12345</h1><p>Thank you for your order.</p>")
Dim settings As New PrinterSettings With {.PrinterName = "Office Printer"}
pdf.GetPrintDocument(settings).Print()Imports IronPdf
Imports System.Drawing.Printing
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Invoice #12345</h1><p>Thank you for your order.</p>")
Dim settings As New PrinterSettings With {.PrinterName = "Office Printer"}
pdf.GetPrintDocument(settings).Print()Łączenie plików PDF
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")Znaki wodne
var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark("<h1 style='color:red; opacity:0.3;'>CONFIDENTIAL</h1>");
pdf.SaveAs("watermarked.pdf");var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark("<h1 style='color:red; opacity:0.3;'>CONFIDENTIAL</h1>");
pdf.SaveAs("watermarked.pdf");Dim pdf = PdfDocument.FromFile("document.pdf")
pdf.ApplyWatermark("<h1 style='color:red; opacity:0.3;'>CONFIDENTIAL</h1>")
pdf.SaveAs("watermarked.pdf")Dim pdf = PdfDocument.FromFile("document.pdf")
pdf.ApplyWatermark("<h1 style='color:red; opacity:0.3;'>CONFIDENTIAL</h1>")
pdf.SaveAs("watermarked.pdf")Ochrona hasłem
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SecuritySettings.UserPassword = "userpassword";
pdf.SecuritySettings.OwnerPassword = "ownerpassword";
pdf.SaveAs("secured.pdf");var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SecuritySettings.UserPassword = "userpassword";
pdf.SecuritySettings.OwnerPassword = "ownerpassword";
pdf.SaveAs("secured.pdf");Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SecuritySettings.UserPassword = "userpassword"
pdf.SecuritySettings.OwnerPassword = "ownerpassword"
pdf.SaveAs("secured.pdf")Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SecuritySettings.UserPassword = "userpassword"
pdf.SecuritySettings.OwnerPassword = "ownerpassword"
pdf.SaveAs("secured.pdf")Wyodrębnianie tekstu
var pdf = PdfDocument.FromFile("document.pdf");
string text = pdf.ExtractAllText();var pdf = PdfDocument.FromFile("document.pdf");
string text = pdf.ExtractAllText();Dim pdf = PdfDocument.FromFile("document.pdf")
Dim text As String = pdf.ExtractAllText()Dim pdf = PdfDocument.FromFile("document.pdf")
Dim text As String = pdf.ExtractAllText()Ważne uwagi dotyczące migracji
Zmiana wzorca klasy
PDFFilePrint używa małej klasy FilePrint z jedną metodą Print(), napędzaną przez app.config.IronPDF oddziela renderowanie, manipulację dokumentem i drukowanie na różne typy:
// 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();
//IronPDF can also create PDFs from HTML —PDFFilePrintcannot
var renderer = new ChromePdfRenderer();
var newPdf = renderer.RenderHtmlAsPdf(html);
newPdf.SaveAs(path);// 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();
//IronPDF can also create PDFs from HTML —PDFFilePrintcannot
var renderer = new ChromePdfRenderer();
var newPdf = renderer.RenderHtmlAsPdf(html);
newPdf.SaveAs(path);' PDFFilePrint: load + silent print (settings come from app.config)
Properties.Settings.[Default].PrinterName = "HP LaserJet"
Dim fileprint = New FilePrint(path, Nothing)
fileprint.Print()
' IronPDF: PdfDocument for load/manipulate, PrinterSettings for print options
Dim pdf = PdfDocument.FromFile(path)
Dim settings = New PrinterSettings With {.PrinterName = "HP LaserJet"}
pdf.GetPrintDocument(settings).Print()
' IronPDF can also create PDFs from HTML — PDFFilePrint cannot
Dim renderer = New ChromePdfRenderer()
Dim newPdf = renderer.RenderHtmlAsPdf(html)
newPdf.SaveAs(path)' PDFFilePrint: load + silent print (settings come from app.config)
Properties.Settings.[Default].PrinterName = "HP LaserJet"
Dim fileprint = New FilePrint(path, Nothing)
fileprint.Print()
' IronPDF: PdfDocument for load/manipulate, PrinterSettings for print options
Dim pdf = PdfDocument.FromFile(path)
Dim settings = New PrinterSettings With {.PrinterName = "HP LaserJet"}
pdf.GetPrintDocument(settings).Print()
' IronPDF can also create PDFs from HTML — PDFFilePrint cannot
Dim renderer = New ChromePdfRenderer()
Dim newPdf = renderer.RenderHtmlAsPdf(html)
newPdf.SaveAs(path)Zmiany nazewnictwa metod/ustawień
//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 = 3 → new PrinterSettings { Copies = 3 }
Properties.Settings.Default.PaperName = "A4" → settings.DefaultPageSettings.PaperSize = ...
//PDFFilePrinthas no native HTML/URL/merge/watermark methods — these are IronPDF-only.//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 = 3 → new PrinterSettings { Copies = 3 }
Properties.Settings.Default.PaperName = "A4" → settings.DefaultPageSettings.PaperSize = ...
//PDFFilePrinthas no native HTML/URL/merge/watermark methods — these are IronPDF-only.'PDFFilePrint→ IronPDF
Dim pdf = PdfDocument.FromFile(path)
pdf.Print() ' silent default
Dim settings As New PrinterSettings With {.PrinterName = "X", .Copies = 3}
settings.DefaultPageSettings.PaperSize = ...
'PDFFilePrinthas no native HTML/URL/merge/watermark methods — these are IronPDF-only.'PDFFilePrint→ IronPDF
Dim pdf = PdfDocument.FromFile(path)
pdf.Print() ' silent default
Dim settings As New PrinterSettings With {.PrinterName = "X", .Copies = 3}
settings.DefaultPageSettings.PaperSize = ...
'PDFFilePrinthas no native HTML/URL/merge/watermark methods — these are IronPDF-only.Obsługa wyjątków
// PDFFilePrint: failures bubble up from PdfiumViewer as plain exceptions
try {
new FilePrint(path, null).Print();
}
catch (Exception ex) {
// Nie granular error type — log the message and inner exception.
}
// IronPDF: typed exception hierarchy
try {
pdf.Print();
}
catch (IronPdf.Exceptions.IronPdfException ex) {
// Granular error details
}// PDFFilePrint: failures bubble up from PdfiumViewer as plain exceptions
try {
new FilePrint(path, null).Print();
}
catch (Exception ex) {
// Nie granular error type — log the message and inner exception.
}
// IronPDF: typed exception hierarchy
try {
pdf.Print();
}
catch (IronPdf.Exceptions.IronPdfException ex) {
// Granular error details
}' PDFFilePrint: failures bubble up from PdfiumViewer as plain exceptions
Try
Call (New FilePrint(path, Nothing)).Print()
Catch ex As Exception
' Nie granular error type — log the message and inner exception.
End Try
' IronPDF: typed exception hierarchy
Try
pdf.Print()
Catch ex As IronPdf.Exceptions.IronPdfException
' Granular error details
End Try' PDFFilePrint: failures bubble up from PdfiumViewer as plain exceptions
Try
Call (New FilePrint(path, Nothing)).Print()
Catch ex As Exception
' Nie granular error type — log the message and inner exception.
End Try
' IronPDF: typed exception hierarchy
Try
pdf.Print()
Catch ex As IronPdf.Exceptions.IronPdfException
' Granular error details
End TryBrak zewnętrznego wykonalnego w żadnym przypadku
Obie biblioteki są dostarczane jako pakiety NuGet. Nie ma PDFFilePrint.exe do paczkowania lub usuwania - dotnet remove package PDFFilePrint jest wystarczające po stronie PDFFilePrint.IronPDF jest podobnie samodzielny dzięki pakietowi IronPdf, z natywnymi zależnościami rozwiązywanymi w czasie przywracania.
Podsumowanie porównania funkcji
| Funkcja | PDFFilePrint | IronPDF |
|---|---|---|
| Podstawowe drukowanie | ✓ | ✓ |
| Ciche drukowanie | ✓ (zawsze cichy) | ✓ |
| Wiele kopii | ✓ (przez app.config) | ✓ |
| Zakres stron | Tylko domyślny sterownik | ✓ |
| Duplex | Tylko domyślny sterownik | ✓ |
| Utwórz z HTML | ✗ | ✓ |
| Utwórz z adresu URL | ✗ | ✓ |
| Łączenie plików PDF | ✗ | ✓ |
| Podział plików PDF | ✗ | ✓ |
| Dodaj znaki wodne | ✗ | ✓ |
| Wyodrębnij tekst | ✗ | ✓ |
| Ochrona hasłem | ✗ | ✓ |
| Podpisy cyfrowe | ✗ | ✓ |
| Wielopłatformowe | ✗ (Windows / net461) | ✓ |
| Natywny interfejs API .NET | ✓ (mała powierzchnia) | ✓ |
Lista kontrolna migracji
Przed migracją
- Zlokalizuj wszystkie miejsca wywołania
using PDFFilePrint;inew FilePrint(...) - Udokumentuj bieżące ustawienia
app.config(PrinterName,PaperName,Copies,PrintToFile,DefaultPrintToDirectory) - Zidentyfikuj nazwy drukarek używane w różnych środowiskach
- Zauważ dowolny kod, który mutuje
Properties.Settings.Defaultw czasie działania - Zidentyfikuj możliwości dla nowych funkcji (renderowanie HTML/URL, łączenie, znaki wodne, zabezpieczenia)
- Uzyskaj klucz licencyjny IronPDF
Zmiany w pakiecie
- Usuń pakiet NuGet
PDFFilePrint:dotnet remove package PDFFilePrint - Zainstaluj pakiet NuGet
IronPdf:dotnet add package IronPdf - Zastąp
using PDFFilePrint;za pomocąusing IronPdf;(dodajusing System.Drawing.Printing;tam, gdzie to potrzebne)
Zmiany w kodzie
- Dodaj konfigurację klucza licencyjnego podczas uruchamiania
- Zastąp
new FilePrint(path, null)za pomocąPdfDocument.FromFile(path) - Przenieś ustawienia drukarki/liczby kopii/papieru poza
app.configi doSystem.Drawing.Printing.PrinterSettings - Użyj
pdf.Print()do niezauważalnego wyjścia na domyślną drukarkę lubpdf.GetPrintDocument(settings).Print()dla jawnych opcji - Opakuj wywołania
Print()wtry/catch IronPdfExceptiontam, gdzie wcześniej łapałeś ogólne wyjątki - Dla funkcji HTML/URL/merge/watermark (którychPDFFilePrintnigdy nie oferował), użyj
ChromePdfRendereri API manipulacjiPdfDocument
Po migracji
- Usuń specyficzne kluczePDFFilePrintz
app.config - Wykonaj wydruk testowy na wszystkich docelowych drukarkach
- Przetestuj międzyplatformowe działanie, jeśli to możliwe (drukowanie w Linuksie wymaga CUPS)
- Dodaj nowe funkcje (znaki wodne, bezpieczeństwo, scalanie) w razie potrzeby
- Aktualizacja dokumentacji
Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podręczników.
Powiązane artykuły


