Jak przeprowadzić migrację z Sumatra PDF do IronPDF w języku C#
Migrating fromSumatra PDFtoIronPDFtransforms your PDF workflow from external process management with a desktop viewer application to native .NET library integration with full PDF creation, manipulation, and extraction capabilities. This guide provides a complete, step-by-step migration path that eliminates external dependencies,GPLlicense restrictions, and the fundamental limitation thatSumatra PDFis a viewer, not a development library.
Why Migrate fromSumatra PDFto IronPDF
Understanding Sumatra PDF
Sumatra PDF is primarily a lightweight, open-source PDF reader renowned for its simplicity and speed. However,Sumatra PDFdoes not provide the capabilities needed for creating or manipulating PDF files beyond viewing them. As a free and versatile option for reading PDFs, it is adored by many users seeking a no-frills experience. But when it comes to developers needing more comprehensive PDF functionalities like creation and library integration within applications,Sumatra PDFfalls short due to its inherent design limitations.
Sumatra PDF is a desktop PDF viewer application, not a development library. If you're usingSumatra PDFin your .NET application, you're likely:
- Launching it as an external process to display PDFs
- Using it for printing PDFs via command-line
- Relying on it as a dependency your users must install
Key Problems withSumatra PDFIntegration
| Problem | Wpływ |
|---|---|
| Nie jest to biblioteka | Nie można programowo tworzyć ani edytować plików PDF |
| Proces zewnętrzny | Wymaga uruchamiania oddzielnych procesów |
| Licencja GPL | Ograniczenia dotyczące oprogramowania komercyjnego |
| Zależność użytkownika | Użytkownicy muszą zainstalować Sumatrę osobno |
| Brak API | Ograniczone do argumentów wiersza poleceń |
| Tylko do przeglądania | Nie można tworzyć, edytować ani modyfikować plików PDF |
| Brak wsparcia internetowego | Aplikacja przeznaczona wyłącznie na komputery stacjonarne |
Sumatra PDFvsIronPDFComparison
| Funkcja | Sumatra PDF | IronPDF |
|---|---|---|
| Typ | Zastosowanie | Biblioteka |
| Odczytywanie plików PDF | Tak | Tak |
| Tworzenie plików PDF | Nie | Tak |
| Edycja plików PDF | Nie | Tak |
| Integracja | Ograniczone (samodzielne) | Pełna integracja z aplikacjami |
| Licencja | GPL | Komercjalne |
| Create PDFs | Nie | Tak |
| Edit PDFs | Nie | Tak |
| HTML do PDF | Nie | Tak |
| Scal/Podziel | Nie | Tak |
| Znaki wodne | Nie | Tak |
| Podpisy cyfrowe | Nie | Tak |
| Wypełnianie formularzy | Nie | Tak |
| Wyodrębnianie tekstu | Nie | Tak |
| Integracja z platformą .NET | None | Język ojczysty |
| Aplikacje internetowe | Nie | Tak |
IronPDF, unlike Sumatra PDF, is not tied to any specific desktop application or external process. It provides developers with a flexible library to dynamically create, edit, and manipulate PDF documents directly in C#. This decoupling from external processes offers a noticeable advantage—it is straightforward and adaptable, suitable for a wide array of applications beyond just viewing.
For teams planning .NET 10 and C# 14 adoption through 2025 and 2026,IronPDFprovides native library integration that eliminates the external process overhead andGPLlicense restrictions of Sumatra PDF.
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
Instalacja
# Install IronPDF
dotnet add package IronPdf
# Install IronPDF
dotnet add package IronPdf
Konfiguracja licencji
// Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
' Add at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Kompletna dokumentacija API
Zmiany w przestrzeni nazw
// Before:Sumatra PDF(external process)
using System.Diagnostics;
using System.IO;
// After: IronPDF
using IronPdf;
// Before:Sumatra PDF(external process)
using System.Diagnostics;
using System.IO;
// After: IronPDF
using IronPdf;
Imports System.Diagnostics
Imports System.IO
Imports IronPdf
Core Capability Mappings
| Sumatra PDFApproach | OdpowiednikIronPDF | Uwagi |
|---|---|---|
Process.Start("SumatraPDF.exe", pdfPath) |
PdfDocument.FromFile() |
Pobierz plik PDF |
| Command-line arguments | Język ojczysty API methods | Nie CLI needed |
External pdftotext.exe |
pdf.ExtractAllText() |
Wyodrębnianie tekstu |
External wkhtmltopdf.exe |
renderer.RenderHtmlAsPdf() |
HTML do PDF |
-print-to-default argument |
pdf.Print() |
Drukowanie |
| Niemożliwe | PdfDocument.Merge() |
Łączenie plików PDF |
| Niemożliwe | pdf.ApplyWatermark() |
Znaki wodne |
| Niemożliwe | pdf.SecuritySettings |
Ochrona hasłem |
Przykłady migracji kodu
Przykład 1: Konwersja HTML do PDF
Before (Sumatra PDF):
// NuGet: Install-Package SumatraPDF (Note: Sumatra is primarily a viewer, not a generator)
//Sumatra PDFdoesn't have direct C# integration for HTML do PDF conversion
// You would need to use external tools or libraries and then open with Sumatra
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
//Sumatra PDFcannot directly convert HTML to PDF
// You'd need to use wkhtmltopdf or similar, then view in Sumatra
string htmlFile = "input.html";
string pdfFile = "output.pdf";
// Using wkhtmltopdf as intermediary
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "wkhtmltopdf.exe",
Arguments = $"{htmlFile} {pdfFile}",
UseShellExecute = false
};
Process.Start(psi)?.WaitForExit();
// Then open with Sumatra
Process.Start("SumatraPDF.exe", pdfFile);
}
}
// NuGet: Install-Package SumatraPDF (Note: Sumatra is primarily a viewer, not a generator)
//Sumatra PDFdoesn't have direct C# integration for HTML do PDF conversion
// You would need to use external tools or libraries and then open with Sumatra
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
//Sumatra PDFcannot directly convert HTML to PDF
// You'd need to use wkhtmltopdf or similar, then view in Sumatra
string htmlFile = "input.html";
string pdfFile = "output.pdf";
// Using wkhtmltopdf as intermediary
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "wkhtmltopdf.exe",
Arguments = $"{htmlFile} {pdfFile}",
UseShellExecute = false
};
Process.Start(psi)?.WaitForExit();
// Then open with Sumatra
Process.Start("SumatraPDF.exe", pdfFile);
}
}
Imports System.Diagnostics
Imports System.IO
Module Program
Sub Main()
' Sumatra PDF cannot directly convert HTML to PDF
' You'd need to use wkhtmltopdf or similar, then view in Sumatra
Dim htmlFile As String = "input.html"
Dim pdfFile As String = "output.pdf"
' Using wkhtmltopdf as intermediary
Dim psi As New ProcessStartInfo With {
.FileName = "wkhtmltopdf.exe",
.Arguments = $"{htmlFile} {pdfFile}",
.UseShellExecute = False
}
Process.Start(psi)?.WaitForExit()
' Then open with Sumatra
Process.Start("SumatraPDF.exe", pdfFile)
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 = "<h1>Hello World</h1><p>This is HTML do PDF conversion.</p>";
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 = "<h1>Hello World</h1><p>This is HTML do PDF conversion.</p>";
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully!");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim htmlContent As String = "<h1>Hello World</h1><p>This is HTML do PDF conversion.</p>"
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF created successfully!")
End Sub
End Class
Ten przykład ilustruje podstawową różnicę architektoniczną.Sumatra PDFcannot directly convert HTML to PDF—you must use an external tool like wkhtmltopdf as an intermediary, then launch Sumatra as a separate process to view the result. This requires two external executables and multiple process launches.
IronPDF uses a ChromePdfRenderer with RenderHtmlAsPdf() in just three lines of code. Nie external tools, no process management, no intermediary files. The PDF is created directly in memory and saved with SaveAs(). Kompleksowe przykłady można znaleźć w dokumentacji dotyczącej konwersji HTML do PDF.
Example 2: Opening and Displaying PDFs
Before (Sumatra PDF):
// NuGet: Install-Package SumatraPDF.CommandLine (or direct executable)
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
string pdfPath = "document.pdf";
//Sumatra PDFexcels at viewing PDFs
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "SumatraPDF.exe",
Arguments = $"\"{pdfPath}\"",
UseShellExecute = true
};
Process.Start(startInfo);
// Optional: Open specific page
// Arguments = $"-page 5 \"{pdfPath}\""
}
}
// NuGet: Install-Package SumatraPDF.CommandLine (or direct executable)
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
string pdfPath = "document.pdf";
//Sumatra PDFexcels at viewing PDFs
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "SumatraPDF.exe",
Arguments = $"\"{pdfPath}\"",
UseShellExecute = true
};
Process.Start(startInfo);
// Optional: Open specific page
// Arguments = $"-page 5 \"{pdfPath}\""
}
}
Imports System.Diagnostics
Imports System.IO
Module Program
Sub Main()
Dim pdfPath As String = "document.pdf"
' Sumatra PDF excels at viewing PDFs
Dim startInfo As New ProcessStartInfo With {
.FileName = "SumatraPDF.exe",
.Arguments = $"""{pdfPath}""",
.UseShellExecute = True
}
Process.Start(startInfo)
' Optional: Open specific page
' .Arguments = $"-page 5 ""{pdfPath}"""
End Sub
End Module
Po (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// Extract information
Console.WriteLine($"Page Count: {pdf.PageCount}");
//IronPDFcan manipulate and save, then open with default viewer
pdf.SaveAs("modified.pdf");
// Open with default PDF viewer
Process.Start(new ProcessStartInfo("modified.pdf") { UseShellExecute = true });
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// Extract information
Console.WriteLine($"Page Count: {pdf.PageCount}");
//IronPDFcan manipulate and save, then open with default viewer
pdf.SaveAs("modified.pdf");
// Open with default PDF viewer
Process.Start(new ProcessStartInfo("modified.pdf") { UseShellExecute = true });
}
}
Imports IronPdf
Imports System
Imports System.Diagnostics
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("document.pdf")
' Extract information
Console.WriteLine($"Page Count: {pdf.PageCount}")
' IronPDF can manipulate and save, then open with default viewer
pdf.SaveAs("modified.pdf")
' Open with default PDF viewer
Process.Start(New ProcessStartInfo("modified.pdf") With {.UseShellExecute = True})
End Sub
End Class
Sumatra PDF excels at viewing PDFs, but it's limited to launching an external process with command-line arguments. You cannot programmatically access the PDF content—only display it.
IronPDF loads the PDF with PdfDocument.FromFile(), giving you full programmatic access. You can read properties like PageCount, manipulate the document, save changes, and then open with the system's default PDF viewer. The key difference is thatIronPDFprovides an actual API, not just process arguments. Dowiedz się więcej z naszych samouczków.
Example 3: Extracting Text from PDFs
Before (Sumatra PDF):
//Sumatra PDFdoesn't provide C# API for text extraction
// You would need to use command-line tools or other libraries
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
//Sumatra PDFis a viewer, not a text extraction library
// You'd need to use PDFBox, iTextSharp, or similar for extraction
string pdfFile = "document.pdf";
// This would require external tools like pdftotext
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "pdftotext.exe",
Arguments = $"{pdfFile} output.txt",
UseShellExecute = false
};
Process.Start(psi)?.WaitForExit();
string extractedText = File.ReadAllText("output.txt");
Console.WriteLine(extractedText);
}
}
//Sumatra PDFdoesn't provide C# API for text extraction
// You would need to use command-line tools or other libraries
using System.Diagnostics;
using System.IO;
class Program
{
static void Main()
{
//Sumatra PDFis a viewer, not a text extraction library
// You'd need to use PDFBox, iTextSharp, or similar for extraction
string pdfFile = "document.pdf";
// This would require external tools like pdftotext
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "pdftotext.exe",
Arguments = $"{pdfFile} output.txt",
UseShellExecute = false
};
Process.Start(psi)?.WaitForExit();
string extractedText = File.ReadAllText("output.txt");
Console.WriteLine(extractedText);
}
}
Imports System.Diagnostics
Imports System.IO
Module Program
Sub Main()
' Sumatra PDF is a viewer, not a text extraction library
' You'd need to use PDFBox, iTextSharp, or similar for extraction
Dim pdfFile As String = "document.pdf"
' This would require external tools like pdftotext
Dim psi As New ProcessStartInfo With {
.FileName = "pdftotext.exe",
.Arguments = $"{pdfFile} output.txt",
.UseShellExecute = False
}
Process.Start(psi)?.WaitForExit()
Dim extractedText As String = File.ReadAllText("output.txt")
Console.WriteLine(extractedText)
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");
// Extract text from all pages
string allText = pdf.ExtractAllText();
Console.WriteLine("Extracted Text:");
Console.WriteLine(allText);
// Extract text from specific page
string pageText = pdf.ExtractTextFromPage(0);
Console.WriteLine($"\nFirst Page Text:\n{pageText}");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("document.pdf");
// Extract text from all pages
string allText = pdf.ExtractAllText();
Console.WriteLine("Extracted Text:");
Console.WriteLine(allText);
// Extract text from specific page
string pageText = pdf.ExtractTextFromPage(0);
Console.WriteLine($"\nFirst Page Text:\n{pageText}");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim pdf = PdfDocument.FromFile("document.pdf")
' Extract text from all pages
Dim allText As String = pdf.ExtractAllText()
Console.WriteLine("Extracted Text:")
Console.WriteLine(allText)
' Extract text from specific page
Dim pageText As String = pdf.ExtractTextFromPage(0)
Console.WriteLine(vbCrLf & "First Page Text:" & vbCrLf & pageText)
End Sub
End Class
Sumatra PDF is a viewer, not a text extraction library. To extract text, you must use external command-line tools like pdftotext.exe, spawn a process, wait for it to complete, read the output file, and handle all the associated file I/O and cleanup.
IronPDF provides native text extraction with ExtractAllText() for the entire document or ExtractTextFromPage(0) for specific pages. Nie external processes, no temporary files, no cleanup required.
Porównanie funkcji
| Funkcja | Sumatra PDF | IronPDF | |||
|---|---|---|---|---|---|
| :Creation: | HTML do PDF | Nie | Tak | ||
| URL do pliku PDF | Nie | Tak | |||
| Tekst do PDF | Nie | Tak | |||
| Obraz do PDF | Nie | Tak | |||
| :Manipulation: | Łączenie plików PDF | Nie | Tak | ||
| Podział plików PDF | Nie | Tak | |||
| Przewracaj strony | Nie | Tak | |||
| Usuń strony | Nie | Tak | |||
| Zmień kolejność stron | Nie | Tak | |||
| :Content: | Dodaj znaki wodne | Nie | Tak | ||
| Dodaj nagłówki/stopki | Nie | Tak | |||
| Tekst stempla | Nie | Tak | |||
| Obrazy stempli | Nie | Tak | |||
| :Security: | Ochrona hasłem | Nie | Tak | ||
| Podpisy cyfrowe | Nie | Tak | |||
| Szyfrowanie | Nie | Tak | |||
| Ustawienia uprawnień | Nie | Tak | |||
| :Extraction: | Wyodrębnij tekst | Nie | Tak | ||
| Wyodrębnij obrazy | Nie | Tak | |||
| :Platform: | Windows | Tak | Tak | ||
| Linux | Nie | Tak | |||
| macOS | Nie | Tak | |||
| Aplikacje internetowe | Nie | Tak | |||
| Azure/AWS | Nie | Tak |
Nowe możliwości po migracji
After migrating to IronPDF, you gain capabilities thatSumatra PDFcannot provide:
PDF Creation from HTML
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
<html>
<head><style>body { font-family: Arial; }</style></head>
<body>
<h1>Invoice #12345</h1>
<p>Thank you for your purchase.</p>
</body>
</html>");
pdf.SaveAs("invoice.pdf");
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
<html>
<head><style>body { font-family: Arial; }</style></head>
<body>
<h1>Invoice #12345</h1>
<p>Thank you for your purchase.</p>
</body>
</html>");
pdf.SaveAs("invoice.pdf");
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("
<html>
<head><style>body { font-family: Arial; }</style></head>
<body>
<h1>Invoice #12345</h1>
<p>Thank you for your purchase.</p>
</body>
</html>")
pdf.SaveAs("invoice.pdf")
Łączenie plików PDF
var pdf1 = PdfDocument.FromFile("chapter1.pdf");
var pdf2 = PdfDocument.FromFile("chapter2.pdf");
var pdf3 = PdfDocument.FromFile("chapter3.pdf");
var book = PdfDocument.Merge(pdf1, pdf2, pdf3);
book.SaveAs("complete_book.pdf");
var pdf1 = PdfDocument.FromFile("chapter1.pdf");
var pdf2 = PdfDocument.FromFile("chapter2.pdf");
var pdf3 = PdfDocument.FromFile("chapter3.pdf");
var book = PdfDocument.Merge(pdf1, pdf2, pdf3);
book.SaveAs("complete_book.pdf");
Dim pdf1 = PdfDocument.FromFile("chapter1.pdf")
Dim pdf2 = PdfDocument.FromFile("chapter2.pdf")
Dim pdf3 = PdfDocument.FromFile("chapter3.pdf")
Dim book = PdfDocument.Merge(pdf1, pdf2, pdf3)
book.SaveAs("complete_book.pdf")
Znaki wodne
var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark(@"
<div style='
font-size: 60pt;
color: rgba(255, 0, 0, 0.3);
transform: rotate(-45deg);
'>
CONFIDENTIAL
</div>");
pdf.SaveAs("watermarked.pdf");
var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark(@"
<div style='
font-size: 60pt;
color: rgba(255, 0, 0, 0.3);
transform: rotate(-45deg);
'>
CONFIDENTIAL
</div>");
pdf.SaveAs("watermarked.pdf");
Dim pdf = PdfDocument.FromFile("document.pdf")
pdf.ApplyWatermark("
<div style='
font-size: 60pt;
color: rgba(255, 0, 0, 0.3);
transform: rotate(-45deg);
'>
CONFIDENTIAL
</div>")
pdf.SaveAs("watermarked.pdf")
Ochrona hasłem
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Sensitive Data</h1>");
pdf.SecuritySettings.OwnerPassword = "owner123";
pdf.SecuritySettings.UserPassword = "user456";
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SaveAs("protected.pdf");
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Sensitive Data</h1>");
pdf.SecuritySettings.OwnerPassword = "owner123";
pdf.SecuritySettings.UserPassword = "user456";
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SaveAs("protected.pdf");
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Sensitive Data</h1>")
pdf.SecuritySettings.OwnerPassword = "owner123"
pdf.SecuritySettings.UserPassword = "user456"
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint
pdf.SaveAs("protected.pdf")
Lista kontrolna migracji
Przed migracją
- Identify all Sumatra process launches (
Process.Start("SumatraPDF.exe", ...)) - Document print workflows (
-print-to-defaultarguments) - Note any Sumatra command-line arguments used
- Uzyskaj klucz licencyjnyIronPDFze strony ironpdf.com
Aktualizacje kodu
- Install
IronPdfNuGet package - Remove Sumatra process code
- Replace
Process.Start("SumatraPDF.exe", pdfPath)withPdfDocument.FromFile(pdfPath) - Replace external
wkhtmltopdf.execalls withChromePdfRenderer.RenderHtmlAsPdf() - Replace external
pdftotext.execalls withpdf.ExtractAllText() - Replace
-print-to-defaultprocess calls withpdf.Print() - Dodaj inicjalizację licencji podczas uruchamiania aplikacji
Testowanie
- Test PDF generation quality
- Verify print functionality
- Test on all target platforms
- Verify no Sumatra dependency remains
Cleanup
- Remove Sumatra from installers
- Aktualizacja dokumentacji
- Remove Sumatra from system requirements

