
Como migrar do RawPrint para o IronPDF em C#
Mover de Impressão bruta para IronPDF é menos uma substituição do que uma adaptação: Impressão bruta e IronPDF resolvem problemas diferentes, e a moldura honesta para a maioria das equipes é 'complementar', não 'substituir'. Este guia percorre os casos onde IronPDF realmente substitui um pipeline Impressão bruta (criar-um-PDF-e-então-enviá-lo fluxos de trabalho no Windows) e sinaliza os casos onde você deve manter Impressão bruta no lugar (ESC/POS, ZPL, EPL, PCL bruto).
Por que migrar do Impressão bruta para o IronPDF?
Entendendo o RawPrint
RawPrint é o pacote NuGet RawPrint (frogmorecs/RawPrint, v0.5.0, último lançamento em setembro de 2019, agora removido/legado no nuget.org). É um wrapper fino de P/Invoke sobre winspool.Drv que envia um fluxo de bytes diretamente para o spooler de impressão doWindowscom o tipo de dado RAW. A API pública é pequena: uma classe Printer implementando IPrinter no namespace RawPrint, expondo sobrecargas PrintRawFile e PrintRawStream. As chamadas subjacentes do Win32 (OpenPrinter, StartDocPrinter, WritePrinter, EndDocPrinter, ClosePrinter) são ocultas atrás dessa interface - você não as escreve por si mesmo ao usar o pacote.
Isso faz do Impressão bruta uma boa opção para impressoras de recibo ESC/POS, impressoras de etiquetas ZPL/EPL Zebra, e trabalhos legados PCL/PostScript onde você já produziu os bytes que o firmware da impressora espera. Para desenvolvedores que visam ambientes específicos doWindowse que necessitam de comunicação direta com a impressora, o Impressão bruta oferece um caminho eficiente, evitando camadas intermediárias como drivers ou interfaces gráficas.
No entanto, Impressão bruta não é uma biblioteca de PDF - ele apenas envia dados para impressoras. Se sua aplicação atualmente constrói um PDF em alguma outra biblioteca e depois o entrega ao RawPrint, todo esse pipeline geralmente pode ser condensado no IronPDF no Windows.
O problema central: a impossibilidade de criar um PDF.
O Impressão bruta apresenta limitações notáveis que o tornam inadequado para fluxos de trabalho de documentos modernos:
-
Sem criação de PDF: O Impressão bruta se concentra exclusivamente na transmissão de dados, não oferecendo funcionalidades para criação, renderização ou manipulação de PDFs.
-
Nível muito baixo: Ao lidar diretamente com bytes brutos, os desenvolvedores precisam ter um conhecimento profundo da linguagem de comando da impressora, o que a torna menos adequada para tarefas simples de impressão de documentos.
-
Específico da plataforma: Depende dos servidores de spooler de impressão do Windows, o que limita sua aplicabilidade em diferentes plataformas.
-
Sem processamento de documentos: apenas transmissão de bytes sem recursos de renderização.
-
Controle limitado: Opções mínimas de configuração de trabalhos de impressão.
Comparação entre Impressão bruta e IronPDF
| Recurso | Impressão bruta | IronPDF |
|---|---|---|
| Funcionalidade | Envia os dados brutos de impressão diretamente para a impressora. | Criação e manipulação abrangentes de PDFs |
| Caso de uso | Impressão especializada, como etiquetas | Gestão e criação geral de documentos |
| Dependência de plataforma | Específico paraWindows | Multiplataforma |
| Complexidade | De baixo nível, requer conhecimento de comandos de impressora. | API de alto nível e fácil de usar |
| Criação de PDF | Não | Sim |
| Criar PDF a partir de HTML | Não | Sim |
| Criar PDF a partir de um URL | Não | Sim |
| Editar/Modificar PDFs | Não | Sim |
| Unir/Dividir PDFs | Não | Sim |
| Imprimir PDF existente | Sim (bytes brutos) | Sim (API de alto nível) |
| Controle de impressão | Básico | Opções completas |
| Ideal para | Necessidades de acesso direto à impressora | Tarefas relacionadas a PDF em aplicativos web e desktop |
| Flexibilidade | Limitado devido ao processamento de bytes brutos | Abrangente e com múltiplas funcionalidades. |
Em nítido contraste com o RawPrint, o IronPDF oferece uma API robusta e versátil para lidar com PDFs de forma abrangente. Como um nome consagrado no ambiente .NET , o IronPDF permite que os desenvolvedores criem, editem e convertam PDFs sem esforço em diversas plataformas.
Para equipes mirando o .NET moderno,IronPDF fornece compatibilidade cross-platform que RawPrint, por design, não oferece.
Antes de começar
Pré-requisitos
- Ambiente .NET : .NET Framework 4.6.2+ ou .NET Core 3.1+ / .NET 5/6/7/8/9+
- Acesso ao NuGet : Capacidade de instalar pacotes NuGet.
- Licença do IronPDF: Obtenha sua chave de licença em IronPDF
Alterações no pacote NuGet
# Remove RawPrint
dotnet remove package RawPrint
# Install IronPDF
dotnet add package IronPdf
Configuração de licença
// 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"Encontre o uso do RawPrint
# Identify all Impressão bruta usage
grep -r "using RawPrint" --include="*.cs" .
grep -r "PrintRawFile\|PrintRawStream" --include="*.cs" .
Nota: wrappers de P/Invoke feitos manualmente em torno de winspool.Drv às vezes usam o nome da classe RawPrinterHelper e parecem superficialmente semelhantes ao uso de RawPrint, mas não são o pacote - eles chamam o spooler do Win32 diretamente. O próprio pacote só expõe IPrinter com PrintRawFile e PrintRawStream.
Referência completa da API
Alterações de namespace
// Before: RawPrint
using RawPrint;
// After: IronPDF
using IronPdf;// Before: RawPrint
using RawPrint;
// After: IronPDF
using IronPdf;Imports IronPdfImports IronPdfMapeamentos da API principal
| RawPrint (API pública real) | IronPDF | Notas |
|---|---|---|
new Printer() / IPrinter | new ChromePdfRenderer() / PdfDocument | RawPrint envia bytes;IronPDF gera PDFs |
printer.PrintRawFile(name, path, paused) | PdfDocument.FromFile(path).Print() | IronPDF re-renderiza para o sistema de impressão do OS; não RAW |
printer.PrintRawStream(name, stream, doc, paused) | new PdfDocument(stream).Print() | Mesma ressalva |
evento printer.OnJobCreated | s/n | Use opções de impressão do IronPDF em vez disso |
| s/n | ChromePdfRenderer.RenderHtmlAsPdf() | Criar PDFs |
| s/n | PdfDocument.Merge() | Mesclar PDFs |
| s/n | pdf.ApplyWatermark() | Adicionar marcas d'água |
IronPDF imprime entregando o documento ao sistema operacional, não transmitindo bytes crus para o spooler. Se sua impressora requer o tipo de dados RAW (ESC/POS, ZPL, certos fluxos de trabalho PCL), esse é o campo do Impressão bruta e IronPDF não pode substituí-lo.
Exemplos de migração de código
Exemplo 1: Conversão de HTML para PDF
Antes (Impressão Bruta):
// NuGet: Install-Package RawPrint
using System;
using System.IO;
using System.Text;
using RawPrint;
class Program
{
static void Main()
{
// Impressão bruta cannot convert HTML to PDF. Sending raw HTML bytes to a printer just
// prints the HTML source as text — the markup is not rendered.
string html = "<html><body><h1>Hello World</h1></body></html>";
byte[] data = Encoding.ASCII.GetBytes(html);
IPrinter printer = new Printer();
using (var stream = new MemoryStream(data))
{
// PrintRawStream(printerName, stream, documentName, paused)
printer.PrintRawStream("Microsoft Print to PDF", stream, "HTML Document", false);
}
Console.WriteLine("Raw HTML bytes sent to spooler (not rendered).");
}
}// NuGet: Install-Package RawPrint
using System;
using System.IO;
using System.Text;
using RawPrint;
class Program
{
static void Main()
{
// Impressão bruta cannot convert HTML to PDF. Sending raw HTML bytes to a printer just
// prints the HTML source as text — the markup is not rendered.
string html = "<html><body><h1>Hello World</h1></body></html>";
byte[] data = Encoding.ASCII.GetBytes(html);
IPrinter printer = new Printer();
using (var stream = new MemoryStream(data))
{
// PrintRawStream(printerName, stream, documentName, paused)
printer.PrintRawStream("Microsoft Print to PDF", stream, "HTML Document", false);
}
Console.WriteLine("Raw HTML bytes sent to spooler (not rendered).");
}
}Imports System
Imports System.IO
Imports System.Text
Imports RawPrint
Module Program
Sub Main()
' Impressão bruta cannot convert HTML to PDF. Sending raw HTML bytes to a printer just
' prints the HTML source as text — the markup is not rendered.
Dim html As String = "<html><body><h1>Hello World</h1></body></html>"
Dim data As Byte() = Encoding.ASCII.GetBytes(html)
Dim printer As IPrinter = New Printer()
Using stream = New MemoryStream(data)
' PrintRawStream(printerName, stream, documentName, paused)
printer.PrintRawStream("Microsoft Print to PDF", stream, "HTML Document", False)
End Using
Console.WriteLine("Raw HTML bytes sent to spooler (not rendered).")
End Sub
End ModuleImports System
Imports System.IO
Imports System.Text
Imports RawPrint
Module Program
Sub Main()
' Impressão bruta cannot convert HTML to PDF. Sending raw HTML bytes to a printer just
' prints the HTML source as text — the markup is not rendered.
Dim html As String = "<html><body><h1>Hello World</h1></body></html>"
Dim data As Byte() = Encoding.ASCII.GetBytes(html)
Dim printer As IPrinter = New Printer()
Using stream = New MemoryStream(data)
' PrintRawStream(printerName, stream, documentName, paused)
printer.PrintRawStream("Microsoft Print to PDF", stream, "HTML Document", False)
End Using
Console.WriteLine("Raw HTML bytes sent to spooler (not rendered).")
End Sub
End ModuleApós (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 html = "<html><body><h1>Hello World</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
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 html = "<html><body><h1>Hello World</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF created successfully");
}
}Imports IronPdf
Imports System
Class Program
Shared Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Hello World</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF created successfully")
End Sub
End ClassImports IronPdf
Imports System
Class Program
Shared Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Hello World</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF created successfully")
End Sub
End ClassA incompatibilidade arquitetônica é visível até mesmo com a API amigável do pacote: Impressão bruta envia bytes para um spoolerWindowscom o tipo de dados RAW, então entregar HTML apenas faz a impressora imprimir o texto de origem. O ChromePdfRenderer do IronPDF realmente renderiza a marcação. Veja a documentação de HTML para PDF para exemplos completos.
Exemplo 2: Conversão de URL para PDF
Antes (Impressão Bruta):
// NuGet: Install-Package RawPrint
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using RawPrint;
class Program
{
static void Main()
{
// Impressão bruta cannot fetch a URL or render a web page; downloading the HTML and
// shipping it to the spooler just prints the raw HTML source.
using (var client = new HttpClient())
{
string htmlSource = client.GetStringAsync("https://example.com").GetAwaiter().GetResult();
byte[] data = Encoding.UTF8.GetBytes(htmlSource);
IPrinter printer = new Printer();
using (var stream = new MemoryStream(data))
{
printer.PrintRawStream("Microsoft Print to PDF", stream, "Web Page", false);
}
Console.WriteLine("Raw HTML sent to spooler (not a rendered PDF).");
}
}
}// NuGet: Install-Package RawPrint
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using RawPrint;
class Program
{
static void Main()
{
// Impressão bruta cannot fetch a URL or render a web page; downloading the HTML and
// shipping it to the spooler just prints the raw HTML source.
using (var client = new HttpClient())
{
string htmlSource = client.GetStringAsync("https://example.com").GetAwaiter().GetResult();
byte[] data = Encoding.UTF8.GetBytes(htmlSource);
IPrinter printer = new Printer();
using (var stream = new MemoryStream(data))
{
printer.PrintRawStream("Microsoft Print to PDF", stream, "Web Page", false);
}
Console.WriteLine("Raw HTML sent to spooler (not a rendered PDF).");
}
}
}Imports System
Imports System.IO
Imports System.Net.Http
Imports System.Text
Imports RawPrint
Module Program
Sub Main()
' Impressão bruta cannot fetch a URL or render a web page; downloading the HTML and
' shipping it to the spooler just prints the raw HTML source.
Using client = New HttpClient()
Dim htmlSource As String = client.GetStringAsync("https://example.com").GetAwaiter().GetResult()
Dim data As Byte() = Encoding.UTF8.GetBytes(htmlSource)
Dim printer As IPrinter = New Printer()
Using stream = New MemoryStream(data)
printer.PrintRawStream("Microsoft Print to PDF", stream, "Web Page", False)
End Using
Console.WriteLine("Raw HTML sent to spooler (not a rendered PDF).")
End Using
End Sub
End ModuleImports System
Imports System.IO
Imports System.Net.Http
Imports System.Text
Imports RawPrint
Module Program
Sub Main()
' Impressão bruta cannot fetch a URL or render a web page; downloading the HTML and
' shipping it to the spooler just prints the raw HTML source.
Using client = New HttpClient()
Dim htmlSource As String = client.GetStringAsync("https://example.com").GetAwaiter().GetResult()
Dim data As Byte() = Encoding.UTF8.GetBytes(htmlSource)
Dim printer As IPrinter = New Printer()
Using stream = New MemoryStream(data)
printer.PrintRawStream("Microsoft Print to PDF", stream, "Web Page", False)
End Using
Console.WriteLine("Raw HTML sent to spooler (not a rendered PDF).")
End Using
End Sub
End ModuleApós (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var renderer = new ChromePdfRenderer();
// Render a live website directly to PDF with full CSS, JavaScript, and images
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("webpage.pdf");
Console.WriteLine("Website rendered to PDF successfully");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var renderer = new ChromePdfRenderer();
// Render a live website directly to PDF with full CSS, JavaScript, and images
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("webpage.pdf");
Console.WriteLine("Website rendered to PDF successfully");
}
}Imports IronPdf
Imports System
Class Program
Shared Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer = New ChromePdfRenderer()
' Render a live website directly to PDF with full CSS, JavaScript, and images
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
pdf.SaveAs("webpage.pdf")
Console.WriteLine("Website rendered to PDF successfully")
End Sub
End ClassImports IronPdf
Imports System
Class Program
Shared Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer = New ChromePdfRenderer()
' Render a live website directly to PDF with full CSS, JavaScript, and images
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
pdf.SaveAs("webpage.pdf")
Console.WriteLine("Website rendered to PDF successfully")
End Sub
End ClassRawPrint não pode renderizar páginas da web - ele apenas envia bytes para o spooler. Baixar HTML e empurrá-lo resulta na impressora imprimindo o texto de origem, não o conteúdo renderizado. O RenderUrlAsPdf() do IronPDF captura a página web totalmente renderizada com CSS, JavaScript e imagens. Saiba mais em nossos tutoriais .
Exemplo 3: Formatação de Documentos
Antes (Impressão Bruta):
// NuGet: Install-Package RawPrint
using System;
using System.IO;
using System.Text;
using RawPrint;
class Program
{
static void Main()
{
// Impressão bruta has no concept of fonts, margins, or layout — formatting must be
// expressed in the printer's own command language (PCL, PostScript, ESC/POS, ZPL).
// Example: a tiny PCL5 stream that selects portrait and a 16.66cpi font.
string pclCommands = "\x1B&l0O\x1B(s0p16.66h8.5v0s0b3T";
string text = "Plain text document - formatting must be expressed in printer command language";
byte[] data = Encoding.ASCII.GetBytes(pclCommands + text);
IPrinter printer = new Printer();
using (var stream = new MemoryStream(data))
{
printer.PrintRawStream("HP LaserJet", stream, "Raw Document", false);
}
}
}// NuGet: Install-Package RawPrint
using System;
using System.IO;
using System.Text;
using RawPrint;
class Program
{
static void Main()
{
// Impressão bruta has no concept of fonts, margins, or layout — formatting must be
// expressed in the printer's own command language (PCL, PostScript, ESC/POS, ZPL).
// Example: a tiny PCL5 stream that selects portrait and a 16.66cpi font.
string pclCommands = "\x1B&l0O\x1B(s0p16.66h8.5v0s0b3T";
string text = "Plain text document - formatting must be expressed in printer command language";
byte[] data = Encoding.ASCII.GetBytes(pclCommands + text);
IPrinter printer = new Printer();
using (var stream = new MemoryStream(data))
{
printer.PrintRawStream("HP LaserJet", stream, "Raw Document", false);
}
}
}Imports System.IO
Imports System.Text
Imports RawPrint
Module Program
Sub Main()
' Impressão bruta has no concept of fonts, margins, or layout — formatting must be
' expressed in the printer's own command language (PCL, PostScript, ESC/POS, ZPL).
' Example: a tiny PCL5 stream that selects portrait and a 16.66cpi font.
Dim pclCommands As String = ChrW(&H1B) & "&l0O" & ChrW(&H1B) & "(s0p16.66h8.5v0s0b3T"
Dim text As String = "Plain text document - formatting must be expressed in printer command language"
Dim data As Byte() = Encoding.ASCII.GetBytes(pclCommands & text)
Dim printer As IPrinter = New Printer()
Using stream = New MemoryStream(data)
printer.PrintRawStream("HP LaserJet", stream, "Raw Document", False)
End Using
End Sub
End ModuleImports System.IO
Imports System.Text
Imports RawPrint
Module Program
Sub Main()
' Impressão bruta has no concept of fonts, margins, or layout — formatting must be
' expressed in the printer's own command language (PCL, PostScript, ESC/POS, ZPL).
' Example: a tiny PCL5 stream that selects portrait and a 16.66cpi font.
Dim pclCommands As String = ChrW(&H1B) & "&l0O" & ChrW(&H1B) & "(s0p16.66h8.5v0s0b3T"
Dim text As String = "Plain text document - formatting must be expressed in printer command language"
Dim data As Byte() = Encoding.ASCII.GetBytes(pclCommands & text)
Dim printer As IPrinter = New Printer()
Using stream = New MemoryStream(data)
printer.PrintRawStream("HP LaserJet", stream, "Raw Document", False)
End Using
End Sub
End ModuleApós (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 html = @"
<html>
<head>
<style>
body { font-family: Arial; margin: 40px; }
h1 { color: #2c3e50; font-size: 24px; }
p { line-height: 1.6; color: #34495e; }
.highlight { background-color: yellow; font-weight: bold; }
</style>
</head>
<body>
<h1>Formatted Document</h1>
<p>This is a <span class='highlight'>beautifully formatted</span> document with CSS styling.</p>
<p>Complex layouts, fonts, colors, and images are fully supported.</p>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("formatted.pdf");
Console.WriteLine("Formatted 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 html = @"
<html>
<head>
<style>
body { font-family: Arial; margin: 40px; }
h1 { color: #2c3e50; font-size: 24px; }
p { line-height: 1.6; color: #34495e; }
.highlight { background-color: yellow; font-weight: bold; }
</style>
</head>
<body>
<h1>Formatted Document</h1>
<p>This is a <span class='highlight'>beautifully formatted</span> document with CSS styling.</p>
<p>Complex layouts, fonts, colors, and images are fully supported.</p>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("formatted.pdf");
Console.WriteLine("Formatted PDF created successfully");
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Imports System
Module Program
Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer = New ChromePdfRenderer()
Dim html As String = "
<html>
<head>
<style>
body { font-family: Arial; margin: 40px; }
h1 { color: #2c3e50; font-size: 24px; }
p { line-height: 1.6; color: #34495e; }
.highlight { background-color: yellow; font-weight: bold; }
</style>
</head>
<body>
<h1>Formatted Document</h1>
<p>This is a <span class='highlight'>beautifully formatted</span> document with CSS styling.</p>
<p>Complex layouts, fonts, colors, and images are fully supported.</p>
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("formatted.pdf")
Console.WriteLine("Formatted PDF created successfully")
End Sub
End Module' NuGet: Install-Package IronPdf
Imports IronPdf
Imports System
Module Program
Sub Main()
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer = New ChromePdfRenderer()
Dim html As String = "
<html>
<head>
<style>
body { font-family: Arial; margin: 40px; }
h1 { color: #2c3e50; font-size: 24px; }
p { line-height: 1.6; color: #34495e; }
.highlight { background-color: yellow; font-weight: bold; }
</style>
</head>
<body>
<h1>Formatted Document</h1>
<p>This is a <span class='highlight'>beautifully formatted</span> document with CSS styling.</p>
<p>Complex layouts, fonts, colors, and images are fully supported.</p>
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("formatted.pdf")
Console.WriteLine("Formatted PDF created successfully")
End Sub
End ModuleCom RawPrint, formatação além de bytes simples significa criar sequências de comandos de impressora como "\x1B&l0O\x1B(s0p16.66h8.5v0s0b3T" manualmente e conhecer o dialeto PCL ou PostScript da impressora alvo.IronPDF usa HTML e CSS padrão - layouts complexos, fontes, cores, e imagens são totalmente suportados sem conhecimento específico da impressora.
Resumo da comparação de recursos
| Recurso | Impressão bruta | IronPDF |
|---|---|---|
| Criação de PDF | ||
| HTML para PDF | Não | Sim |
| URL para PDF | Não | Sim |
| Criar do zero | Não | Sim |
| Manipulação de PDF | ||
| Mesclar PDFs | Não | Sim |
| Dividir PDFs | Não | Sim |
| Adicionar marcas d'água | Não | Sim |
| Editar existente | Não | Sim |
| Impressão | ||
| Empurre bytes RAW para o spooler | Sim | Não |
| ESC/POS, ZPL, PCL bruto | Sim | Não |
| Imprimir via sistema de impressão OS | Não | Sim |
| Plataforma | ||
| Windows | Sim | Sim |
| Linux | Não | Sim |
| macOS | Não | Sim |
| Docker | Não | Sim |
| Outros | ||
| Criptografia / Segurança | Não | Sim |
| Assinaturas digitais | Não | Sim |
| PDF/A | Não | Sim |
Novas funcionalidades após a migração
Após migrar para o IronPDF, você obtém recursos que o Impressão bruta não pode oferecer:
Fusão de PDFs
var pdfs = pdfFiles.Select(f => PdfDocument.FromFile(f)).ToList();
var merged = PdfDocument.Merge(pdfs);
merged.SaveAs("complete.pdf");var pdfs = pdfFiles.Select(f => PdfDocument.FromFile(f)).ToList();
var merged = PdfDocument.Merge(pdfs);
merged.SaveAs("complete.pdf");Dim pdfs = pdfFiles.Select(Function(f) PdfDocument.FromFile(f)).ToList()
Dim merged = PdfDocument.Merge(pdfs)
merged.SaveAs("complete.pdf")Dim pdfs = pdfFiles.Select(Function(f) PdfDocument.FromFile(f)).ToList()
Dim merged = PdfDocument.Merge(pdfs)
merged.SaveAs("complete.pdf")Imprimir com configurações
var pdf = PdfDocument.FromFile("report.pdf");
pdf.Print(new PrintOptions
{
PrinterName = "HP LaserJet",
NumberOfCopies = 2,
DPI = 300,
GrayScale = false
});var pdf = PdfDocument.FromFile("report.pdf");
pdf.Print(new PrintOptions
{
PrinterName = "HP LaserJet",
NumberOfCopies = 2,
DPI = 300,
GrayScale = false
});Dim pdf = PdfDocument.FromFile("report.pdf")
pdf.Print(New PrintOptions With {
.PrinterName = "HP LaserJet",
.NumberOfCopies = 2,
.DPI = 300,
.GrayScale = False
})Dim pdf = PdfDocument.FromFile("report.pdf")
pdf.Print(New PrintOptions With {
.PrinterName = "HP LaserJet",
.NumberOfCopies = 2,
.DPI = 300,
.GrayScale = False
})Criar e imprimir em um único fluxo de trabalho
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
<h1>Invoice #12345</h1>
<p>Customer: John Doe</p>
<p>Amount: $150.00</p>
");
// Print directly
pdf.Print("HP LaserJet");
// Or save first
pdf.SaveAs("invoice.pdf");var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
<h1>Invoice #12345</h1>
<p>Customer: John Doe</p>
<p>Amount: $150.00</p>
");
// Print directly
pdf.Print("HP LaserJet");
// Or save first
pdf.SaveAs("invoice.pdf");Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("
<h1>Invoice #12345</h1>
<p>Customer: John Doe</p>
<p>Amount: $150.00</p>
")
' Print directly
pdf.Print("HP LaserJet")
' Or save first
pdf.SaveAs("invoice.pdf")Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("
<h1>Invoice #12345</h1>
<p>Customer: John Doe</p>
<p>Amount: $150.00</p>
")
' Print directly
pdf.Print("HP LaserJet")
' Or save first
pdf.SaveAs("invoice.pdf")Lista de verificação para migração
Pré-migração
- Identifique todo o uso do Impressão bruta (
PrintRawFile,PrintRawStream) - Classifique cada local de chamada: PDFs indo para impressoras de escritório são candidatos para IronPDF; ESC/POS, ZPL, EPL, ou bytes PCL/PostScript construídos manualmente devem permanecer no RawPrint
- Documente os nomes das impressoras usadas em seu aplicativo - IronPDF imprime através do sistema de impressão do OS, então os nomes devem ainda resolver
- Anote qualquer código externo de criação de PDF que possa ser consolidado.
- Obtenha a chave de licença do IronPDF em IronPDF
Atualizações de código
- Instale o pacote IronPDF:
dotnet add package IronPdf - Remova o Impressão bruta apenas onde não houver canais de bytes brutos remanescentes:
dotnet remove package RawPrint - Substitua pipelines de criar-então-RawPrint por
ChromePdfRenderermaispdf.Print() - Consolide a criação e impressão de PDF em um único fluxo de trabalho no Windows
- Adicionar inicialização de licença na inicialização do aplicativo
Testando
- Impressão de teste nas impressoras de destino
- Verificar a qualidade de impressão
- Teste várias cópias
- Teste de impressão silenciosa
- Verificação multiplataforma, se necessário
Curtis Chau é bacharel em Ciência da Computação (Universidade Carleton) e se especializa em desenvolvimento front-end, com experiência em Node.js, TypeScript, JavaScript e React. Apaixonado por criar interfaces de usuário intuitivas e esteticamente agradáveis, Curtis gosta de trabalhar com frameworks modernos e criar manuais bem estruturados e visualmente atraentes.
Artigos Relacionados



Relatar um problema