Przejdź do treści stopki
PRZEWODNIKI MIGRACJI

Jak przeprowadzić migrację z Pdfium do IronPDF w języku C#

Migracja z wrappera PDFium .NET do IronPDF przenosi twój przepływ pracy PDF .NET z silnika skupiającego się na renderowaniu z natywnymi zależnościami binarnymi do kompleksowego rozwiązania PDF, które obsługuje tworzenie, manipulację i renderowanie bez złożoności specyficznej dla platformy. Ten przewodnik dostarcza ścieżkę migracji krok po kroku, która eliminuje zarządzanie natywnymi zależnościami, a jednocześnie dodaje możliwości, których sam PDFium nie oferuje.

Dlaczego migrować z wrappera PDFium do IronPDF

Rozumienie wrappów PDFium .NET

PDFium to silnik renderowania i analizy PDF Google'a BSD-3-Clause C++ — ten sam silnik, który zasila wbudowaną przeglądarkę PDF Chrome'a. Nie ma oficjalnego wiązania .NET dostarczonego przez Google; zamiast tego, ekosystem .NET korzysta z PDFium przez wrappery społecznościowe. Cztery najczęściej cytowane pakiety NuGet to PdfiumViewer (pvginkel; Apache 2.0; zarchiwizowany w sierpniu 2019, ostatnie wydanie 2.13.0 w listopadzie 2017, .NET Framework 2.0+), PdfiumViewer.Updated (utrzymane rozwidlenie przeniesione na .NET Core / .NET 6), PDFiumCore (Dtronix; .NET Standard 2.1 P/Invoke bindings), and Pdfium.Net.SDK (Patagames; komercyjne, licencja wieczysta SDK).

Ich API różnią się, ale mają jedną cechę wspólną: Sam PDFium jest silnikiem renderowania i analizy, a nie silnikiem do tworzenia HTML-to-PDF ani do tworzenia dokumentów. PDFium nie ma parsera HTML, więc żaden wrapper nie może samodzielnie konwertować HTML na PDF. Ten przewodnik wykorzystuje PdfiumViewer jako reprezentatywną warstwę dla fragmentów 'przed', ponieważ jego API jest najczęściej cytowane; podejście migracyjne jest takie samo dla każdego z czterech.

Krytyczne ograniczenia wrappów PDFium

  1. Renderowanie-Pierwsze: PDFium nie ma parsera HTML, więc żaden wrapper nie może tworzyć PDF-ów z HTML, URL-i ani dowolnych obrazów.

  2. Ograniczona manipulacja we wrappach open-source:PdfiumViewer/PDFiumCore eksponują oglądanie i ekstrakcję tekstu na stronę; łączenie / dzielenie / edycja formularzy jest częściowe w Patagames Pdfium.Net.SDK i w dużej mierze nieobecne we free wrappach.

  3. Natywne zależności binarne: Wymaga specyficznych dla platformy binariów PDFium (pdfium.dll / .so / .dylib) dla każdego RID.

  4. Złożoność wdrożenia: Musi zbierać i zarządzać natywnymi binariami dla każdej platformy z folderami x86, x64 i runtime.

  5. Podstawowe wydobycie tekstu:PdfiumViewerudostępnia surowy tekst per strona za pomocą GetPdfText(int); metadane układu / formatu nie są eksponowane.

  6. Brak HTML do PDF: PDFium nie ma parsera HTML; treść webowa nie może być konwertowana bezpośrednio.

  7. Brak wbudowanych nagłówków/stopek: Brak wysokopoziomowego API nakładek na stronie.

  8. Brak wbudowanych znaków wodnych: Brak prymitywu stemplem.

  9. Formularze: Tylko do odczytu lub nieobecne we free wrappach; dostępne w Patagames Pdfium.Net.SDK.

  10. Bezpieczeństwo: Szyfrowanie / uprawnienia nie są eksponowane przez free warppery; dostępne w Patagames Pdfium.Net.SDK.

Porównanie wrappów PDFium i IronPDF

Aspekt Wrappy .NET PDFium IronPDF
Główny cel Renderowanie/wyświetlanie Kompletne rozwiązanie PDF
Wierność odwzorowania Wysokiej jakości renderowanie Wysoki, zwłaszcza w przypadku HTML/CSS/JS
Tworzenie PDF z HTML None Tak (HTML, URL, obrazy)
Manipulacja plikami PDF Darmowe wrappery: brak; Patagames: częściowo Tak (łączenie, dzielenie, edytowanie)
HTML do PDF None Tak (silnik Chromium)
Znaki wodne Nie wbudowane Tak
Nagłówki/stopki Nie wbudowane Tak
Wypełnianie formularzy Darmowe wrappery: brak; Patagames: tak Tak
Bezpieczeństwo Darmowe wrappery: brak; Patagames: tak Tak
Zależności natywne Wymagane Pakiety/Dostępne z zarządzania NuGet
Wielopłatformowe Ręczne zarządzanie natywnymi binariami Automatyczne
Łatwość wdrożenia Skomplikowane przez zależności natywne Łatwiejsze; mniejsze skomplikowanie zależności

Dla zespołów, które chcą celować w nowoczesne .NET,IronPDF dostarcza w pełni zarządzaną podstawę, która eliminuje zarządzanie natywnymi binariami, jednocześnie dodając kompleksowe możliwości tworzenia i manipulacji PDF-ami.


Zanim zaczniesz

Wymagania wstępne

  1. Środowisko .NET: .NET Framework 4.6.2+ lub .NET Core 3.1+ / .NET 5/6/7/8/9+
  2. Dostęp do NuGet: Możliwość instalowania pakietów NuGet
  3. Licencja IronPDF: Uzyskaj klucz licencyjny na stronie ironpdf.com

Zmiany w pakiecie NuGet

# Remove whichever PDFium wrapper you used:
#  PdfiumViewer           (Apache 2.0 - archived 2019, .NET Framework only)
#   PdfiumViewer.Updated    (community fork, .NET Core / .NET 6)
#   PDFiumCore              (Dtronix - .NET Standard 2.1 P/Invoke bindings)
#   Pdfium.Net.SDK          (Patagames - commercial, perpetual license)
dotnet remove package PdfiumViewer
dotnet remove package PdfiumViewer.Updated
dotnet remove package PDFiumCore
dotnet remove package Pdfium.Net.SDK

# Install IronPDF
dotnet add package IronPdf
# Remove whichever PDFium wrapper you used:
#  PdfiumViewer           (Apache 2.0 - archived 2019, .NET Framework only)
#   PdfiumViewer.Updated    (community fork, .NET Core / .NET 6)
#   PDFiumCore              (Dtronix - .NET Standard 2.1 P/Invoke bindings)
#   Pdfium.Net.SDK          (Patagames - commercial, perpetual license)
dotnet remove package PdfiumViewer
dotnet remove package PdfiumViewer.Updated
dotnet remove package PDFiumCore
dotnet remove package Pdfium.Net.SDK

# Install IronPDF
dotnet add package IronPdf
SHELL

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"
$vbLabelText   $csharpLabel

Identyfikacja użycia wrappów PDFium

# Find PDFium wrapper usage
grep -rE "PdfiumViewer|PDFiumCore|Patagames\.Pdf|PdfDocument\.Load|\.Render\(" --include="*.cs" .

# Find native binary references
grep -rE "pdfium\.dll|libpdfium\.(so|dylib)" --include="*.csproj" --include="*.config" .

# Find platform-specific code
grep -rE "#if.*64|WIN32|WIN64|LINUX|OSX" --include="*.cs" .
# Find PDFium wrapper usage
grep -rE "PdfiumViewer|PDFiumCore|Patagames\.Pdf|PdfDocument\.Load|\.Render\(" --include="*.cs" .

# Find native binary references
grep -rE "pdfium\.dll|libpdfium\.(so|dylib)" --include="*.csproj" --include="*.config" .

# Find platform-specific code
grep -rE "#if.*64|WIN32|WIN64|LINUX|OSX" --include="*.cs" .
SHELL

Kompletna dokumentacija API

Zmiany w przestrzeni nazw

// PDFium wrappers (use the one you installed)
using PdfiumViewer;             //PdfiumViewer/PdfiumViewer.Updated
using PDFiumCore;               // Dtronix PDFiumCore (P/Invoke bindings)
using Patagames.Pdf;            // Patagames Pdfium.Net.SDK
using Patagames.Pdf.Net;        // Patagames Pdfium.Net.SDK

// IronPDF
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
// PDFium wrappers (use the one you installed)
using PdfiumViewer;             //PdfiumViewer/PdfiumViewer.Updated
using PDFiumCore;               // Dtronix PDFiumCore (P/Invoke bindings)
using Patagames.Pdf;            // Patagames Pdfium.Net.SDK
using Patagames.Pdf.Net;        // Patagames Pdfium.Net.SDK

// IronPDF
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;
Imports PdfiumViewer 'PdfiumViewer/PdfiumViewer.Updated
Imports PDFiumCore ' Dtronix PDFiumCore (P/Invoke bindings)
Imports Patagames.Pdf ' Patagames Pdfium.Net.SDK
Imports Patagames.Pdf.Net ' Patagames Pdfium.Net.SDK

Imports IronPdf
Imports IronPdf.Rendering
Imports IronPdf.Editing
$vbLabelText   $csharpLabel

Mapowania klas podstawowych

PdfiumViewer IronPDF Uwagi
PdfiumViewer.PdfDocument IronPdf.PdfDocument Ta sama prosta nazwa w różnych przestrzeniach nazw
PdfRenderer (kontrola WinForms) (nie dotyczy) PdfiumViewerrównież dostarcza kontrolkę UI;IronPDF działa bez głowy
(niedostępne) ChromePdfRenderer HTML / URL → PDF
(niedostępne) HtmlHeaderFooter Nagłówki/stopki

Mapowania ładowania dokumentów

PdfiumViewer IronPDF Uwagi
PdfDocument.Load(path) PdfDocument.FromFile(path) Wczytaj z pliku
PdfDocument.Load(stream) PdfDocument.FromStream(stream) Wczytaj ze strumienia
(opakuj bajty w MemoryStream) PdfDocument.FromBinaryData(bytes) Wczytaj z bajtów

Mapowanie właściwości dokumentu

PdfiumViewer IronPDF Uwagi
document.PageCount document.PageCount Taki sam
document.PageSizes (IList<SizeF>) document.Pages[index].Width / Height PdfiumViewereksponuje rozmiary; pages are not first-class objects
document.PageSizes[i].Width document.Pages[i].Width Szerokość na stronę w punktach

Mapowania ekstrakcji tekstu

PdfiumViewer IronPDF Uwagi
document.GetPdfText(pageIndex) document.Pages[index].Text Na stronę
(pętla ręczna) document.ExtractAllText() Wszystkie strony

Zapisywanie mapowań dokumentów

PdfiumViewer IronPDF Uwagi
document.Save(stream) document.SaveAs(path) PdfiumViewerpobiera strumień;IronPDF pobiera ścieżkę
(niedostępne) document.Stream Dostęp do surowego strumienia
(niedostępne) document.BinaryData Pobierz bajty

Mapowania renderowania stron

PdfiumViewer IronPDF Uwagi
document.Render(page, width, height, dpiX, dpiY, flags) pdf.RasterizeToImageFiles(path, DPI) Rasteryzuj
Pętla ręczna przez document.Render(i, ...) pdf.RasterizeToImageFiles("page_*.png") Renderowanie w partii w poprzek wszystkich stron
Ręczne obliczenia skali matematycznej DPI = 72 * scale Przeliczenie skali na DPI

Nowe funkcje niedostępne w wrappach PDFium

Funkcja IronPDF Opis
ChromePdfRenderer.RenderHtmlAsPdf() Utwórz z HTML
ChromePdfRenderer.RenderUrlAsPdf() Utwórz z adresu URL
ChromePdfRenderer.RenderHtmlFileAsPdf() Utwórz z pliku HTML
PdfDocument.Merge() Łączenie plików PDF
pdf.CopyPages() Wyodrębnij strony
pdf.RemovePages() Usuń strony
pdf.InsertPdf() Wstaw plik PDF w miejscu
pdf.ApplyWatermark() Dodaj znaki wodne
pdf.AddHtmlHeaders() Dodaj nagłówki
pdf.AddHtmlFooters() Dodaj stopki
pdf.SecuritySettings Ochrona hasłem
pdf.SignWithDigitalSignature() Podpisy cyfrowe
pdf.Form Wypełnianie formularzy

Przykłady migracji kodu

Przykład 1: Pobieranie tekstu z pliku PDF

Przed (PdfiumViewer):

// NuGet: Install-PackagePdfiumViewer (Apache 2.0; archived Aug 2019, .NET Framework 2.0+)
//        or Install-Package PdfiumViewer.Updated  (maintained fork, .NET Core / .NET 6)
//        or Install-Package PDFiumCore             (Dtronix, .NET Standard 2.1 P/Invoke)
//        or Install-Package Pdfium.Net.SDK         (Patagames, commercial perpetual license)
using PdfiumViewer;
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        using (var document = PdfDocument.Load(pdfPath))
        {
            StringBuilder text = new StringBuilder();

            for (int i = 0; i < document.PageCount; i++)
            {
                // PdfiumViewer's text extraction is per-page raw text via GetPdfText(int).
                // No layout / format metadata is exposed.
                string pageText = document.GetPdfText(i);
                text.AppendLine(pageText);
            }

            Console.WriteLine(text.ToString());
        }
    }
}
// NuGet: Install-PackagePdfiumViewer (Apache 2.0; archived Aug 2019, .NET Framework 2.0+)
//        or Install-Package PdfiumViewer.Updated  (maintained fork, .NET Core / .NET 6)
//        or Install-Package PDFiumCore             (Dtronix, .NET Standard 2.1 P/Invoke)
//        or Install-Package Pdfium.Net.SDK         (Patagames, commercial perpetual license)
using PdfiumViewer;
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main()
    {
        string pdfPath = "document.pdf";

        using (var document = PdfDocument.Load(pdfPath))
        {
            StringBuilder text = new StringBuilder();

            for (int i = 0; i < document.PageCount; i++)
            {
                // PdfiumViewer's text extraction is per-page raw text via GetPdfText(int).
                // No layout / format metadata is exposed.
                string pageText = document.GetPdfText(i);
                text.AppendLine(pageText);
            }

            Console.WriteLine(text.ToString());
        }
    }
}
Imports PdfiumViewer
Imports System
Imports System.IO
Imports System.Text

Module Program
    Sub Main()
        Dim pdfPath As String = "document.pdf"

        Using document = PdfDocument.Load(pdfPath)
            Dim text As New StringBuilder()

            For i As Integer = 0 To document.PageCount - 1
                ' PdfiumViewer's text extraction is per-page raw text via GetPdfText(int).
                ' No layout / format metadata is exposed.
                Dim pageText As String = document.GetPdfText(i)
                text.AppendLine(pageText)
            Next

            Console.WriteLine(text.ToString())
        End Using
    End Sub
End Module
$vbLabelText   $csharpLabel

Po (IronPDF):

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

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        string pdfPath = "document.pdf";

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

        Console.WriteLine(text);
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        string pdfPath = "document.pdf";

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

        Console.WriteLine(text);
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"

        Dim pdfPath As String = "document.pdf"

        Dim pdf = PdfDocument.FromFile(pdfPath)
        Dim text As String = pdf.ExtractAllText()

        Console.WriteLine(text)
    End Sub
End Class
$vbLabelText   $csharpLabel

Różnica w tym przypadku jest znacząca.PdfiumViewerwymaga ręcznej pętli przez każdą stronę z GetPdfText(int), budowania StringBuilder i zarządzania instrukcją using do prawidłowego usuwania—i zwrócony tekst jest surowym tekstem per strona bez metadanych układu/formatu.

IronPDF upraszcza to do kilku linii: ładowanie z PdfDocument.FromFile(), wydobycie z ExtractAllText() i wyprowadzenie. Metoda ExtractAllText() obsługuje wszystkie strony automatycznie. Jeśli potrzebujesz wydobycia per strona, możesz użyć pdf.Pages[index].Text. Dodatkowe opcje można znaleźć w dokumentacji dotyczącej ekstrakcji tekstu.

Przykład 2: Łączenie plików PDF

Przed (PdfiumViewer):

// NuGet: Install-PackagePdfiumViewer (representative open-source PDFium wrapper)
//PdfiumViewerand PDFiumCore do not expose PDF merge APIs - PDFium itself
// is a rendering / parsing engine, not a document-authoring engine.
// (Patagames Pdfium.Net.SDK exposes some document-edit operations but is commercial.)
using PdfiumViewer;
using System;
using System.IO;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string>
        {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        };

        // To merge PDFs from a PDFium wrapper you must reach for another library
        // (PdfSharp, iText, IronPDF) or, with Patagames Pdfium.Net.SDK, use its
        // document-edit APIs.

        Console.WriteLine("PDF merging is not supported byPdfiumViewer/PDFiumCore.");
    }
}
// NuGet: Install-PackagePdfiumViewer (representative open-source PDFium wrapper)
//PdfiumViewerand PDFiumCore do not expose PDF merge APIs - PDFium itself
// is a rendering / parsing engine, not a document-authoring engine.
// (Patagames Pdfium.Net.SDK exposes some document-edit operations but is commercial.)
using PdfiumViewer;
using System;
using System.IO;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<string> pdfFiles = new List<string>
        {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        };

        // To merge PDFs from a PDFium wrapper you must reach for another library
        // (PdfSharp, iText, IronPDF) or, with Patagames Pdfium.Net.SDK, use its
        // document-edit APIs.

        Console.WriteLine("PDF merging is not supported byPdfiumViewer/PDFiumCore.");
    }
}
Imports PdfiumViewer
Imports System
Imports System.IO
Imports System.Collections.Generic

Module Program
    Sub Main()
        Dim pdfFiles As New List(Of String) From {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        }

        ' To merge PDFs from a PDFium wrapper you must reach for another library
        ' (PdfSharp, iText, IronPDF) or, with Patagames Pdfium.Net.SDK, use its
        ' document-edit APIs.

        Console.WriteLine("PDF merging is not supported by PdfiumViewer/PDFiumCore.")
    End Sub
End Module
$vbLabelText   $csharpLabel

Po (IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        List<string> pdfFiles = new List<string>
        {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        };

        // PdfDocument.Merge accepts an IEnumerable<PdfDocument>, so load each file first.
        var docs = pdfFiles.Select(path => PdfDocument.FromFile(path)).ToList();
        var merged = PdfDocument.Merge(docs);
        merged.SaveAs("merged.pdf");

        Console.WriteLine("PDFs merged successfully");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        List<string> pdfFiles = new List<string>
        {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        };

        // PdfDocument.Merge accepts an IEnumerable<PdfDocument>, so load each file first.
        var docs = pdfFiles.Select(path => PdfDocument.FromFile(path)).ToList();
        var merged = PdfDocument.Merge(docs);
        merged.SaveAs("merged.pdf");

        Console.WriteLine("PDFs merged successfully");
    }
}
Imports IronPdf
Imports System
Imports System.Collections.Generic
Imports System.Linq

Module Program
    Sub Main()
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"

        Dim pdfFiles As New List(Of String) From {
            "document1.pdf",
            "document2.pdf",
            "document3.pdf"
        }

        ' PdfDocument.Merge accepts an IEnumerable(Of PdfDocument), so load each file first.
        Dim docs = pdfFiles.Select(Function(path) PdfDocument.FromFile(path)).ToList()
        Dim merged = PdfDocument.Merge(docs)
        merged.SaveAs("merged.pdf")

        Console.WriteLine("PDFs merged successfully")
    End Sub
End Module
$vbLabelText   $csharpLabel

Ten przykład podkreśla lukę funkcjonalnościową. Wolne wrappy PDFium (PdfiumViewer, PDFiumCore) nie udostępniają API do łączenia; Patagames Pdfium.Net.SDK oferuje pewne operacje edytowania dokumentów, ale jest komercyjne.

IronPDF zapewnia natywne scalanie za pomocą statycznej metody PdfDocument.Merge(), która przyjmuje IEnumerable<PdfDocument>—należy najpierw załadować każdy plik wejściowy z PdfDocument.FromFile(), a następnie scalić otrzymane dokumenty. Wynik jest nowym PdfDocument, który zapisujesz z SaveAs(). Dowiedz się więcej o łączeniu i dzieleniu plików PDF.

Przykład 3: Konwersja HTML do PDF

Przed (PdfiumViewer):

// NuGet: Install-PackagePdfiumViewer (representative PDFium wrapper)
// PDFium is a PDF rendering / parsing engine. It has NO HTML parser, so no
// PDFium .NET wrapper (PdfiumViewer, PdfiumViewer.Updated, PDFiumCore,
// Pdfium.Net.SDK) can convert HTML to PDF on its own.
using PdfiumViewer;
using System;
using System.IO;
using System.Drawing.Printing;

class Program
{
    static void Main()
    {
        // PDFium has no native HTML-to-PDF capability.
        // Produce the PDF with another engine (wkhtmltopdf, headless Chromium,
        // IronPDF, etc.) and then load it with PdfDocument.Load(...) for rendering.
        string htmlContent = "<h1>Hello World</h1>";

        Console.WriteLine("HTML to PDF conversion is not supported by PDFium.");
    }
}
// NuGet: Install-PackagePdfiumViewer (representative PDFium wrapper)
// PDFium is a PDF rendering / parsing engine. It has NO HTML parser, so no
// PDFium .NET wrapper (PdfiumViewer, PdfiumViewer.Updated, PDFiumCore,
// Pdfium.Net.SDK) can convert HTML to PDF on its own.
using PdfiumViewer;
using System;
using System.IO;
using System.Drawing.Printing;

class Program
{
    static void Main()
    {
        // PDFium has no native HTML-to-PDF capability.
        // Produce the PDF with another engine (wkhtmltopdf, headless Chromium,
        // IronPDF, etc.) and then load it with PdfDocument.Load(...) for rendering.
        string htmlContent = "<h1>Hello World</h1>";

        Console.WriteLine("HTML to PDF conversion is not supported by PDFium.");
    }
}
Imports PdfiumViewer
Imports System
Imports System.IO
Imports System.Drawing.Printing

Module Program
    Sub Main()
        ' PDFium has no native HTML-to-PDF capability.
        ' Produce the PDF with another engine (wkhtmltopdf, headless Chromium,
        ' IronPDF, etc.) and then load it with PdfDocument.Load(...) for rendering.
        Dim htmlContent As String = "<h1>Hello World</h1>"

        Console.WriteLine("HTML to PDF conversion is not supported by PDFium.")
    End Sub
End Module
$vbLabelText   $csharpLabel

Po (IronPDF):

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

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        var renderer = new ChromePdfRenderer();
        string htmlContent = "<h1>Hello World</h1>";

        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        pdf.SaveAs("output.pdf");

        Console.WriteLine("PDF created successfully");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

        var renderer = new ChromePdfRenderer();
        string htmlContent = "<h1>Hello World</h1>";

        var pdf = renderer.RenderHtmlAsPdf(htmlContent);
        pdf.SaveAs("output.pdf");

        Console.WriteLine("PDF created successfully");
    }
}
Imports IronPdf
Imports System

Module Program
    Sub Main()
        IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"

        Dim renderer As New ChromePdfRenderer()
        Dim htmlContent As String = "<h1>Hello World</h1>"

        Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
        pdf.SaveAs("output.pdf")

        Console.WriteLine("PDF created successfully")
    End Sub
End Module
$vbLabelText   $csharpLabel

Ten przykład ilustruje najbardziej znaczącą różnicę w możliwościach. PDFium nie ma parsera HTML, więc żaden wrapper .NET nie może samodzielnie konwertować HTMLa na PDF.

IronPDF zapewnia natywną konwersję HTML do PDF przez ChromePdfRenderer, który wykorzystuje silnik Chromium wewnętrznie do dokładnego renderowania HTML, CSS i JavaScript. Metoda RenderHtmlAsPdf() konwertuje ciągi HTML bezpośrednio do dokumentów PDF.IronPDF może także renderować URL-e z RenderUrlAsPdf() i pliki HTML z RenderHtmlFileAsPdf(). Kompleksowe przykłady można znaleźć w dokumentacji dotyczącej konwersji HTML do PDF.


Usuwanie zależności natywnych

Jedną z najważniejszych korzyści z migracji z wrappera PDFium do IronPDF jest eliminacja zarządzania natywnymi binariami.

Przed (wrapper PDFium) - Złożone wdrożenie

MyApp/
├── bin/
│   ├── MyApp.dll
│   ├── PdfiumViewer.dll      # or PDFiumCore.dll / Patagames.Pdf.dll
│   ├── x86/
│   │   └── pdfium.dll
│   └── x64/
│       └── pdfium.dll
├── runtimes/
│   ├── win-x86/native/
│   │   └── pdfium.dll
│   ├── win-x64/native/
│   │   └── pdfium.dll
│   ├── linux-x64/native/
│   │   └── libpdfium.so
│   └── osx-x64/native/
│       └── libpdfium.dylib

Po (IronPDF) - Czyste wdrożenie

MyApp/
├── bin/
│   ├── MyApp.dll
│   └── IronPdf.dll  # Wszystko w zestawie

Usuń odniesienia do plików binarnych

# Delete native PDFium binaries
rm -rf x86/x64/runtimes/

# Remove from .csproj
# Delete any <Content Include="pdfium.dll" /> entries
# Delete any <None Include="x86/pdfium.dll" /> entries
# Delete native PDFium binaries
rm -rf x86/x64/runtimes/

# Remove from .csproj
# Delete any <Content Include="pdfium.dll" /> entries
# Delete any <None Include="x86/pdfium.dll" /> entries
SHELL

Ważne uwagi dotyczące migracji

Konwersja skali na DPI

Metoda Render(...)PdfiumViewerwymaga jawnych dpiX/dpiY, a podstawowe renderowanie PDFium jest skalowane (1.0 = 72 DPI).IronPDF używa DPI bezpośrednio:

// Formula:IronPDF DPI = 72 × PDFium scale
// PDFium scale 2.0 →IronPDF DPI 144
pdf.RasterizeToImageFiles("*.png", DPI: 144);
// Formula:IronPDF DPI = 72 × PDFium scale
// PDFium scale 2.0 →IronPDF DPI 144
pdf.RasterizeToImageFiles("*.png", DPI: 144);
' Formula: IronPDF DPI = 72 × PDFium scale
' PDFium scale 2.0 → IronPDF DPI 144
pdf.RasterizeToImageFiles("*.png", DPI:=144)
$vbLabelText   $csharpLabel

Zmiana metody ładowania dokumentów

// PdfiumViewer
PdfDocument.Load(path)

// IronPDF
PdfDocument.FromFile(path)
// PdfiumViewer
PdfDocument.Load(path)

// IronPDF
PdfDocument.FromFile(path)
' PdfiumViewer
PdfDocument.Load(path)

' IronPDF
PdfDocument.FromFile(path)
$vbLabelText   $csharpLabel

Zmiana metody zapisywania

//PdfiumViewer(takes a Stream)
document.Save(stream)

//IronPDF(takes a path)
pdf.SaveAs(path)
//PdfiumViewer(takes a Stream)
document.Save(stream)

//IronPDF(takes a path)
pdf.SaveAs(path)
' PdfiumViewer (takes a Stream)
document.Save(stream)

' IronPDF (takes a path)
pdf.SaveAs(path)
$vbLabelText   $csharpLabel

Uproszczenie wzorca usuwania

// PdfiumViewer: explicit disposal of document and the rendered Image
using (var document = PdfDocument.Load(path))
using (var bitmap = document.Render(0, 1024, 768, 96, 96, PdfRenderFlags.None))
{
    bitmap.Save("output.png");
}

// IronPDF: Simplified
var pdf = PdfDocument.FromFile(path);
pdf.RasterizeToImageFiles("output.png");
// PdfiumViewer: explicit disposal of document and the rendered Image
using (var document = PdfDocument.Load(path))
using (var bitmap = document.Render(0, 1024, 768, 96, 96, PdfRenderFlags.None))
{
    bitmap.Save("output.png");
}

// IronPDF: Simplified
var pdf = PdfDocument.FromFile(path);
pdf.RasterizeToImageFiles("output.png");
Imports PdfiumViewer

' PdfiumViewer: explicit disposal of document and the rendered Image
Using document = PdfDocument.Load(path)
    Using bitmap = document.Render(0, 1024, 768, 96, 96, PdfRenderFlags.None)
        bitmap.Save("output.png")
    End Using
End Using

' IronPDF: Simplified
Dim pdf = PdfDocument.FromFile(path)
pdf.RasterizeToImageFiles("output.png")
$vbLabelText   $csharpLabel

Usunięcie kodu specyficznego dla platformy

// PDFium wrapper: required platform detection / RID-specific binaries
#if WIN64
    // Load x64 pdfium.dll
#else
    // Load x86 pdfium.dll
#endif

// IronPDF: Remove all platform-specific code
// Just use the API directly
// PDFium wrapper: required platform detection / RID-specific binaries
#if WIN64
    // Load x64 pdfium.dll
#else
    // Load x86 pdfium.dll
#endif

// IronPDF: Remove all platform-specific code
// Just use the API directly
$vbLabelText   $csharpLabel

Podsumowanie porównania funkcji

Funkcja Wrappy .NET PDFium IronPDF
Pobierz plik PDF Tak Tak
Renderuj do obrazu Tak Tak
Wyodrębnij tekst Tak (podstawowe, na stronę) Tak (logiczna / wizualna kolejność)
Informacje o stronie Tak Tak
Utwórz z HTML None Tak
Utwórz z adresu URL None Tak
Łączenie plików PDF Wrappy free: brak; Patagames: częściowo Tak
Podział plików PDF Wrappy free: brak; Patagames: częściowo Tak
Dodaj znaki wodne Nie wbudowane Tak
Nagłówki/stopki Nie wbudowane Tak
Wypełnianie formularzy Wrappy free: brak; Patagames: tak Tak
Podpisy cyfrowe Wrappy free: brak; Patagames: tak Tak
Ochrona hasłem Wrappy free: brak; Patagames: tak Tak
Zależności natywne Wymagane Pakiety/Dostępne z zarządzania NuGet
Wielopłatformowe Złożona (binarie natywne per-RID) Automatyczne
Zarządzanie pamięcią Ręczne usuwanie Uproszczone

Lista kontrolna migracji

Przed migracją

  • Zidentyfikuj, który z wrapperów PDFium jest używany (PdfiumViewer / PdfiumViewer.Updated / PDFiumCore / Pdfium.Net.SDK)
  • Udokumentuj aktualne wymiary renderowania / DPI / skale używane
  • Wypisz lokalizacje natywnych binarii w projekcie (per RID)
  • Sprawdź kod ładowania specyficzny dla platformy
  • Określ potrzeby związane z tworzeniem plików PDF (obecnie używasz oddzielnych narzędzi?)
  • Przejrzyj wzorce usuwania w celu konwersji
  • Uzyskaj klucz licencyjny IronPDF

Zmiany w pakiecie

  • Usuń pakiet(i) PDFium wrapper NuGet: PdfiumViewer, PdfiumViewer.Updated, PDFiumCore, lub Pdfium.Net.SDK
  • Usuń natywne binaria pdfium.dll / .so / .dylib z folderów x86/, x64/, runtimes/
  • Usuń kompilację warunkową specyficzną dla platformy
  • Zaktualizuj plik .csproj, aby usunąć odwołania do natywnych plików binarnych
  • Zainstaluj pakiet NuGet IronPdf: dotnet add package IronPdf

Zmiany w kodzie

  • Dodaj konfigurację klucza licencyjnego podczas uruchamiania
  • Zamień PdfDocument.Load() na PdfDocument.FromFile()
  • Zamień document.Save() na pdf.SaveAs()
  • Zamień pętle document.GetPdfText(i) na pdf.ExtractAllText()
  • Przelicz współczynniki skali na wartości DPI (DPI = 72 × skala)
  • Uprość wzorce usuwania (usuń zagnieżdżone instrukcje using)
  • Usuń kod specyficzny dla platformy

Po migracji

  • Sprawdź jakość renderowania
  • Porównaj wyniki ekstrakcji tekstu
  • Testowanie wdrożenia na wielu platformach
  • Dodaj nowe funkcje (konwersja HTML do PDF, scałanie, znaki wodne, zabezpieczenia)
  • Aktualizacja dokumentacji

Zwróć uwagęPDFium jest projektem Google LLC, wydanym na licencji BSD-3-Clause. PdfiumViewer, PDFiumCore i Pdfium.Net.SDK są znakami towarowymi ich odpowiednich właścicieli (pvginkel, Dtronix i Patagames Software Ltd, odpowiednio). Ta strona nie jest związana, ani polecana, ani sponsorowana przez Google, projekt Chromium, ani żadnego z autorów wrapperów. Wszystkie nazwy produktów, logo i marki są własnością ich odpowiednich właścicieli. Porównania mają charakter wyłącznie informacyjny i odzwierciedlają informacje dostępne publicznie w momencie pisania.

Curtis Chau
Autor tekstów technicznych

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ę...

Czytaj więcej

Zespół wsparcia Iron

Jesteśmy online 24 godziny, 5 dni w tygodniu.
Czat
E-mail
Zadzwoń do mnie