Przejdź do treści stopki
PRZEWODNIKI MIGRACJI

Migracja z ActivePDF do IronPDF: (Przewodnik .NET)

ActivePDF to niezawodny zestaw narzędzi do obsługi plików PDF dla programistów .NET. Od momentu przejęcia przez PDFTron w czerwcu 2020 i rebrandingu na Apryse w lutym 2023,ActivePDFjest teraz jednym z kilku marek w szerokim portfolio Apryse. Ten przewodnik oferuje szczegółową, krok po kroku ścieżkę migracji zActivePDFdo IronPDF— nowoczesnej, aktywnie utrzymywanej biblioteki PDF dla .NET, wspierającej .NET Framework 4.6.2 do .NET 9.

Dlaczego warto rozważyć odejście od ActivePDF?

ActivePDF wciąż jest dostarczany, a pakiet NuGet ActivePDF.Toolkit nadal otrzymuje aktualizacje pod marką Apryse, jednak kilka aspektów jego projektowania i pakowania może skłonić zespoły do oceny alternatyw.

Rozważania dotyczące marki i planu rozwoju

ActivePDF jest teraz jedną z marek wewnątrz Apryse, obok flagowego SDK Apryse. Zespoły, które wybrałyActivePDFspecjalnie ze względu na jego skupienie na automatyzacji po stronie serwera, mogą zastanowić się, czy pozostawić SKUs ActivePDF, czy przejść na szersze SDK Apryse z czasem.

Model licencjonowania

Tradycyjne licencjonowanieActivePDFna serwer/rdzeń może wprowadzać trudności w środowiskach chmurowych i kontenerowych, gdzie aplikacje dynamicznie skalują się w infrastrukturze.

Wzorce architektury starszego typu

Powierzchnia APIActivePDFodzwierciedla jego poczynania z COM/natywnego pochodzenia. Workflow CloseOutputFile i zwracane kody całkowite (0 dla sukcesu) wymagają jawnego zarządzania cyklem życia, które nie zawsze jest zgodne z nowoczesnymi idiomami C#, takimi jak using, wyjątki i asynchroniczność.

Rozmieszczenie produktów z wieloma SKU

Renderowanie HTML/URL do PDF funkcjonuje w osobnym produkcie ActivePDF.WebGrabber, podczas gdy manipulacja PDF znajduje się w ActivePDF.Toolkit. Od wersji Toolkit 10, natywne biblioteki nie są już automatycznie kopiowane do folderu systemowego, dlatego konstruktor często wymaga jawnego argumentu CoreLibPath—wzorzec ten może komplikować wdrożenia Docker, CI i bezinstalacyjne.

ActivePDFa IronPDF: kluczowe różnice

Przed rozpoczęciem procesu migracji zrozumienie podstawowych różnic międzyActivePDFa IronPDF pomaga określić oczekiwania dotyczące wymaganych zmian w kodzie.

Aspekt ActivePDF IronPDF
Dostawca Apryse (dawniej PDFTron, przejętyActivePDFw czerwcu 2020) Iron Software, niezależne
Układ produktu Multiple SKUs (Toolkit, WebGrabber, DocConverter, Server, Meridian) Pojedynczy pakiet NuGet IronPdf
Instalacja Pakiet NuGet + ścieżka runtime (CoreLibPath od wersji 10) Pojedynczy pakiet NuGet; natives bundled
Wzorzec API Stan (CloseOutputFile), pochodne COM Płynne, funkcjonalne API
Model licencji Na serwer / na rdzeń Klucz oparty na kodzie
Wsparcie .NET .NET Framework 4.5+ / .NET Standard 1.0+ / .NET Core Framework 4.6.2 do .NET Framework 9
Obsługa błędów Zwracanie kodów całkowitych (0 = sukces) Standardowe wyjątki .NET Standard
Obsługa asynchroniczna Nie natywny Pełna obsługa async/await

Przygotowania przed migracją

Przeprowadź audyt swojego kodu źródłowego

Przed rozpoczęciem migracji należy zidentyfikować wszystkie miejsca użyciaActivePDFw całym rozwiązaniu. Rzeczywiste przestrzenie nazw to APToolkitNET (Toolkit) i APWebGrabber (WebGrabber); Kilka starszych projektów również odwołuje się do ActivePDF.Toolkit poprzez zespół interop COM. Uruchom te polecenia w katalogu rozwiązania:

grep -r "using APToolkitNET" --include="*.cs" .
grep -r "using APWebGrabber" --include="*.cs" .
grep -r "ActivePDF" --include="*.csproj" .
grep -r "using APToolkitNET" --include="*.cs" .
grep -r "using APWebGrabber" --include="*.cs" .
grep -r "ActivePDF" --include="*.csproj" .
SHELL

Zmiany powodujące niekompatybilność dokumentów

Zrozumienie podstawowych różnic między interfejsami API pomaga w planowaniu strategii migracji:

Kategoria DziałanieActivePDF Działanie IronPDF Działanie migracyjne
Podział produktu Toolkit (manipulacja) + WebGrabber (renderowanie HTML) sprzedawane osobno Pojedynczy pakiet IronPdf Scal oba w jedną bibliotekę
Model obiektowy APToolkitNET.Toolkit dla PDFów, APWebGrabber.WebGrabber dla HTML ChromePdfRenderer + PdfDocument Rozdzielenie zagadnień
Operacje na plikach CloseOutputFile() Bezpośrednie SaveAs() Usuń niejednoznaczne sformułowania
Natywne środowisko uruchomieniowe Argument CoreLibPath od wersji 10 NuGet dostarcza natywne Usuń konfigurację ścieżki
Tworzenie strony Metoda NewPage() Automatycznie z HTML Usuń wywołania tworzenia stron
Wartości zwracane Kody błędów liczb całkowitych Wyjątki Wprowadź try/catch
Jednostki rozmiaru strony Punkty (612x792 = Letter) Wypisywanie lub milimetry Aktualizacja pomiarów

Wymagania wstępne

Upewnij się, że Twoje środowisko spełnia następujące wymagania:

  • .NET Framework 4.6.2+ lub .NET Core 3.1 / .NET 5-9
  • Visual Studio 2019+ lub JetBrains Rider
  • Dostęp do menedżera pakietów NuGet
  • Klucz licencyjny IronPDF(bezpłatna wersja próbna dostępna na stronie ironpdf.com)

Proces migracji krok po kroku

Krok 1: Zaktualizuj pakiety NuGet

Pakiet na nuget.org to ActivePDF.Toolkit (bieżąca wersja 11.4.4, opublikowany w grudniu 2025). Renderowanie HTML jest dostarczane oddzielnie jako ActivePDF.WebGrabber. Usuń SKUActivePDFi zainstaluj IronPDF:

# RemoveActivePDFpackages
dotnet remove package ActivePDF.Toolkit
dotnet remove package ActivePDF.WebGrabber

# Install IronPDF
dotnet add package IronPdf
# RemoveActivePDFpackages
dotnet remove package ActivePDF.Toolkit
dotnet remove package ActivePDF.WebGrabber

# Install IronPDF
dotnet add package IronPdf
SHELL

Alternatywnie, za pomocą konsoli menedżera pakietów Visual Studio:

Uninstall-Package ActivePDF.Toolkit
Uninstall-Package ActivePDF.WebGrabber
Install-Package IronPdf

Dla projektów z ręcznymi odwołaniami do DLL, usuń odwołanie z pliku .csproj:


<Reference Include="APToolkitNET">
    <HintPath>path\to\APToolkitNET.dll</HintPath>
</Reference>

<Reference Include="APToolkitNET">
    <HintPath>path\to\APToolkitNET.dll</HintPath>
</Reference>
XML

Krok 2: Skonfiguruj klucz licencyjny

Dodaj klucz licencyjny IronPDF podczas uruchamiania aplikacji, przed wykonaniem jakichkolwiek operacji na plikach PDF:

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

// Verify license status
bool isLicensed = IronPdf.License.IsLicensed;
// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

// Verify license status
bool isLicensed = IronPdf.License.IsLicensed;
' Add at application startup (Program.vb or Startup.vb)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"

' Verify license status
Dim isLicensed As Boolean = IronPdf.License.IsLicensed
$vbLabelText   $csharpLabel

Krok 3: Zaktualizuj odniesienia do przestrzeni nazw

Przeprowadź globalne wyszukiwanie i zamianę w całym rozwiązaniu:

Znajdź Zastąp przez
using APToolkitNET; using IronPdf;
using APWebGrabber; using IronPdf;
APToolkitNET.Toolkit ChromePdfRenderer (renderowanie) / PdfDocument (manipulacja)
APWebGrabber.WebGrabber ChromePdfRenderer

Kompletna dokumentacja API

Metody tworzenia dokumentów

MetodaActivePDF Odpowiednik IronPDF Uwagi
new APToolkitNET.Toolkit() new ChromePdfRenderer() / new PdfDocument(...) IronPDF oddziela renderowanie od manipulacji
new Toolkit(CoreLibPath: path) new ChromePdfRenderer() NuGet dostarcza natywne—brak CoreLibPath
toolkit.OpenOutputFile(path) Nie jest potrzebny odpowiednik Wystarczy wywołać SaveAs na końcu
toolkit.CloseOutputFile() Nie jest potrzebny odpowiednik using zajmuje się sprzątaniem
webGrabber.URL = html; webGrabber.ConvertToPDF() renderer.RenderHtmlAsPdf(html) WebGrabber, nie Toolkit
webGrabber.URL = url; webGrabber.ConvertToPDF() renderer.RenderUrlAsPdf(url) WebGrabber, nie Toolkit

Operacje na plikach

MetodaActivePDF Odpowiednik IronPDF Uwagi
toolkit.OpenInputFile(path) PdfDocument.FromFile(path) Wczytaj istniejący plik PDF
toolkit.MergeFile(path, startPage, endPage) PdfDocument.Merge(pdfs) ActivePDF scalany jest w pliku wyjściowym na miejscu;IronPDF zwraca nowy scalony dokument
toolkit.NumPages (właściwość) pdf.PageCount Liczba stron
toolkit.GetPageText(page, 0) pdf.Pages[i].Text / pdf.ExtractAllText() Wyodrębnianie tekstu

Konfiguracja strony

MetodaActivePDF Odpowiednik IronPDF
toolkit.SetPageSize(612, 792) RenderingOptions.PaperSize = PdfPaperSize.Letter
toolkit.SetOrientation("Landscape") RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape
toolkit.SetMargins(t, b, l, r) RenderingOptions.MarginTop/Bottom/Left/Right

Metody bezpieczeństwa

MetodaActivePDF Odpowiednik IronPDF
toolkit.SetEncryption(user, owner, 128, 0) pdf.SecuritySettings.OwnerPassword / UserPassword
toolkit.SetPermissions(flags) pdf.SecuritySettings.AllowUserXxx
toolkit.PrintText(x, y, text) (znak wodny na stronę) pdf.ApplyWatermark(html)

Przykłady migracji kodu

Konwersja HTML do PDF

Konwersja ciągów znaków HTML na dokumenty PDF stanowi jeden z najczęstszych scenariuszy generowania plików PDF. Zauważ, że w ActivePDF, renderowanie HTML znajduje się w osobno licencjonowanym produkcie WebGrabber, a nie Toolkit, i WebGrabber renderuje z URL-a lub ścieżki pliku, zamiast z pamięci jako ciąg.

ImplementacjaActivePDF(WebGrabber):

// NuGet: Install-Package ActivePDF.WebGrabber
using APWebGrabber;
using System;
using System.IO;

class Program
{
    static void Main()
    {
        WebGrabber wg = new WebGrabber();

        string htmlContent = "<html><body><h1>Hello World</h1></body></html>";
        string tempHtml = Path.Combine(Path.GetTempPath(), "input.html");
        File.WriteAllText(tempHtml, htmlContent);

        wg.URL = tempHtml;
        wg.OutputDirectory = Directory.GetCurrentDirectory();
        wg.OutputFilename = "output.pdf";

        if (wg.ConvertToPDF() == 0)
        {
            Console.WriteLine("PDF created successfully");
        }
    }
}
// NuGet: Install-Package ActivePDF.WebGrabber
using APWebGrabber;
using System;
using System.IO;

class Program
{
    static void Main()
    {
        WebGrabber wg = new WebGrabber();

        string htmlContent = "<html><body><h1>Hello World</h1></body></html>";
        string tempHtml = Path.Combine(Path.GetTempPath(), "input.html");
        File.WriteAllText(tempHtml, htmlContent);

        wg.URL = tempHtml;
        wg.OutputDirectory = Directory.GetCurrentDirectory();
        wg.OutputFilename = "output.pdf";

        if (wg.ConvertToPDF() == 0)
        {
            Console.WriteLine("PDF created successfully");
        }
    }
}
Imports APWebGrabber
Imports System
Imports System.IO

Module Program
    Sub Main()
        Dim wg As New WebGrabber()

        Dim htmlContent As String = "<html><body><h1>Hello World</h1></body></html>"
        Dim tempHtml As String = Path.Combine(Path.GetTempPath(), "input.html")
        File.WriteAllText(tempHtml, htmlContent)

        wg.URL = tempHtml
        wg.OutputDirectory = Directory.GetCurrentDirectory()
        wg.OutputFilename = "output.pdf"

        If wg.ConvertToPDF() = 0 Then
            Console.WriteLine("PDF created successfully")
        End If
    End Sub
End Module
$vbLabelText   $csharpLabel

Wdrożenie 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");

        Console.WriteLine("PDF created successfully");
    }
}
// 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");

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

Module Program
    Sub Main()
        Dim renderer As New ChromePdfRenderer()

        Dim htmlContent As String = "<html><body><h1>Hello World</h1></body></html>"

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

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

Podejście IronPDF eliminuje konieczność jawnego zarządzania uchwytami plików, zapewniając jednocześnie czystszy i bardziej czytelny kod. Dla zaawansowanych scenariuszy HTML do PDF, ChromePdfRenderer w IronPDF używa silnika renderującego bazującego na Chromium do idealnego wsparcia dla CSS i JavaScript.

Konwersja adresów URL do formatu PDF

Przechwytywanie stron internetowych jako dokumentów PDF również znajduje się w WebGrabber, a nie Toolkit.

ImplementacjaActivePDF(WebGrabber):

// NuGet: Install-Package ActivePDF.WebGrabber
using APWebGrabber;
using System;
using System.IO;

class Program
{
    static void Main()
    {
        WebGrabber wg = new WebGrabber();

        wg.URL = "https://www.example.com";
        wg.OutputDirectory = Directory.GetCurrentDirectory();
        wg.OutputFilename = "webpage.pdf";

        if (wg.ConvertToPDF() == 0)
        {
            Console.WriteLine("PDF from URL created successfully");
        }
    }
}
// NuGet: Install-Package ActivePDF.WebGrabber
using APWebGrabber;
using System;
using System.IO;

class Program
{
    static void Main()
    {
        WebGrabber wg = new WebGrabber();

        wg.URL = "https://www.example.com";
        wg.OutputDirectory = Directory.GetCurrentDirectory();
        wg.OutputFilename = "webpage.pdf";

        if (wg.ConvertToPDF() == 0)
        {
            Console.WriteLine("PDF from URL created successfully");
        }
    }
}
Imports APWebGrabber
Imports System
Imports System.IO

Module Program
    Sub Main()
        Dim wg As New WebGrabber()

        wg.URL = "https://www.example.com"
        wg.OutputDirectory = Directory.GetCurrentDirectory()
        wg.OutputFilename = "webpage.pdf"

        If wg.ConvertToPDF() = 0 Then
            Console.WriteLine("PDF from URL created successfully")
        End If
    End Sub
End Module
$vbLabelText   $csharpLabel

Wdrożenie IronPDF:

using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();

        string url = "https://www.example.com";

        var pdf = renderer.RenderUrlAsPdf(url);
        pdf.SaveAs("webpage.pdf");

        Console.WriteLine("PDF from URL created successfully");
    }
}
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();

        string url = "https://www.example.com";

        var pdf = renderer.RenderUrlAsPdf(url);
        pdf.SaveAs("webpage.pdf");

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

Class Program
    Shared Sub Main()
        Dim renderer = New ChromePdfRenderer()

        Dim url As String = "https://www.example.com"

        Dim pdf = renderer.RenderUrlAsPdf(url)
        pdf.SaveAs("webpage.pdf")

        Console.WriteLine("PDF from URL created successfully")
    End Sub
End Class
$vbLabelText   $csharpLabel

Łączenie wielu plików PDF

Łączenie wielu dokumentów PDF w jeden plik pokazuje funkcjonalne podejście IronPDF do manipulacji dokumentami.

ImplementacjaActivePDF(Toolkit):

// NuGet: Install-Package ActivePDF.Toolkit
using APToolkitNET;
using System;

class Program
{
    static void Main()
    {
        using (Toolkit toolkit = new Toolkit())
        {
            if (toolkit.OpenOutputFile("merged.pdf") == 0)
            {
                // MergeFile(FileName, StartPage, EndPage); -1 = end of file
                toolkit.MergeFile("document1.pdf", 1, -1);
                toolkit.MergeFile("document2.pdf", 1, -1);
                toolkit.CloseOutputFile();
                Console.WriteLine("PDFs merged successfully");
            }
        }
    }
}
// NuGet: Install-Package ActivePDF.Toolkit
using APToolkitNET;
using System;

class Program
{
    static void Main()
    {
        using (Toolkit toolkit = new Toolkit())
        {
            if (toolkit.OpenOutputFile("merged.pdf") == 0)
            {
                // MergeFile(FileName, StartPage, EndPage); -1 = end of file
                toolkit.MergeFile("document1.pdf", 1, -1);
                toolkit.MergeFile("document2.pdf", 1, -1);
                toolkit.CloseOutputFile();
                Console.WriteLine("PDFs merged successfully");
            }
        }
    }
}
Imports APToolkitNET
Imports System

Module Program
    Sub Main()
        Using toolkit As New Toolkit()
            If toolkit.OpenOutputFile("merged.pdf") = 0 Then
                ' MergeFile(FileName, StartPage, EndPage); -1 = end of file
                toolkit.MergeFile("document1.pdf", 1, -1)
                toolkit.MergeFile("document2.pdf", 1, -1)
                toolkit.CloseOutputFile()
                Console.WriteLine("PDFs merged successfully")
            End If
        End Using
    End Sub
End Module
$vbLabelText   $csharpLabel

Wdrożenie IronPDF:

using IronPdf;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var pdf1 = PdfDocument.FromFile("document1.pdf");
        var pdf2 = PdfDocument.FromFile("document2.pdf");

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

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

class Program
{
    static void Main()
    {
        var pdf1 = PdfDocument.FromFile("document1.pdf");
        var pdf2 = PdfDocument.FromFile("document2.pdf");

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

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

Module Program
    Sub Main()
        Dim pdf1 = PdfDocument.FromFile("document1.pdf")
        Dim pdf2 = PdfDocument.FromFile("document2.pdf")

        Dim merged = PdfDocument.Merge(pdf1, pdf2)
        merged.SaveAs("merged.pdf")

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

Aby uzyskać informacje na temat bardziej zaawansowanych scenariuszy łączenia, w tym selektywnego wyodrębniania stron, zapoznaj się z dokumentacją dotyczącą łączenia plików PDF.

Dodawanie nagłówków i stopek

ImplementacjaActivePDF(WebGrabber):

using APWebGrabber;
using System.IO;

public void CreatePdfWithHeaderFooter(string html, string outputPath)
{
    var wg = new WebGrabber();
    string tempHtml = Path.Combine(Path.GetTempPath(), "input.html");
    File.WriteAllText(tempHtml, html);

    wg.URL = tempHtml;
    wg.HeaderText = "My Document";
    wg.FooterText = "Page [page] of [pages]";
    wg.OutputDirectory = Path.GetDirectoryName(outputPath);
    wg.OutputFilename = Path.GetFileName(outputPath);
    wg.ConvertToPDF();
}
using APWebGrabber;
using System.IO;

public void CreatePdfWithHeaderFooter(string html, string outputPath)
{
    var wg = new WebGrabber();
    string tempHtml = Path.Combine(Path.GetTempPath(), "input.html");
    File.WriteAllText(tempHtml, html);

    wg.URL = tempHtml;
    wg.HeaderText = "My Document";
    wg.FooterText = "Page [page] of [pages]";
    wg.OutputDirectory = Path.GetDirectoryName(outputPath);
    wg.OutputFilename = Path.GetFileName(outputPath);
    wg.ConvertToPDF();
}
Imports APWebGrabber
Imports System.IO

Public Sub CreatePdfWithHeaderFooter(html As String, outputPath As String)
    Dim wg As New WebGrabber()
    Dim tempHtml As String = Path.Combine(Path.GetTempPath(), "input.html")
    File.WriteAllText(tempHtml, html)

    wg.URL = tempHtml
    wg.HeaderText = "My Document"
    wg.FooterText = "Page [page] of [pages]"
    wg.OutputDirectory = Path.GetDirectoryName(outputPath)
    wg.OutputFilename = Path.GetFileName(outputPath)
    wg.ConvertToPDF()
End Sub
$vbLabelText   $csharpLabel

Wdrożenie IronPDF:

using IronPdf;

public void CreatePdfWithHeaderFooter(string html, string outputPath)
{
    var renderer = new ChromePdfRenderer();

    renderer.RenderingOptions.TextHeader = new TextHeaderFooter
    {
        CenterText = "My Document",
        FontSize = 12,
        FontFamily = "Arial"
    };

    renderer.RenderingOptions.TextFooter = new TextHeaderFooter
    {
        CenterText = "Page {page} of {total-pages}",
        FontSize = 10,
        FontFamily = "Arial"
    };

    using var pdf = renderer.RenderHtmlAsPdf(html);
    pdf.SaveAs(outputPath);
}
using IronPdf;

public void CreatePdfWithHeaderFooter(string html, string outputPath)
{
    var renderer = new ChromePdfRenderer();

    renderer.RenderingOptions.TextHeader = new TextHeaderFooter
    {
        CenterText = "My Document",
        FontSize = 12,
        FontFamily = "Arial"
    };

    renderer.RenderingOptions.TextFooter = new TextHeaderFooter
    {
        CenterText = "Page {page} of {total-pages}",
        FontSize = 10,
        FontFamily = "Arial"
    };

    using var pdf = renderer.RenderHtmlAsPdf(html);
    pdf.SaveAs(outputPath);
}
Imports IronPdf

Public Sub CreatePdfWithHeaderFooter(html As String, outputPath As String)
    Dim renderer = New ChromePdfRenderer()

    renderer.RenderingOptions.TextHeader = New TextHeaderFooter With {
        .CenterText = "My Document",
        .FontSize = 12,
        .FontFamily = "Arial"
    }

    renderer.RenderingOptions.TextFooter = New TextHeaderFooter With {
        .CenterText = "Page {page} of {total-pages}",
        .FontSize = 10,
        .FontFamily = "Arial"
    }

    Using pdf = renderer.RenderHtmlAsPdf(html)
        pdf.SaveAs(outputPath)
    End Using
End Sub
$vbLabelText   $csharpLabel

IronPDF obsługuje zarówno nagłówki i stopki tekstowe, jak i HTML, zapewniając pełną elastyczność projektowania.

Ochrona hasłem i bezpieczeństwo

ImplementacjaActivePDF(Toolkit):

using APToolkitNET;

public void ProtectPdf(string inputPath, string outputPath, string password)
{
    using (Toolkit toolkit = new Toolkit())
    {
        if (toolkit.OpenOutputFile(outputPath) == 0
            && toolkit.OpenInputFile(inputPath) == 0)
        {
            toolkit.SetEncryption(password, password, 128, 0);
            toolkit.CopyForm(0, 0);
            toolkit.CloseInputFile();
            toolkit.CloseOutputFile();
        }
    }
}
using APToolkitNET;

public void ProtectPdf(string inputPath, string outputPath, string password)
{
    using (Toolkit toolkit = new Toolkit())
    {
        if (toolkit.OpenOutputFile(outputPath) == 0
            && toolkit.OpenInputFile(inputPath) == 0)
        {
            toolkit.SetEncryption(password, password, 128, 0);
            toolkit.CopyForm(0, 0);
            toolkit.CloseInputFile();
            toolkit.CloseOutputFile();
        }
    }
}
Imports APToolkitNET

Public Sub ProtectPdf(inputPath As String, outputPath As String, password As String)
    Using toolkit As New Toolkit()
        If toolkit.OpenOutputFile(outputPath) = 0 AndAlso toolkit.OpenInputFile(inputPath) = 0 Then
            toolkit.SetEncryption(password, password, 128, 0)
            toolkit.CopyForm(0, 0)
            toolkit.CloseInputFile()
            toolkit.CloseOutputFile()
        End If
    End Using
End Sub
$vbLabelText   $csharpLabel

Wdrożenie IronPDF:

using IronPdf;

public void ProtectPdf(string inputPath, string outputPath, string password)
{
    using var pdf = PdfDocument.FromFile(inputPath);

    pdf.SecuritySettings.OwnerPassword = password;
    pdf.SecuritySettings.UserPassword = password;
    pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;
    pdf.SecuritySettings.AllowUserCopyPasteContent = false;
    pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit;

    pdf.SaveAs(outputPath);
}
using IronPdf;

public void ProtectPdf(string inputPath, string outputPath, string password)
{
    using var pdf = PdfDocument.FromFile(inputPath);

    pdf.SecuritySettings.OwnerPassword = password;
    pdf.SecuritySettings.UserPassword = password;
    pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;
    pdf.SecuritySettings.AllowUserCopyPasteContent = false;
    pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit;

    pdf.SaveAs(outputPath);
}
Imports IronPdf

Public Sub ProtectPdf(inputPath As String, outputPath As String, password As String)
    Using pdf = PdfDocument.FromFile(inputPath)
        pdf.SecuritySettings.OwnerPassword = password
        pdf.SecuritySettings.UserPassword = password
        pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights
        pdf.SecuritySettings.AllowUserCopyPasteContent = False
        pdf.SecuritySettings.AllowUserEdits = PdfEditSecurity.NoEdit

        pdf.SaveAs(outputPath)
    End Using
End Sub
$vbLabelText   $csharpLabel

API ustawień zabezpieczeńIronPDF zapewnia szczegółową kontrolę nad uprawnieniami do dokumentów dzięki silnie typowanym wyliczeniom zamiast flag całkowitoliczbowych.

Wyodrębnianie tekstu

ImplementacjaActivePDF(Toolkit):

using APToolkitNET;
using System.Text;

public string ExtractText(string pdfPath)
{
    var sb = new StringBuilder();

    using (Toolkit toolkit = new Toolkit())
    {
        if (toolkit.OpenInputFile(pdfPath) == 0)
        {
            int pageCount = toolkit.NumPages;
            for (int i = 1; i <= pageCount; i++)
            {
                sb.AppendLine(toolkit.GetPageText(i, 0));
            }
            toolkit.CloseInputFile();
        }
    }

    return sb.ToString();
}
using APToolkitNET;
using System.Text;

public string ExtractText(string pdfPath)
{
    var sb = new StringBuilder();

    using (Toolkit toolkit = new Toolkit())
    {
        if (toolkit.OpenInputFile(pdfPath) == 0)
        {
            int pageCount = toolkit.NumPages;
            for (int i = 1; i <= pageCount; i++)
            {
                sb.AppendLine(toolkit.GetPageText(i, 0));
            }
            toolkit.CloseInputFile();
        }
    }

    return sb.ToString();
}
Imports APToolkitNET
Imports System.Text

Public Function ExtractText(pdfPath As String) As String
    Dim sb As New StringBuilder()

    Using toolkit As New Toolkit()
        If toolkit.OpenInputFile(pdfPath) = 0 Then
            Dim pageCount As Integer = toolkit.NumPages
            For i As Integer = 1 To pageCount
                sb.AppendLine(toolkit.GetPageText(i, 0))
            Next
            toolkit.CloseInputFile()
        End If
    End Using

    Return sb.ToString()
End Function
$vbLabelText   $csharpLabel

Wdrożenie IronPDF:

using IronPdf;

public string ExtractText(string pdfPath)
{
    using var pdf = PdfDocument.FromFile(pdfPath);
    return pdf.ExtractAllText();
}
using IronPdf;

public string ExtractText(string pdfPath)
{
    using var pdf = PdfDocument.FromFile(pdfPath);
    return pdf.ExtractAllText();
}
Imports IronPdf

Public Function ExtractText(pdfPath As String) As String
    Using pdf = PdfDocument.FromFile(pdfPath)
        Return pdf.ExtractAllText()
    End Using
End Function
$vbLabelText   $csharpLabel

Wdrożenie IronPDF sprowadza wyodrębnianie tekstu z wielu wierszy do jednego wywołania metody.

Dodawanie znaków wodnych

ImplementacjaActivePDF(Toolkit — rysowane jako tekst strony na stronę):

using APToolkitNET;

public void AddWatermark(string inputPath, string outputPath, string watermarkText)
{
    using (Toolkit toolkit = new Toolkit())
    {
        if (toolkit.OpenOutputFile(outputPath) == 0
            && toolkit.OpenInputFile(inputPath) == 0)
        {
            int pageCount = toolkit.NumPages;
            for (int i = 1; i <= pageCount; i++)
            {
                toolkit.CopyForm(i, 0);
                toolkit.SetFont("Helvetica", 72);
                toolkit.SetTextColor(200, 200, 200);
                toolkit.PrintText(150, 400, watermarkText);
            }
            toolkit.CloseInputFile();
            toolkit.CloseOutputFile();
        }
    }
}
using APToolkitNET;

public void AddWatermark(string inputPath, string outputPath, string watermarkText)
{
    using (Toolkit toolkit = new Toolkit())
    {
        if (toolkit.OpenOutputFile(outputPath) == 0
            && toolkit.OpenInputFile(inputPath) == 0)
        {
            int pageCount = toolkit.NumPages;
            for (int i = 1; i <= pageCount; i++)
            {
                toolkit.CopyForm(i, 0);
                toolkit.SetFont("Helvetica", 72);
                toolkit.SetTextColor(200, 200, 200);
                toolkit.PrintText(150, 400, watermarkText);
            }
            toolkit.CloseInputFile();
            toolkit.CloseOutputFile();
        }
    }
}
Imports APToolkitNET

Public Sub AddWatermark(inputPath As String, outputPath As String, watermarkText As String)
    Using toolkit As New Toolkit()
        If toolkit.OpenOutputFile(outputPath) = 0 AndAlso toolkit.OpenInputFile(inputPath) = 0 Then
            Dim pageCount As Integer = toolkit.NumPages
            For i As Integer = 1 To pageCount
                toolkit.CopyForm(i, 0)
                toolkit.SetFont("Helvetica", 72)
                toolkit.SetTextColor(200, 200, 200)
                toolkit.PrintText(150, 400, watermarkText)
            Next
            toolkit.CloseInputFile()
            toolkit.CloseOutputFile()
        End If
    End Using
End Sub
$vbLabelText   $csharpLabel

Wdrożenie IronPDF:

using IronPdf;

public void AddWatermark(string inputPath, string outputPath, string watermarkText)
{
    using var pdf = PdfDocument.FromFile(inputPath);

    pdf.ApplyWatermark(
        $"<h1 style='color:lightgray;font-size:72px;'>{watermarkText}</h1>",
        rotation: 45,
        opacity: 50);

    pdf.SaveAs(outputPath);
}
using IronPdf;

public void AddWatermark(string inputPath, string outputPath, string watermarkText)
{
    using var pdf = PdfDocument.FromFile(inputPath);

    pdf.ApplyWatermark(
        $"<h1 style='color:lightgray;font-size:72px;'>{watermarkText}</h1>",
        rotation: 45,
        opacity: 50);

    pdf.SaveAs(outputPath);
}
Imports IronPdf

Public Sub AddWatermark(inputPath As String, outputPath As String, watermarkText As String)
    Using pdf = PdfDocument.FromFile(inputPath)
        pdf.ApplyWatermark(
            $"<h1 style='color:lightgray;font-size:72px;'>{watermarkText}</h1>",
            rotation:=45,
            opacity:=50)

        pdf.SaveAs(outputPath)
    End Using
End Sub
$vbLabelText   $csharpLabel

Funkcja znakowania wodnego oparta na HTML w IronPDF umożliwia stosowanie stylów CSS, co zapewnia pełną kontrolę nad projektem bez konieczności powtarzania czynności na każdej stronie.

Integracja z ASP.NET Core.NET Core

Nowoczesne aplikacje internetowe czerpią znaczne korzyści z bardziej przejrzystych wzorców integracji IronPDF.

WzorzecActivePDF(WebGrabber):

[HttpPost]
public IActionResult GeneratePdf([FromBody] ReportRequest request)
{
    var wg = new APWebGrabber.WebGrabber();
    string tempHtml = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".html");
    System.IO.File.WriteAllText(tempHtml, request.Html);

    wg.URL = tempHtml;
    wg.OutputDirectory = Path.GetTempPath();
    wg.OutputFilename = "temp.pdf";

    if (wg.ConvertToPDF() == 0)
    {
        byte[] bytes = System.IO.File.ReadAllBytes(Path.Combine(Path.GetTempPath(), "temp.pdf"));
        return File(bytes, "application/pdf", "report.pdf");
    }

    return BadRequest("PDF generation failed");
}
[HttpPost]
public IActionResult GeneratePdf([FromBody] ReportRequest request)
{
    var wg = new APWebGrabber.WebGrabber();
    string tempHtml = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".html");
    System.IO.File.WriteAllText(tempHtml, request.Html);

    wg.URL = tempHtml;
    wg.OutputDirectory = Path.GetTempPath();
    wg.OutputFilename = "temp.pdf";

    if (wg.ConvertToPDF() == 0)
    {
        byte[] bytes = System.IO.File.ReadAllBytes(Path.Combine(Path.GetTempPath(), "temp.pdf"));
        return File(bytes, "application/pdf", "report.pdf");
    }

    return BadRequest("PDF generation failed");
}
Imports System
Imports System.IO
Imports Microsoft.AspNetCore.Mvc

<HttpPost>
Public Function GeneratePdf(<FromBody> request As ReportRequest) As IActionResult
    Dim wg As New APWebGrabber.WebGrabber()
    Dim tempHtml As String = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() & ".html")
    System.IO.File.WriteAllText(tempHtml, request.Html)

    wg.URL = tempHtml
    wg.OutputDirectory = Path.GetTempPath()
    wg.OutputFilename = "temp.pdf"

    If wg.ConvertToPDF() = 0 Then
        Dim bytes As Byte() = System.IO.File.ReadAllBytes(Path.Combine(Path.GetTempPath(), "temp.pdf"))
        Return File(bytes, "application/pdf", "report.pdf")
    End If

    Return BadRequest("PDF generation failed")
End Function
$vbLabelText   $csharpLabel

Wzór IronPDF:

[HttpPost]
public IActionResult GeneratePdf([FromBody] ReportRequest request)
{
    var renderer = new ChromePdfRenderer();
    using var pdf = renderer.RenderHtmlAsPdf(request.Html);

    return File(pdf.BinaryData, "application/pdf", "report.pdf");
}
[HttpPost]
public IActionResult GeneratePdf([FromBody] ReportRequest request)
{
    var renderer = new ChromePdfRenderer();
    using var pdf = renderer.RenderHtmlAsPdf(request.Html);

    return File(pdf.BinaryData, "application/pdf", "report.pdf");
}
<HttpPost>
Public Function GeneratePdf(<FromBody> request As ReportRequest) As IActionResult
    Dim renderer As New ChromePdfRenderer()
    Using pdf = renderer.RenderHtmlAsPdf(request.Html)
        Return File(pdf.BinaryData, "application/pdf", "report.pdf")
    End Using
End Function
$vbLabelText   $csharpLabel

IronPDF eliminuje potrzebę tworzenia plików tymczasowych, zwracając dane binarne PDF bezpośrednio z pamięci.

Obsługa asynchroniczna w aplikacjach internetowych

ActivePDF nie obsługuje natywnie operacji asynchronicznych.IronPDF zapewnia pełne możliwości async/await niezbędne dla skalowalnych aplikacji internetowych:

using IronPdf;

public async Task<byte[]> GeneratePdfAsync(string html)
{
    var renderer = new ChromePdfRenderer();
    using var pdf = await renderer.RenderHtmlAsPdfAsync(html);
    return pdf.BinaryData;
}
using IronPdf;

public async Task<byte[]> GeneratePdfAsync(string html)
{
    var renderer = new ChromePdfRenderer();
    using var pdf = await renderer.RenderHtmlAsPdfAsync(html);
    return pdf.BinaryData;
}
Imports IronPdf

Public Async Function GeneratePdfAsync(html As String) As Task(Of Byte())
    Dim renderer As New ChromePdfRenderer()
    Using pdf = Await renderer.RenderHtmlAsPdfAsync(html)
        Return pdf.BinaryData
    End Using
End Function
$vbLabelText   $csharpLabel

Konfiguracja wstrzykiwania zależności

W przypadku aplikacji .NET 6+ zarejestruj usługi IronPDF w swoim kontenerze DI:

// Program.cs (.NET 6+)
builder.Services.AddSingleton<ChromePdfRenderer>();

// Service wrapper
public interface IPdfService
{
    Task<byte[]> GeneratePdfAsync(string html);
    Task<byte[]> GeneratePdfFromUrlAsync(string url);
}

public class IronPdfService : IPdfService
{
    private readonly ChromePdfRenderer _renderer;

    public IronPdfService()
    {
        _renderer = new ChromePdfRenderer();
        _renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
    }

    public async Task<byte[]> GeneratePdfAsync(string html)
    {
        using var pdf = await _renderer.RenderHtmlAsPdfAsync(html);
        return pdf.BinaryData;
    }

    public async Task<byte[]> GeneratePdfFromUrlAsync(string url)
    {
        using var pdf = await _renderer.RenderUrlAsPdfAsync(url);
        return pdf.BinaryData;
    }
}
// Program.cs (.NET 6+)
builder.Services.AddSingleton<ChromePdfRenderer>();

// Service wrapper
public interface IPdfService
{
    Task<byte[]> GeneratePdfAsync(string html);
    Task<byte[]> GeneratePdfFromUrlAsync(string url);
}

public class IronPdfService : IPdfService
{
    private readonly ChromePdfRenderer _renderer;

    public IronPdfService()
    {
        _renderer = new ChromePdfRenderer();
        _renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
    }

    public async Task<byte[]> GeneratePdfAsync(string html)
    {
        using var pdf = await _renderer.RenderHtmlAsPdfAsync(html);
        return pdf.BinaryData;
    }

    public async Task<byte[]> GeneratePdfFromUrlAsync(string url)
    {
        using var pdf = await _renderer.RenderUrlAsPdfAsync(url);
        return pdf.BinaryData;
    }
}
Imports Microsoft.Extensions.DependencyInjection
Imports System.Threading.Tasks

' Program.vb (.NET 6+)
builder.Services.AddSingleton(Of ChromePdfRenderer)()

' Service wrapper
Public Interface IPdfService
    Function GeneratePdfAsync(html As String) As Task(Of Byte())
    Function GeneratePdfFromUrlAsync(url As String) As Task(Of Byte())
End Interface

Public Class IronPdfService
    Implements IPdfService

    Private ReadOnly _renderer As ChromePdfRenderer

    Public Sub New()
        _renderer = New ChromePdfRenderer()
        _renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
    End Sub

    Public Async Function GeneratePdfAsync(html As String) As Task(Of Byte()) Implements IPdfService.GeneratePdfAsync
        Using pdf = Await _renderer.RenderHtmlAsPdfAsync(html)
            Return pdf.BinaryData
        End Using
    End Function

    Public Async Function GeneratePdfFromUrlAsync(url As String) As Task(Of Byte()) Implements IPdfService.GeneratePdfFromUrlAsync
        Using pdf = Await _renderer.RenderUrlAsPdfAsync(url)
            Return pdf.BinaryData
        End Using
    End Function
End Class
$vbLabelText   $csharpLabel

Obsługa błędów Migracja

ActivePDF używa całkowitoliczbowych kodów zwrotnych, które wymagają tabel odnośników.IronPDF wykorzystuje nowoczesną obsługę wyjątków:

Obsługa błędów ActivePDF:

using APToolkitNET;

using (var toolkit = new Toolkit())
{
    int result = toolkit.OpenOutputFile(path);

    if (result != 0)
    {
        // Error - look up the code in "Toolkit Return Results and Error Codes"
        Console.WriteLine($"Error code: {result}");
    }
}
using APToolkitNET;

using (var toolkit = new Toolkit())
{
    int result = toolkit.OpenOutputFile(path);

    if (result != 0)
    {
        // Error - look up the code in "Toolkit Return Results and Error Codes"
        Console.WriteLine($"Error code: {result}");
    }
}
Imports APToolkitNET

Using toolkit As New Toolkit()
    Dim result As Integer = toolkit.OpenOutputFile(path)

    If result <> 0 Then
        ' Error - look up the code in "Toolkit Return Results and Error Codes"
        Console.WriteLine($"Error code: {result}")
    End If
End Using
$vbLabelText   $csharpLabel

Obsługa błędów w IronPDF:

try
{
    var renderer = new ChromePdfRenderer();
    using var pdf = renderer.RenderHtmlAsPdf(html);
    pdf.SaveAs(path);
}
catch (IronPdf.Exceptions.IronPdfProductException ex)
{
    Console.WriteLine($"IronPDF Error: {ex.Message}");
}
catch (Exception ex)
{
    Console.WriteLine($"General Error: {ex.Message}");
}
try
{
    var renderer = new ChromePdfRenderer();
    using var pdf = renderer.RenderHtmlAsPdf(html);
    pdf.SaveAs(path);
}
catch (IronPdf.Exceptions.IronPdfProductException ex)
{
    Console.WriteLine($"IronPDF Error: {ex.Message}");
}
catch (Exception ex)
{
    Console.WriteLine($"General Error: {ex.Message}");
}
Imports IronPdf.Exceptions

Try
    Dim renderer = New ChromePdfRenderer()
    Using pdf = renderer.RenderHtmlAsPdf(html)
        pdf.SaveAs(path)
    End Using
Catch ex As IronPdfProductException
    Console.WriteLine($"IronPDF Error: {ex.Message}")
Catch ex As Exception
    Console.WriteLine($"General Error: {ex.Message}")
End Try
$vbLabelText   $csharpLabel

Wskazówki dotyczące optymalizacji wydajności

Ponowne wykorzystanie instancji renderera

Tworzenie nowego ChromePdfRenderer ma obciążenie inicjalizacyjne. W przypadku operacji wsadowych należy ponownie wykorzystać pojedynczą instancję:

var renderer = new ChromePdfRenderer();
foreach (var html in htmlList)
{
    using var pdf = renderer.RenderHtmlAsPdf(html);
    pdf.SaveAs($"output_{i}.pdf");
}
var renderer = new ChromePdfRenderer();
foreach (var html in htmlList)
{
    using var pdf = renderer.RenderHtmlAsPdf(html);
    pdf.SaveAs($"output_{i}.pdf");
}
Imports IronPdf

Dim renderer As New ChromePdfRenderer()
For Each html In htmlList
    Using pdf = renderer.RenderHtmlAsPdf(html)
        pdf.SaveAs($"output_{i}.pdf")
    End Using
Next
$vbLabelText   $csharpLabel

Wykorzystanie Async w aplikacjach internetowych

W przypadku aplikacji .NET Core asynchroniczne generowanie plików PDF poprawia przepustowość:

public async Task<IActionResult> GenerateReport()
{
    var renderer = new ChromePdfRenderer();
    using var pdf = await renderer.RenderHtmlAsPdfAsync(html);
    return File(pdf.BinaryData, "application/pdf");
}
public async Task<IActionResult> GenerateReport()
{
    var renderer = new ChromePdfRenderer();
    using var pdf = await renderer.RenderHtmlAsPdfAsync(html);
    return File(pdf.BinaryData, "application/pdf");
}
Imports System.Threading.Tasks
Imports Microsoft.AspNetCore.Mvc

Public Class ReportController
    Inherits Controller

    Public Async Function GenerateReport() As Task(Of IActionResult)
        Dim renderer As New ChromePdfRenderer()
        Using pdf = Await renderer.RenderHtmlAsPdfAsync(html)
            Return File(pdf.BinaryData, "application/pdf")
        End Using
    End Function
End Class
$vbLabelText   $csharpLabel

Właściwa utylizacja zasobów

Zawsze używaj instrukcji using, aby zapewnić prawidłowe sprzątanie:

using var pdf = renderer.RenderHtmlAsPdf(html);
return pdf.BinaryData;
using var pdf = renderer.RenderHtmlAsPdf(html);
return pdf.BinaryData;
$vbLabelText   $csharpLabel

Kompresja obrazów

Zmniejsz rozmiar plików wyjściowych dzięki kompresji obrazów:

using var pdf = renderer.RenderHtmlAsPdf(html);
pdf.CompressImages(85); // 85% quality
pdf.SaveAs("compressed.pdf");
using var pdf = renderer.RenderHtmlAsPdf(html);
pdf.CompressImages(85); // 85% quality
pdf.SaveAs("compressed.pdf");
$vbLabelText   $csharpLabel

Rozwiązywanie typowych problemów związanych z migracją

Problem: Różnice w rozmiarze stron

ActivePDF WebGrabber używa punktów (612x792 = Letter), podczas gdy IronPDF używa wyliczeń lub milimetrów:

//ActivePDFWebGrabber: Points
wg.PageWidth = 612;
wg.PageHeight = 792;

// IronPDF: Use enum
renderer.RenderingOptions.PaperSize = PdfPaperSize.Letter;
// Or custom in mm:
renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(215.9, 279.4);
//ActivePDFWebGrabber: Points
wg.PageWidth = 612;
wg.PageHeight = 792;

// IronPDF: Use enum
renderer.RenderingOptions.PaperSize = PdfPaperSize.Letter;
// Or custom in mm:
renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(215.9, 279.4);
'ActivePDFWebGrabber: Points
wg.PageWidth = 612
wg.PageHeight = 792

' IronPDF: Use enum
renderer.RenderingOptions.PaperSize = PdfPaperSize.Letter
' Or custom in mm:
renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(215.9, 279.4)
$vbLabelText   $csharpLabel

Problem: Brak odpowiednika CloseOutputFile

IronPDF wykorzystuje nowoczesny paradygmat bez jawnego zarządzania uchwytami plików:

//ActivePDFToolkit
toolkit.OpenOutputFile(path);
// ... operations ...
toolkit.CloseOutputFile(); // Required!

//IronPDF- no open/close needed
using var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs(path); // 'using' handles cleanup
//ActivePDFToolkit
toolkit.OpenOutputFile(path);
// ... operations ...
toolkit.CloseOutputFile(); // Required!

//IronPDF- no open/close needed
using var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs(path); // 'using' handles cleanup
Imports IronPdf

' ActivePDFToolkit
toolkit.OpenOutputFile(path)
' ... operations ...
toolkit.CloseOutputFile() ' Required!

' IronPDF - no open/close needed
Using pdf = renderer.RenderHtmlAsPdf(html)
    pdf.SaveAs(path) ' 'Using' handles cleanup
End Using
$vbLabelText   $csharpLabel

Problem: Plik PDF wyświetla się jako pusty

Jeśli treści zależne od JavaScriptu wyświetlają się jako puste, skonfiguruj opóźnienia renderowania:

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.WaitFor.RenderDelay(2000);
// Or wait for element:
renderer.RenderingOptions.WaitFor.HtmlElementById("content-loaded");
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.WaitFor.RenderDelay(2000);
// Or wait for element:
renderer.RenderingOptions.WaitFor.HtmlElementById("content-loaded");
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.WaitFor.RenderDelay(2000)
' Or wait for element:
renderer.RenderingOptions.WaitFor.HtmlElementById("content-loaded")
$vbLabelText   $csharpLabel

Problem: CSS/obrazy się nie ładują

Skonfiguruj adres URL bazowy dla rozpoznawania ścieżek względnych:

renderer.RenderingOptions.BaseUrl = new Uri("https://yourdomain.com/assets/");
renderer.RenderingOptions.BaseUrl = new Uri("https://yourdomain.com/assets/");
renderer.RenderingOptions.BaseUrl = New Uri("https://yourdomain.com/assets/")
$vbLabelText   $csharpLabel

Lista kontrolna po migracji

Po zakończeniu migracji kodu sprawdź, czy:

  • Uruchom wszystkie istniejące testy jednostkowe i integracyjne
  • Porównaj wizualnie pliki PDF z poprzednimi wersjami
  • Przetestuj wszystkie procesy związane z plikami PDF w środowisku testowym
  • Zweryfikuj poprawne działanie licencjonowania (IronPdf.License.IsLicensed)
  • Porównanie wydajności z poprzednią implementacją
  • Usuń stare pliki instalacyjneActivePDFi odwołania do bibliotek DLL
  • Aktualizacja zależności potoku CI/CD
  • Udokumentuj wzorce IronPDF dla swojego zespołu programistów

Dodatkowe zasoby


Przejście zActivePDFna IronPDF unowocześnia infrastrukturę generowania plików PDF dzięki bardziej przejrzystym interfejsom API, lepszej integracji z platformą .NET oraz aktywnemu, długoterminowemu wsparciu technicznemu. Inwestycja w migrację przynosi korzyści w postaci lepszej łatwości utrzymania kodu, możliwości asynchronicznych oraz pewności co do dalszego rozwoju biblioteki PDF.

Zwróć uwagęActivePDF i Apryse są zarejestrowanymi znakami towarowymi swoich właścicieli. Ta strona nie jest powiązana, popierana ani sponsorowana przezActivePDFani Apryse. 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