Jak przejść z PDFFilePrint na IronPDF w języku C#
Przejście z PDFFilePrint naIronPDFprzenosi proces obsługi plików PDF w środowisku .NET z narzędzia skupionego na drukowaniu o ograniczonych możliwościach do kompleksowej biblioteki PDF, która obsługuje tworzenie, edycję i drukowanie w ramach jednego, ujednoliconego interfejsu API. Niniejszy przewodnik zawiera kompletną, szczegółową ścieżkę migracji, która eliminuje zależności od wiersza poleceń, dodając jednocześnie funkcje generowania i edycji plików PDF, których nie zapewnia PDFFilePrint.
Dlaczego warto przejść z PDFFilePrint na IronPDF
Zrozumienie PDFFilePrint
PDFFilePrint to praktyczne narzędzie zaprojektowane specjalnie do drukowania plików PDF z aplikacji napisanych w języku C#. Chociaż dobrze sprawdza się w przypadku docelowych zadań drukowania plików PDF, jego funkcjonalność ogranicza się do jednego aspektu obsługi dokumentów. Głównym atutem PDFFilePrint jest jego prostota — skupienie się wyłącznie na zapewnieniu możliwości drukowania plików PDF. Jednak to wąskie ukierunkowanie stwarza znaczne ograniczenia dla kompleksowych systemów zarządzania dokumentami.
Istotne ograniczenia PDFFilePrint
-
Skupienie wyłącznie na drukowaniu: Funkcjonalność PDFFilePrint ogranicza się do drukowania. Brakuje w nim funkcji tworzenia lub modyfikowania plików PDF, co ogranicza jego zastosowanie w bardziej kompleksowych systemach zarządzania dokumentami.
-
Zależność od wiersza poleceń: Często opierając się na operacjach wiersza poleceń z wywołaniami
Process.Start(), PDFFilePrint może nie spełniać wymagań dotyczących płynnej integracji z aplikacjami, które wymagają bardziej rozbudowanych interfejsów API. -
Tylko dla systemu Windows: Ponieważ opiera się w dużym stopniu na systemach drukowania Windows, może nie być najlepszym wyborem dla środowisk korzystających z innych systemów operacyjnych.
-
Brak integracji z .NET: brak natywnego API, brak pakietu NuGet oraz brak obsługi IntelliSense w niektórych scenariuszach użytkowania.
-
Zarządzanie procesami zewnętrznymi: Musi obsługiwać cykl życia procesów, kody wyjścia oraz analizę błędów ze stdout/stderr.
-
Ograniczona obsługa błędów: Wykrywanie błędów wymaga analizowania standardowego strumienia wyjściowego i strumienia błędów, a nie natywnych wyjątków.
-
Złożoność wdrożenia: W scenariuszach użytkowania z wiersza poleceń należy dołączyć plik PDFFilePrint.exe do aplikacji.
- Brak generowania plików PDF: Nie można tworzyć plików PDF — w trybie wiersza poleceń można jedynie drukować istniejące pliki.
Porównanie PDFFilePrint i IronPDF
| Aspekt | PDFFilePrint | IronPDF |
|---|---|---|
| Główny cel | Drukowanie plików PDF | Kompleksowe API PDF |
| Typ | Narzędzie wiersza poleceń / Biblioteka podstawowa | Natywna biblioteka .NET |
| Integracja | Process.Start() / Podstawowe API | Bezpośrednie wywołania API |
| Drukowanie plików PDF | ✓ | ✓ |
| Tworzenie plików PDF | Ograniczone | ✓(HTML, URL, obrazy) |
| Manipulacja plikami PDF | ✗ | ✓(scal, podziel, edytuj) |
| Wieloplatformowe | Tylko dla systemu Windows | Windows, Linux, macOS |
| Obsługa błędów | Analiza stdout/stderr | Wyjątki natywne |
| IntelliSense | Ograniczone | Obsługiwane |
| Pakiet NuGet | Ograniczone | ✓ |
| Dokumentacja | Podstawowe | Obszerne |
Dla zespołów planujących wdrożenie .NET 10 i C# 14 w latach 2025 i 2026,IronPDFzapewnia kompleksową platformę z obsługą wielu platform i aktywnym rozwojem, rozwiązując ograniczenia architektury PDFFilePrint.
Zanim zaczniesz
Wymagania wstępne
- Środowisko .NET: .NET Framework 4.6.2+ lub .NET Core 3.1+ / .NET 5/6/7/8/9+
- Dostęp do NuGet: Możliwość instalowania pakietów NuGet
- Licencja IronPDF: Uzyskaj klucz licencyjny na stronie ironpdf.com
Zmiany w pakiecie NuGet
# Remove PDFFilePrint package (if installed via NuGet)
dotnet remove package PDFFilePrint
# If using command-line PDFFilePrint.exe, remove from deployment
# Delete bundled PDFFilePrint.exe from your project
# Install IronPDF
dotnet add package IronPdf
# Remove PDFFilePrint package (if installed via NuGet)
dotnet remove package PDFFilePrint
# If using command-line PDFFilePrint.exe, remove from deployment
# Delete bundled PDFFilePrint.exe from your project
# 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.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"
Zidentyfikuj użycie PDFFilePrint
# Find PDFFilePrint references
grep -r "PDFFilePrint\|PDFFile\|CreateFromHtml\|CreateFromUrl" --include="*.cs" .
# Find command-line execution patterns
grep -r "ProcessStartInfo.*pdf\|Process.Start.*print" --include="*.cs" .
# Find batch scripts
find . -name "*.bat" -o -name "*.cmd" | xargs grep -l "PDFFilePrint"
# Find PDFFilePrint references
grep -r "PDFFilePrint\|PDFFile\|CreateFromHtml\|CreateFromUrl" --include="*.cs" .
# Find command-line execution patterns
grep -r "ProcessStartInfo.*pdf\|Process.Start.*print" --include="*.cs" .
# Find batch scripts
find . -name "*.bat" -o -name "*.cmd" | xargs grep -l "PDFFilePrint"
Kompletna dokumentacija API
Zmiany w przestrzeni nazw
// PDFFilePrint
using PDFFilePrint;
using System.Diagnostics; // For command-line usage
// IronPDF
using IronPdf;
using IronPdf.Printing;
// PDFFilePrint
using PDFFilePrint;
using System.Diagnostics; // For command-line usage
// IronPDF
using IronPdf;
using IronPdf.Printing;
Imports PDFFilePrint
Imports System.Diagnostics ' For command-line usage
' IronPDF
Imports IronPdf
Imports IronPdf.Printing
Mapowania klas podstawowych
| PDFFilePrint | IronPDF |
|---|---|
new PDFFile() |
new ChromePdfRenderer() |
new PDFFile() |
PdfDocument.FromFile() |
PDFFile |
PdfDocument |
Mapowania metod generowania plików PDF
| PDFFilePrint | IronPDF |
|---|---|
pdf.CreateFromHtml(html) |
renderer.RenderHtmlAsPdf(html) |
pdf.CreateFromUrl(url) |
renderer.RenderUrlAsPdf(url) |
pdf.SaveToFile(path) |
pdf.SaveAs(path) |
Mapowania ładowania i drukowania plików PDF
| PDFFilePrint | IronPDF |
|---|---|
pdf.LoadFromFile(path) |
PdfDocument.FromFile(path) |
pdf.Print(printerName) |
pdf.Print(printerName) |
pdf.Print("Default Printer") |
pdf.Print() |
Mapowanie ustawień drukowania (z wiersza poleceń do API)
| PDFFilePrint Flag | WłaściwośćIronPDFPrintSettings |
|---|---|
-printer "Name" |
PrinterName |
-copies N |
NumberOfCopies |
-silent |
ShowPrintDialog = false |
-pages "1-5" |
FromPage, ToPage |
-orientation landscape |
PaperOrientation |
-duplex |
Duplex |
-collate |
Collate |
Nowe funkcje niedostępne w PDFFilePrint
| FunkcjaIronPDF | 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
using System;
using PDFFilePrint;
class Program
{
static void Main()
{
var pdf = new PDFFile();
string htmlContent = "<html><body><h1>Hello World</h1></body></html>";
pdf.CreateFromHtml(htmlContent);
pdf.SaveToFile("output.pdf");
}
}
// NuGet: Install-Package PDFFilePrint
using System;
using PDFFilePrint;
class Program
{
static void Main()
{
var pdf = new PDFFile();
string htmlContent = "<html><body><h1>Hello World</h1></body></html>";
pdf.CreateFromHtml(htmlContent);
pdf.SaveToFile("output.pdf");
}
}
Imports System
Imports PDFFilePrint
Module Program
Sub Main()
Dim pdf As New PDFFile()
Dim htmlContent As String = "<html><body><h1>Hello World</h1></body></html>"
pdf.CreateFromHtml(htmlContent)
pdf.SaveToFile("output.pdf")
End Sub
End Module
Po (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 Class
Podstawową różnicą jest tutaj wzorzec API. PDFFilePrint wykorzystuje pojedynczą klasę PDFFile z metodami CreateFromHtml() i SaveToFile().IronPDFoddziela renderowanie od obiektu dokumentu — ChromePdfRenderer obsługuje konwersję HTML do PDF i zwraca obiekt PdfDocument, który następnie zapisujesz za pomocą SaveAs().
To rozdzielenie zapewnia znaczące korzyści: przed konwersją można skonfigurować opcje renderowania w rendererze, a zwrócony plik PdfDocument można modyfikować (dodawać znaki wodne, łączyć z innymi plikami PDF, dodawać zabezpieczenia) 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
using System;
using PDFFilePrint;
class Program
{
static void Main()
{
var pdf = new PDFFile();
pdf.CreateFromUrl("https://www.example.com");
pdf.SaveToFile("webpage.pdf");
}
}
// NuGet: Install-Package PDFFilePrint
using System;
using PDFFilePrint;
class Program
{
static void Main()
{
var pdf = new PDFFile();
pdf.CreateFromUrl("https://www.example.com");
pdf.SaveToFile("webpage.pdf");
}
}
Imports System
Imports PDFFilePrint
Class Program
Shared Sub Main()
Dim pdf As New PDFFile()
pdf.CreateFromUrl("https://www.example.com")
pdf.SaveToFile("webpage.pdf")
End Sub
End Class
Po (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 Class
PDFFilePrint używa CreateFromUrl() w tej samej klasie PDFFile.IronPDFwykorzystuje dedykowaną metodę RenderUrlAsPdf() w ChromePdfRenderer, która wykorzystuje nowoczesny silnik Chromium do dokładnego renderowania złożonych elementów CSS3, JavaScript oraz nowoczesnych funkcji internetowych. Jakość renderowania jest przewidywalna i odpowiada temu, co widać w przeglądarce Chrome. 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()
{
var pdf = new PDFFile();
pdf.LoadFromFile("document.pdf");
pdf.Print("Default Printer");
Console.WriteLine("PDF sent to printer");
}
}
// NuGet: Install-Package PDFFilePrint
using System;
using PDFFilePrint;
class Program
{
static void Main()
{
var pdf = new PDFFile();
pdf.LoadFromFile("document.pdf");
pdf.Print("Default Printer");
Console.WriteLine("PDF sent to printer");
}
}
Imports System
Imports PDFFilePrint
Module Program
Sub Main()
Dim pdf As New PDFFile()
pdf.LoadFromFile("document.pdf")
pdf.Print("Default Printer")
Console.WriteLine("PDF sent to printer")
End Sub
End Module
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
pdf.Print();
Console.WriteLine("PDF sent to printer");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
pdf.Print();
Console.WriteLine("PDF sent to printer");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("document.pdf")
pdf.Print()
Console.WriteLine("PDF sent to printer")
End Sub
End Class
Ten przykład pokazuje fundamentalną różnicę architektoniczną w ładowaniu i drukowaniu plików PDF. PDFFilePrint używa new PDFFile(), po którym następuje LoadFromFile(), a następnie Print(printerName).IronPDFużywa statycznej metody fabrycznej PdfDocument.FromFile() do bezpośredniego ładowania, a następnie Print(), która korzysta z domyślnej drukarki (można też podać nazwę drukarki).
Najważniejsze zmiany związane z migracją:
new PDFFile()+LoadFromFile(path)→PdfDocument.FromFile(path)Print("Default Printer")→Print()(domyślna drukarka jest ustawiona automatycznie)
W przypadku zaawansowanych ustawień drukowaniaIronPDFudostępnia klasę PrintSettings. Aby zapoznać się z opcjami zaawansowanymi, zobacz dokumentację dotyczącą drukowania.
Migracja zaawansowanych ustawień drukowania
W przypadku aplikacji korzystających z flag wiersza poleceń PDFFilePrint, oto jak przeprowadzić migrację doIronPDFPrintSettings:
// PDFFilePrint command-line approach:
// PDFFilePrint.exe -silent -copies 3 -printer "HP LaserJet" -pages "1-5" "document.pdf"
//IronPDFequivalent:
using IronPdf;
var pdf = PdfDocument.FromFile("document.pdf");
var settings = new PrintSettings
{
ShowPrintDialog = false, // -silent
NumberOfCopies = 3, // -copies 3
PrinterName = "HP LaserJet", // -printer "HP LaserJet"
FromPage = 1, // -pages "1-5"
ToPage = 5
};
pdf.Print(settings);
// PDFFilePrint command-line approach:
// PDFFilePrint.exe -silent -copies 3 -printer "HP LaserJet" -pages "1-5" "document.pdf"
//IronPDFequivalent:
using IronPdf;
var pdf = PdfDocument.FromFile("document.pdf");
var settings = new PrintSettings
{
ShowPrintDialog = false, // -silent
NumberOfCopies = 3, // -copies 3
PrinterName = "HP LaserJet", // -printer "HP LaserJet"
FromPage = 1, // -pages "1-5"
ToPage = 5
};
pdf.Print(settings);
Imports IronPdf
Dim pdf = PdfDocument.FromFile("document.pdf")
Dim settings As New PrintSettings With {
.ShowPrintDialog = False, ' -silent
.NumberOfCopies = 3, ' -copies 3
.PrinterName = "HP LaserJet", ' -printer "HP LaserJet"
.FromPage = 1, ' -pages "1-5"
.ToPage = 5
}
pdf.Print(settings)
Konwersja flagi trybu cichego
Zwróć uwagę na odwróconą logikę cichego drukowania:
// PDFFilePrint: -silent flag enables silent mode
// IronPDF: ShowPrintDialog = false (false = silent)
var settings = new PrintSettings { ShowPrintDialog = false };
// PDFFilePrint: -silent flag enables silent mode
// IronPDF: ShowPrintDialog = false (false = silent)
var settings = new PrintSettings { ShowPrintDialog = false };
' PDFFilePrint: -silent flag enables silent mode
' IronPDF: ShowPrintDialog = false (false = silent)
Dim settings As New PrintSettings With {.ShowPrintDialog = False}
Nowe możliwości po migracji
Po migracji doIronPDFzyskujesz możliwości, których nie zapewnia PDFFilePrint:
Twórz i drukuj w jednym kroku
using IronPdf;
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Invoice #12345</h1><p>Thank you for your order.</p>");
pdf.Print("Office Printer");
using IronPdf;
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Invoice #12345</h1><p>Thank you for your order.</p>");
pdf.Print("Office Printer");
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Invoice #12345</h1><p>Thank you for your order.</p>")
pdf.Print("Office Printer")
Łą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")
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")
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")
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()
Ważne uwagi dotyczące migracji
Zmiana wzorca klasy
PDFFilePrint wykorzystuje jedną klasę PDFFile do wszystkiego;IronPDFrozdziela obszary odpowiedzialności:
// PDFFilePrint: Single class
var pdf = new PDFFile();
pdf.CreateFromHtml(html);
pdf.SaveToFile(path);
// IronPDF: Renderer for creation, Document for manipulation
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs(path);
// PDFFilePrint: Single class
var pdf = new PDFFile();
pdf.CreateFromHtml(html);
pdf.SaveToFile(path);
// IronPDF: Renderer for creation, Document for manipulation
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs(path);
' PDFFilePrint: Single class
Dim pdf1 = New PDFFile()
pdf1.CreateFromHtml(html)
pdf1.SaveToFile(path)
' IronPDF: Renderer for creation, Document for manipulation
Dim renderer = New ChromePdfRenderer()
Dim pdf2 = renderer.RenderHtmlAsPdf(html)
pdf2.SaveAs(path)
Zmiany w nazewnictwie metod
// PDFFilePrint → IronPDF
CreateFromHtml() → RenderHtmlAsPdf()
CreateFromUrl() → RenderUrlAsPdf()
LoadFromFile() → PdfDocument.FromFile()
SaveToFile() → SaveAs()
Print(printerName) → Print(printerName) or Print()
// PDFFilePrint → IronPDF
CreateFromHtml() → RenderHtmlAsPdf()
CreateFromUrl() → RenderUrlAsPdf()
LoadFromFile() → PdfDocument.FromFile()
SaveToFile() → SaveAs()
Print(printerName) → Print(printerName) or Print()
' PDFFilePrint → IronPDF
' CreateFromHtml() → RenderHtmlAsPdf()
' CreateFromUrl() → RenderUrlAsPdf()
' LoadFromFile() → PdfDocument.FromFile()
' SaveToFile() → SaveAs()
' Print(printerName) → Print(printerName) or Print()
Kod wyjścia do obsługi wyjątków
W przypadku korzystania z polecenia PDFFilePrint w wierszu poleceń:
// PDFFilePrint: Check process exit code
if (process.ExitCode != 0) {
var error = process.StandardError.ReadToEnd();
throw new Exception($"Print failed: {error}");
}
// IronPDF: Use try-catch
try {
pdf.Print();
}
catch (Exception ex) {
// Handle error with full exception details
}
// PDFFilePrint: Check process exit code
if (process.ExitCode != 0) {
var error = process.StandardError.ReadToEnd();
throw new Exception($"Print failed: {error}");
}
// IronPDF: Use try-catch
try {
pdf.Print();
}
catch (Exception ex) {
// Handle error with full exception details
}
' PDFFilePrint: Check process exit code
If process.ExitCode <> 0 Then
Dim error = process.StandardError.ReadToEnd()
Throw New Exception($"Print failed: {error}")
End If
' IronPDF: Use try-catch
Try
pdf.Print()
Catch ex As Exception
' Handle error with full exception details
End Try
Usuń zależności zewnętrzne
W przypadku korzystania z programu PDFFilePrint z wiersza poleceń należy usunąć dołączony plik wykonywalny:
// Before: Required external executable
private readonly string _pdfFilePrintPath = @"C:\tools\PDFFilePrint.exe";
// After: No external dependencies
//IronPDFis fully self-contained via NuGet
// Before: Required external executable
private readonly string _pdfFilePrintPath = @"C:\tools\PDFFilePrint.exe";
// After: No external dependencies
//IronPDFis fully self-contained via NuGet
' Before: Required external executable
Private ReadOnly _pdfFilePrintPath As String = "C:\tools\PDFFilePrint.exe"
' After: No external dependencies
'IronPDF is fully self-contained via NuGet
Podsumowanie porównania funkcji
| Funkcja | PDFFilePrint | IronPDF |
|---|---|---|
| Podstawowe drukowanie | ✓ | ✓ |
| Ciche drukowanie | ✓ | ✓ |
| Wiele kopii | ✓ | ✓ |
| Zakres stron | ✓ | ✓ |
| Duplex | Różne | ✓ |
| Utwórz z HTML | Ograniczone | ✓ |
| Utwórz z adresu URL | Ograniczone | ✓ |
| Łączenie plików PDF | ✗ | ✓ |
| Podział plików PDF | ✗ | ✓ |
| Dodaj znaki wodne | ✗ | ✓ |
| Wyodrębnij tekst | ✗ | ✓ |
| Ochrona hasłem | ✗ | ✓ |
| Podpisy cyfrowe | ✗ | ✓ |
| Wieloplatformowe | ✗ | ✓ |
| Natywny interfejs API .NET | Ograniczone | ✓ |
Lista kontrolna migracji
Przed migracją
- Znajdź wszystkie odniesienia do PDFFilePrint w kodzie źródłowym
- Opisz aktualnie stosowane metody (CreateFromHtml, CreateFromUrl, PRINT itp.)
- Zidentyfikuj nazwy drukarek używane w różnych środowiskach
- Wymień wszystkie argumenty wiersza poleceń, jeśli używasz wzorca Process.Start
- Zidentyfikuj możliwości wprowadzenia nowych funkcji (łączenie, znaki wodne, bezpieczeństwo)
- Uzyskaj klucz licencyjny IronPDF
Zmiany w pakiecie
- Usuń pakiet NuGet
PDFFilePrint - Usuń dołączony plik PDFFilePrint.exe z wdrożenia (jeśli dotyczy)
- Zainstaluj pakiet NuGet
IronPdf:dotnet add package IronPdf - Zaktualizuj importy przestrzeni nazw
Zmiany w kodzie
- Dodaj konfigurację klucza licencyjnego podczas uruchamiania
- Zastąp
new PDFFile()+CreateFromHtml()przezChromePdfRenderer.RenderHtmlAsPdf() - Zastąp
new PDFFile()+CreateFromUrl()przezChromePdfRenderer.RenderUrlAsPdf() - Zastąp
LoadFromFile()przezPdfDocument.FromFile() - Zastąp
SaveToFile()przezSaveAs() - W razie potrzeby zaktualizuj wywołania
Print() - Zastąp sprawdzanie kodów wyjścia obsługą wyjątków (jeśli ma to zastosowanie)
Po migracji
- Usuń plik PDFFilePrint.exe z kontroli wersji
- Zaktualizuj skrypty kompilacji, aby usunąć kopiowanie PDFFilePrint
- Wykonaj wydruk testowy na wszystkich docelowych drukarkach
- W razie potrzeby przeprowadź testy na różnych platformach
- W razie potrzeby dodaj nowe funkcje (znaki wodne, zabezpieczenia)
- Aktualizacja dokumentacji

