Pruebe en producción sin marcas de agua.
Funciona donde lo necesite.
Obtén 30 días de producto totalmente funcional.
Ténlo en funcionamiento en minutos.
Acceso completo a nuestro equipo de asistencia técnica durante la prueba del producto
El ActivePDF Toolkit
es un componente de software utilizado para trabajar con archivos PDF (incluida la generación de archivos PDF desde diferentes fuentes) y establecer sus propiedades (como Encabezado, Pie de página, Margen o Marca de agua).
IronPDF
es una librería PDF para C# que también ofrece estas funciones, con precios competitivos.
Aquí veremos las funciones, ejemplos de código y acciones paso a paso para utilizar ambos componentes de software en un proyecto .NET Visual Studio, para que pueda decidir por sí mismo qué es lo mejor para su aplicación.
Iron Software es un proveedor de componentes líder en el mercado, que ofrece IronPDF para trabajar con archivos PDF. Una forma integral de generar fácilmente archivos PDF a partir de diferentes formatos y establecer todas las propiedades mediante programación. Es el preferido por los desarrolladores debido a la salida consistente, fiable y precisa de archivos PDF utilizando sólo unas pocas líneas de código.
IronPDF está diseñado para C#, .NET, VB, ASPX, ASP.NET, MVC y .NET Core. Es compatible con Visual Studio, NuGet, Linux, Azure, Docker, etc.
ActivePDF es una empresa de software que ofrece muchos componentes para trabajar con archivos PDF. A diferencia del componente único IronPDF, ActivePDF ofrece diferentes soluciones para archivos PDF. Por ejemplo, para reducir el tamaño de los archivos PDF, puedes usar ActivePDF Compressor
. Para crear PDFs a partir de fuentes HTML, usa ActivePDF WebGrabber
.
En este artículo, utilizaremos ActivePDF WebGrabber para compararlo con IronPDF, echémosle un vistazo:
ActivePDF WebGrabber es un componente separado de ActivePDF utilizado específicamente para generar archivos PDF a partir de fuentes HTML como URL, archivo HTML o cadena HTML. También proporciona las funciones para establecer las propiedades de página como Encabezado, Pie de página, Margen, Marca de agua o Marca de libro para crear archivos PDF según nuestros requisitos.
Veamos la comparación entre ambos componentes.
IronPDF | ActivePDF |
---|---|
IronPDF converts HTML sources to PDF files. | ActivePDF converts HTML sources to PDF files. |
IronPDF supports .NET Core. | ActivePDF does not support .NET Core. |
IronPDF supports .NET 4.0 or higher. | ActivePDF supports .NET 4.6.2 or higher. |
IronPDF supports macOS. | ActivePDF does not support macOS. |
IronPDF can apply CSS to set WaterMark properties. | ActivePDF does not support CSS to set WaterMark properties. |
IronPDF can set Paper Orientation of PDF files. | ActivePDF can set Paper Orientation of PDF files. |
IronPDF provides the RenderDelay function to delay the PDF conversion. | ActivePDF provides the TimeoutSpan function to delay the PDF conversion. |
IronPDF provides predefined functions to set Header or Footer. | ActivePDF requires setting Header and Footer by raw HTML and CSS. |
IronPDF provides a predefined function to draw a horizontal line to separate content. | ActivePDF does not provide a line to separate headers and footers. |
To save the PDF file, we can set the directory and file name in one line. | We have to set file directory and file name separately. |
Need to write fewer lines of code with a simple programming structure. | Need to write many lines of code. |
License starts from $749 . | License starts from $1180 . |
Puede añadir la biblioteca IronPDF a su proyecto de dos formas distintas, sin que importe cuál adopte.
Navega para IronPDF
, luego instálalo.
Alternativamente:
tools
consola del administrador de paquetes
Install-Package IronPdf
También podemos descargar IronPDF.dll, luego agregar su referencia en el proyecto.
Si puedes acceder a IronPDF
escribiendo using IronPdf;
namespace, significa que IronPDF se ha importado correctamente en tu proyecto y está listo para su uso.
Descargue WebGrabber-install.exe y seleccione el archivo a descargar. Una vez que se haya descargado, haga doble clic en el archivo descargado. Luego solicite una clave de activación de ActivePDF para usar con la siguiente clave de evaluación de 15 días: 001-AEALX-LC6Z5-7YD95-S3D8J-3LR25.
Tras la instalación, vaya al siguiente directorio:
C:\Program Files\ActivePDF\WebGrabber\bin\
En este directorio, obtienes el archivo APWebGrabber.Net45.dll
. Agrega su referencia en tu proyecto de Visual Studio.
Ahora, si puedes acceder a WebGrabber
escribiendo using APWebGrabber;
namespace, significa que ActivePDF WebGrabber se ha importado exitosamente en tu proyecto y puedes usarlo.
Documentación de ActivePDF está disponible para obtener más información sobre la instalación de ActivePDF WebGrabber.
Hemos visto la introducción de estos dos componentes y sus procesos de instalación, y ahora comenzaremos la comparación realizando diferentes tareas utilizando ambos. Esto nos permitirá entender la estructura de programación de ambos y decidir cuál es el mejor para nuestros proyectos. Para una mejor comprensión, ejecutaremos un caso de uso específico en cada tarea y proporcionaremos el código utilizado para implementarlo.
En la primera comparación, tomaremos un caso de uso en el que necesitamos crear un archivo PDF mediante una cadena HTML y guardarlo en la ubicación de destino. En primer lugar, empezamos a implementar este caso de uso mediante IronPDF:
/**
HTML String to PDF
anchor-html-string-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to IronPDF</h2> ";
//convert HTML string to PDF file
using var PDF = converter.RenderHtmlAsPdf(html);
//Save the file
PDF.SaveAs("E:/sample.pdf");
}
/**
HTML String to PDF
anchor-html-string-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to IronPDF</h2> ";
//convert HTML string to PDF file
using var PDF = converter.RenderHtmlAsPdf(html);
//Save the file
PDF.SaveAs("E:/sample.pdf");
}
'''
'''HTML String to PDF
'''anchor-html-string-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New ChromePdfRenderer()
'HTML Source
Dim html As String = "<h1>Hello World!</h1> <h2>Welcome to IronPDF</h2> "
'convert HTML string to PDF file
Dim PDF = converter.RenderHtmlAsPdf(html)
'Save the file
PDF.SaveAs("E:/sample.pdf")
End Sub
Salida:
El código anterior creará un archivo PDF sample.pdf
en Disco local E:
y su captura de pantalla es:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to ActivePDF WebGrabber</h2>";
//assign source html to WebGrabber
wg.CreateFromHTMLText = html;
//specify file directory
wg.OutputDirectory = "E:/";
// file name
wg.NewDocumentName = "sample.pdf";
//convert source HTML to PDF file
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML Source
string html = "<h1>Hello World!</h1> <h2>Welcome to ActivePDF WebGrabber</h2>";
//assign source html to WebGrabber
wg.CreateFromHTMLText = html;
//specify file directory
wg.OutputDirectory = "E:/";
// file name
wg.NewDocumentName = "sample.pdf";
//convert source HTML to PDF file
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'HTML Source
Dim html As String = "<h1>Hello World!</h1> <h2>Welcome to ActivePDF WebGrabber</h2>"
'assign source html to WebGrabber
wg.CreateFromHTMLText = html
'specify file directory
wg.OutputDirectory = "E:/"
' file name
wg.NewDocumentName = "sample.pdf"
'convert source HTML to PDF file
wg.ConvertToPDF()
End Sub
La siguiente captura de pantalla es el archivo sample.pdf
recién generado a partir de este código:
En esta comparación, tomamos el caso de uso en el que necesitamos generar un archivo PDF a partir de un archivo HTML llamado myHtmlFile.html
que existe en el directorio E:/
, y tiene el siguiente código HTML y CSS:
<html>
<style>
li{
font-size:x-large;
color: magenta;
font-style: italic;
}
</style>
<body>
<h1>I am Heading</h1>
<h2>Items List:</h2>
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</body>
</html>
<html>
<style>
li{
font-size:x-large;
color: magenta;
font-style: italic;
}
</style>
<body>
<h1>I am Heading</h1>
<h2>Items List:</h2>
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</body>
</html>
Ahora, convertiremos el archivo myHtmlFile.html
a un archivo PDF utilizando ambos componentes. Empecemos por IronPDF.
/**
HTML File to PDF
anchor-html-file-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new IronPdf.ChromePdfRenderer();
//render html file to pdf
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
/**
HTML File to PDF
anchor-html-file-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new IronPdf.ChromePdfRenderer();
//render html file to pdf
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''HTML File to PDF
'''anchor-html-file-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New IronPdf.ChromePdfRenderer()
'render html file to pdf
Dim PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html")
'save to target location
PDF.SaveAs("E:/Sample.pdf")
End Sub
La siguiente captura de pantalla es del archivo Sample.pdf
recién generado utilizando el código anterior:
Podemos ver que la página HTML myHtmlFile.html
se convirtió con éxito en el archivo PDF Sample.pdf
, y los estilos CSS también se aplicaron.
Lea la documentación de IronPDF para obtener más información sobre cómo podemos usar IronPDF en nuestro proyecto .NET.
Realicemos la misma tarea utilizando ActivePDF WebGrabber.
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify file path to be converted
wg.URL = "E:/myHtmlFile.html";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//newly generated file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify file path to be converted
wg.URL = "E:/myHtmlFile.html";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//newly generated file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'specify file path to be converted
wg.URL = "E:/myHtmlFile.html"
'specify the directory for newly generated file
wg.OutputDirectory = "E:/"
'newly generated file name
wg.NewDocumentName = "Sample.pdf"
'convert HTML file to PDF
wg.ConvertToPDF()
End Sub
La siguiente captura de pantalla es del archivo Sample.pdf
recién generado, utilizando el código anterior:
Supongamos que tenemos una URL https://yandex.com/ y queremos generar un archivo PDF de su página web. Para ello, ambos componentes proporcionan una función. En primer lugar, veremos cómo puede hacerlo IronPDF.
/**
URL to PDF
anchor-url-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//Specify URL
using var PDF = converter.RenderUrlAsPdf("https://yandex.com/");
//Save the file
PDF.SaveAs("E:/Sample.pdf");
}
/**
URL to PDF
anchor-url-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//Specify URL
using var PDF = converter.RenderUrlAsPdf("https://yandex.com/");
//Save the file
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''URL to PDF
'''anchor-url-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New ChromePdfRenderer()
'Specify URL
Dim PDF = converter.RenderUrlAsPdf("https://yandex.com/")
'Save the file
PDF.SaveAs("E:/Sample.pdf")
End Sub
La siguiente captura de pantalla es del archivo Sample.pdf
recién generado por el código anterior
Puede visitar la página web de la muestra de URL para comparar y ver qué tan exactamente coincide el archivo de IronPDF.
Ahora, haremos la misma tarea utilizando ActivePDF WebGrabber.
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify URL
wg.URL = "https://yandex.com/";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert specified URL webpage to PDF
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//specify URL
wg.URL = "https://yandex.com/";
//specify the directory for newly generated file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert specified URL webpage to PDF
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'specify URL
wg.URL = "https://yandex.com/"
'specify the directory for newly generated file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert specified URL webpage to PDF
wg.ConvertToPDF()
End Sub
La siguiente captura de pantalla es del archivo Sample.pdf
recién generado por el código anterior:
En esta comparación, crearemos un archivo PDF utilizando una cadena HTML, y luego añadiremos una Marca de Agua en el centro de la página. Empecemos por IronPDF.
IronPDF proporciona la siguiente función para añadir WaterMark:
WatermarkPage(Cadena HTML WaterMark, PageIndexToWaterMark, WaterMarkLocation, Opacity, Rotation, Hyperlink)
Podemos usar el WaterMarkLocation
para establecer la marca de agua en las siguientes posiciones:
EsquinaSuperiorIzquierda
Centro Superior
Arriba a la derecha
MiddleLeft
CentroMedio
Centrado a la derecha
InferiorIzquierda
FondoCentro
InferiorDerecha
Veamos cómo utilizar las funciones anteriores para establecer la marca de agua:
/**
Watermark PDF
anchor-watermark-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//source html string
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//add above string as PDF file content
using var PDF = converter.RenderHtmlAsPdf(html);
//HTML string for WaterMark
string WMStr = "<h1 style='color:red'>WaterMark</h1>";
//add WaterMark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter, 100, -45, "");
//save the document
PDF.SaveAs("E:/Sample.pdf");
}
/**
Watermark PDF
anchor-watermark-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create rendering converter
var converter = new ChromePdfRenderer();
//source html string
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//add above string as PDF file content
using var PDF = converter.RenderHtmlAsPdf(html);
//HTML string for WaterMark
string WMStr = "<h1 style='color:red'>WaterMark</h1>";
//add WaterMark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter, 100, -45, "");
//save the document
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''Watermark PDF
'''anchor-watermark-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create rendering converter
Dim converter = New ChromePdfRenderer()
'source html string
Dim html As String = "<h1 style='text-align:center'>WaterMark Example</h1>"
'add above string as PDF file content
Dim PDF = converter.RenderHtmlAsPdf(html)
'HTML string for WaterMark
Dim WMStr As String = "<h1 style='color:red'>WaterMark</h1>"
'add WaterMark
PDF.WatermarkPage(WMStr, 0, PdfDocument.WaterMarkLocation.MiddleCenter, 100, -45, "")
'save the document
PDF.SaveAs("E:/Sample.pdf")
End Sub
La siguiente captura de pantalla es del archivo Sample.pdf
recién generado por el código anterior:
Podemos añadir cualquier tipo de WaterMark y establecer sus propiedades mediante CSS. Ahora, haremos la misma tarea utilizando ActivePDF WebGrabber.
ActivePDF WebGrabber no proporciona una función específica para WaterMark, a diferencia de IronPDF. Pero podemos usar la función AddStampText()
como una solución alternativa para este propósito:
AddStampText(float x, float y, string stampText);
stampText es el texto real del TextStamp.
Nota: ActivePDF WebGrabber no admite el estilo CSS para TextStamp. Debemos configurarlo mediante otras funciones proporcionadas de la siguiente manera:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML source for Page content
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//assign page content source
wg.CreateFromHTMLText = html;
//add text stamp as WaterMark
wg.AddStampText(270.0f, 350.0f, "WaterMark");
//specify WaterMark's font size
wg.StampFontSize = 20;
//specify WaterMark's font family
wg.StampFont = "Times New Roman";
//specify WaterMark's opacity
wg.StampFontTransparency = 1f;
//specify WaterMark's rotation
wg.StampRotation = 45.0f;
//specify WaterMark's color
wg.StampColorNET = new ADK.PDF.Color() { Red = 255, Green = 0, Blue = 0, Gray = 0 };
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//HTML source for Page content
string html = "<h1 style='text-align:center'>WaterMark Example</h1>";
//assign page content source
wg.CreateFromHTMLText = html;
//add text stamp as WaterMark
wg.AddStampText(270.0f, 350.0f, "WaterMark");
//specify WaterMark's font size
wg.StampFontSize = 20;
//specify WaterMark's font family
wg.StampFont = "Times New Roman";
//specify WaterMark's opacity
wg.StampFontTransparency = 1f;
//specify WaterMark's rotation
wg.StampRotation = 45.0f;
//specify WaterMark's color
wg.StampColorNET = new ADK.PDF.Color() { Red = 255, Green = 0, Blue = 0, Gray = 0 };
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'HTML source for Page content
Dim html As String = "<h1 style='text-align:center'>WaterMark Example</h1>"
'assign page content source
wg.CreateFromHTMLText = html
'add text stamp as WaterMark
wg.AddStampText(270.0F, 350.0F, "WaterMark")
'specify WaterMark's font size
wg.StampFontSize = 20
'specify WaterMark's font family
wg.StampFont = "Times New Roman"
'specify WaterMark's opacity
wg.StampFontTransparency = 1F
'specify WaterMark's rotation
wg.StampRotation = 45.0F
'specify WaterMark's color
wg.StampColorNET = New ADK.PDF.Color() With {
.Red = 255,
.Green = 0,
.Blue = 0,
.Gray = 0
}
'specify directory for newly created file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert above sources to PDF file
wg.ConvertToPDF()
End Sub
La siguiente captura de pantalla es del archivo Sample.pdf
recién generado.
Supongamos que tenemos una simple página web llamada myHtmlFile.html
en nuestro Disco Local E
, que tiene un ancho del 100%
y un borde
de color negro
. Generaremos un archivo PDF a partir de él y estableceremos el Margen de página. Empecemos por IronPDF.
Para establecer los márgenes, IronPDF proporciona la clase ChromePdfRenderOptions
, que tiene las siguientes propiedades:
MarginBottom para establecer un margen desde la parte inferior de la página.
Nota: De forma predeterminada, IronPDF establece un margen de 20mm
desde la izquierda, arriba, derecha y abajo para que la página sea más legible. Podemos establecerlo en 0mm
si no lo necesitamos.
/**
Set Margins
anchor-margins-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new ChromePdfRenderer();
//specify left Margin
converter.RenderingOptions.MarginLeft = 50;
//specify top Margin
converter.RenderingOptions.MarginTop = 40;
//render html file to PDF
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to the target location
PDF.SaveAs("E:/Sample.pdf");
}
/**
Set Margins
anchor-margins-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new ChromePdfRenderer();
//specify left Margin
converter.RenderingOptions.MarginLeft = 50;
//specify top Margin
converter.RenderingOptions.MarginTop = 40;
//render html file to PDF
using var PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html");
//save to the target location
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''Set Margins
'''anchor-margins-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create html to PDF converter
Dim converter = New ChromePdfRenderer()
'specify left Margin
converter.RenderingOptions.MarginLeft = 50
'specify top Margin
converter.RenderingOptions.MarginTop = 40
'render html file to PDF
Dim PDF = converter.RenderHTMLFileAsPdf("E:/myHtmlFile.html")
'save to the target location
PDF.SaveAs("E:/Sample.pdf")
End Sub
La siguiente captura de pantalla es del archivo Sample.pdf
recién generado por el código anterior:
Se puede ver que la página PDF tiene 50mm
desde el lado izquierdo, 40
desde la parte superior, y el margen izquierdo es de 20mm
que es por defecto
. Podemos ver lo simple que es establecer el margen de cualquier lado utilizando la clase ChromePdfRenderOptions
de IronPDF.
Lea más sobre Configuración de Generación de PDF para más detalles: cómo trabajar con márgenes y otras propiedades del archivo PDF.
Ahora, estableceremos el Margen de la página utilizando ActivePDF WebGrabber.
Para establecer los márgenes de la página, ActivePDF WebGrabber proporciona la función SetMargins()
, y podemos usarla de la siguiente manera:
SetMargins(Margen Superior, Margen Inferior, Margen Izquierdo, Margen Derecho)
Utilizaremos esta función para establecer el margen de página:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber()
//specify source HTML file path
wg.URL = "E:/myHtmlFile.html";
//Margins
wg.SetMargins(1, 0, 1.5f, 0);
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber()
//specify source HTML file path
wg.URL = "E:/myHtmlFile.html";
//Margins
wg.SetMargins(1, 0, 1.5f, 0);
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert HTML file to PDF
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
'INSTANT VB WARNING: An assignment within expression was extracted from the following statement:
'ORIGINAL LINE: WebGrabber wg = new WebGrabber() wg.URL = "E:/myHtmlFile.html";
New WebGrabber() wg.URL = "E:/myHtmlFile.html"
Dim wg As New WebGrabber() wg.URL
'Margins
wg.SetMargins(1, 0, 1.5F, 0)
'specify directory for newly created file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert HTML file to PDF
wg.ConvertToPDF()
End Sub
La siguiente captura de pantalla es del archivo Sample.pdf
recién generado por el código anterior:
Podemos ver que la página PDF tiene un Margen de 1.5f
del lado izquierdo y 1f
desde la parte superior. Utilizando ambos componentes, podemos establecer fácilmente los márgenes de página según nuestras necesidades.
Lea más sobre cómo establecer márgenes con ActivePDF.
En esta comparación, veremos cómo establecer el Encabezado y el Pie de página de un archivo PDF. Utilizaremos las funciones y técnicas proporcionadas por ambos componentes, a través de las cuales podemos imprimir encabezados y pies de página personalizados en páginas PDF mediante programación.
IronPDF proporciona las siguientes propiedades, que pueden utilizarse para establecer tanto Encabezados como Pies de página:
DrawDividerLine: dibuja una línea horizontal que separa el contenido de la página del Encabezado o Pie de página.
Podemos utilizar las siguientes funciones predefinidas de IronPDF en llaves {}
para el encabezado o pie de página:
{pdf-title} establece el título del documento.
Veamos el siguiente ejemplo, en el que estableceremos el Encabezado y el Pie de Página utilizando las funciones anteriores:
/**
Set Header Footers
anchor-headers-and-footers-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new IronPdf.ChromePdfRenderer();
//Page Content source
string html = "<h1 style='text-align:center;'>Page Content</h2>";
//Assign source to converter
using var PDF = converter.RenderHtmlAsPdf(html);
//Add Header settings
converter.RenderingOptions.TextHeader = new TextHeaderFooter()
{
LeftText = "Header Text",
RightText = "{date} {time}",
DrawDividerLine=true,
FontSize=13
};
//Add Footer settings
converter.RenderingOptions.TextFooter = new TextHeaderFooter()
{
RightText = "Page {page} of {total-pages}",
FontSize = 12
};
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
/**
Set Header Footers
anchor-headers-and-footers-with-ironpdf
**/
using IronPdf;
static void Main(string [] args)
{
//create html to PDF converter
var converter = new IronPdf.ChromePdfRenderer();
//Page Content source
string html = "<h1 style='text-align:center;'>Page Content</h2>";
//Assign source to converter
using var PDF = converter.RenderHtmlAsPdf(html);
//Add Header settings
converter.RenderingOptions.TextHeader = new TextHeaderFooter()
{
LeftText = "Header Text",
RightText = "{date} {time}",
DrawDividerLine=true,
FontSize=13
};
//Add Footer settings
converter.RenderingOptions.TextFooter = new TextHeaderFooter()
{
RightText = "Page {page} of {total-pages}",
FontSize = 12
};
//save to target location
PDF.SaveAs("E:/Sample.pdf");
}
'''
'''Set Header Footers
'''anchor-headers-and-footers-with-ironpdf
'''*
Imports IronPdf
Shared Sub Main(ByVal args() As String)
'create html to PDF converter
Dim converter = New IronPdf.ChromePdfRenderer()
'Page Content source
Dim html As String = "<h1 style='text-align:center;'>Page Content</h2>"
'Assign source to converter
Dim PDF = converter.RenderHtmlAsPdf(html)
'Add Header settings
converter.RenderingOptions.TextHeader = New TextHeaderFooter() With {
.LeftText = "Header Text",
.RightText = "{date} {time}",
.DrawDividerLine=True,
.FontSize=13
}
'Add Footer settings
converter.RenderingOptions.TextFooter = New TextHeaderFooter() With {
.RightText = "Page {page} of {total-pages}",
.FontSize = 12
}
'save to target location
PDF.SaveAs("E:/Sample.pdf")
End Sub
La siguiente captura de pantalla es del archivo Sample.pdf
recién generado por el código anterior:
Podemos ver que
Header Text
se imprime en el lado izquierdo del encabezado.DateTime
se imprime en el lado derecho del encabezado.Página CurrentPage de TotalPages
en el lado derecho del pie de página.
Lea más sobre cómo establecer propiedades de HTML a PDF utilizando IronPDF.
Utilicemos ahora ActivePDF WebGrabber para establecer encabezados y pies de página:
ActivePDF WebGrabber proporciona las propiedades HeaderHTML
y FooterHTML
para establecer el encabezado y el pie de página respectivamente. El HTML en bruto se pasa a estas propiedades como Cabecera o Pie de Página. A diferencia de IronPDF, ActivePDF WebGrabber no proporciona funciones predefinidas para establecer la alineación del Encabezado y Pie de Página, por lo que tenemos que establecerla utilizando propiedades HTML y CSS como se indica a continuación:
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//Page content source
string html = @"<h1 style='text-align:center;'>Page Content</h2>";
//assign above source to WebGrabber
wg.CreateFromHTMLText = html;
//specify Footer height
wg.FooterHeight = 0.5f;
//Add Footer setting
wg.FooterHTML = "<div style='text-align: right;'>%cp% of %tp%</div>";
//create object for datetime
DateTime now = DateTime.Now;
//specify header height
wg.HeaderHeight = 0.5f;
//Add Header setting
wg.HeaderHTML = "<div style='float: left;'>Header Text</div>";
//append Header settings
wg.HeaderHTML = $"<div style='float: right;'>{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}</div>";
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
using APWebGrabber;
static void Main(string [] args)
{
//Instantiate Object
WebGrabber wg = new WebGrabber();
//Page content source
string html = @"<h1 style='text-align:center;'>Page Content</h2>";
//assign above source to WebGrabber
wg.CreateFromHTMLText = html;
//specify Footer height
wg.FooterHeight = 0.5f;
//Add Footer setting
wg.FooterHTML = "<div style='text-align: right;'>%cp% of %tp%</div>";
//create object for datetime
DateTime now = DateTime.Now;
//specify header height
wg.HeaderHeight = 0.5f;
//Add Header setting
wg.HeaderHTML = "<div style='float: left;'>Header Text</div>";
//append Header settings
wg.HeaderHTML = $"<div style='float: right;'>{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}</div>";
//specify directory for newly created file
wg.OutputDirectory = "E:/";
//specify file name
wg.NewDocumentName = "Sample.pdf";
//convert above sources to PDF file
wg.ConvertToPDF();
}
Imports APWebGrabber
Shared Sub Main(ByVal args() As String)
'Instantiate Object
Dim wg As New WebGrabber()
'Page content source
Dim html As String = "<h1 style='text-align:center;'>Page Content</h2>"
'assign above source to WebGrabber
wg.CreateFromHTMLText = html
'specify Footer height
wg.FooterHeight = 0.5F
'Add Footer setting
wg.FooterHTML = "<div style='text-align: right;'>%cp% of %tp%</div>"
'create object for datetime
Dim now As DateTime = DateTime.Now
'specify header height
wg.HeaderHeight = 0.5F
'Add Header setting
wg.HeaderHTML = "<div style='float: left;'>Header Text</div>"
'append Header settings
wg.HeaderHTML = $"<div style='float: right;'>{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}</div>"
'specify directory for newly created file
wg.OutputDirectory = "E:/"
'specify file name
wg.NewDocumentName = "Sample.pdf"
'convert above sources to PDF file
wg.ConvertToPDF()
End Sub
La siguiente captura de pantalla es del archivo Sample.pdf
recién generado a partir del código anterior:
Lea más sobre cómo configurar encabezados y pies de página con ActivePDF WebGrabber.
DateTime
del framework .NETName | Detail |
---|---|
ActivePDF DocConverter | It is used to convert popular file types to and from PDF format. |
ActivePDF WebGrabber | It grabs the HTML from many sources and converts it to PDF files. |
ActivePDF DocSpace | It provides Batch Process Automation, and a user interface for display, generate, converting, manipulating, and interacting with PDF and other file formats. |
ActivePDF Toolkit | It is used to create, modify, view, extract, manipulate, and automate the document content to and from PDF files. |
ActivePDF Portal | It enables the users to view and modify PDF documents from any source in a standard web browser. |
ActivePDF CADConverter | It is used to convert CAD files into PDF. |
ActivePDF Xtractor | It is used to extract and find the text and images from PDF files. |
ActivePDF Spooler | It allows the developer to print the PDF file page on paper. |
ActivePDF Redactor | It is used to hide sensitive information from the viewer. |
ActivePDF Server | It provides the printing solution for different purposes. |
ActivePDF no proporciona ninguna información sobre sus paquetes en su sitio web de ActivePDF. Para obtener información sobre las licencias, debe contactar a su representante de ventas. Sin embargo, debe saber exactamente qué tipo de licencia de producción está buscando. No facilitan una lista de precios, y aunque los precios empiezan en 1.180 dólares por una licencia anual, pueden ser más altos dependiendo del ámbito de uso y hay que detallarlos para obtener un presupuesto.
IronPDF ofrece precios transparentes con licencias desde $749, con muchas opciones personalizables. Póngase en contacto con el equipo si tiene alguna duda.
Explore la Referencia de la API para la Biblioteca IronPDF C#, incluyendo detalles de todas las características, clases, campos de métodos, espacios de nombres y enums de IronPDF.
Ver la referencia de la API