Cómo Configurar la Impresión en PDF Usando C# | IronPrint

How to Configure Print Settings

This article was translated from English: Does it need improvement?
Translated
View the article in English

A print setting refers to a configuration or set of parameters that dictate how a document or content should be printed. These settings include details such as paper size, orientation (e.g., portrait or landscape), print resolution (dots per inch - DPI), the number of copies, printer selection, margins, and options like grayscale printing. Users can customize these settings to achieve specific printing preferences and requirements.

Quickstart: Configure and Print Using IronPrint Settings

Easily get started by creating a PrintSettings object, setting just a few properties like paper size, orientation, DPI, copies, and grayscale. Then call Printer.Print(...) to apply these settings instantly — no complex setup required.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPrint with NuGet Package Manager

    PM > Install-Package IronPrint

  2. Copy and run this code snippet.

    IronPrint.Printer.Print("document.pdf", new IronPrint.PrintSettings { PaperSize = IronPrint.PaperSize.A4, PaperOrientation = IronPrint.PaperOrientation.Landscape, Dpi = 300, NumberOfCopies = 2, Grayscale = true });
  3. Deploy to test on your live environment

    Start using IronPrint in your project today with a free trial
    arrow pointer

Set Print Settings

To configure print settings, instantiate the PrintSettings class and configure it according to your preferences. In the Print or ShowPrintDialog methods, pass the PrintSettings object as the second parameter. The code example below illustrates this usage.

// Import the necessary namespace for IronPrint
using IronPrint;

// Initialize a new instance of the PrintSettings class
PrintSettings settings = new PrintSettings();

// Configure various print settings
settings.PaperSize = PaperSize.A4;                // Set paper size to A4
settings.PaperOrientation = PaperOrientation.Landscape; // Set paper orientation to Landscape
settings.Dpi = 300;                               // Set print resolution to 300 DPI
settings.NumberOfCopies = 2;                      // Set the number of copies to 2
settings.PrinterName = "MyPrinter";               // Set the name of the printer
settings.PaperMargins = new Margins(10, 10, 10, 10); // Set margins to 10mm on each side
settings.Grayscale = true;                        // Print in grayscale

// Use the PrintSettings in the Print method
IronPrint.Printer.Print(document, settings);
// Import the necessary namespace for IronPrint
using IronPrint;

// Initialize a new instance of the PrintSettings class
PrintSettings settings = new PrintSettings();

// Configure various print settings
settings.PaperSize = PaperSize.A4;                // Set paper size to A4
settings.PaperOrientation = PaperOrientation.Landscape; // Set paper orientation to Landscape
settings.Dpi = 300;                               // Set print resolution to 300 DPI
settings.NumberOfCopies = 2;                      // Set the number of copies to 2
settings.PrinterName = "MyPrinter";               // Set the name of the printer
settings.PaperMargins = new Margins(10, 10, 10, 10); // Set margins to 10mm on each side
settings.Grayscale = true;                        // Print in grayscale

// Use the PrintSettings in the Print method
IronPrint.Printer.Print(document, settings);
' Import the necessary namespace for IronPrint
Imports IronPrint

' Initialize a new instance of the PrintSettings class
Private settings As New PrintSettings()

' Configure various print settings
settings.PaperSize = PaperSize.A4 ' Set paper size to A4
settings.PaperOrientation = PaperOrientation.Landscape ' Set paper orientation to Landscape
settings.Dpi = 300 ' Set print resolution to 300 DPI
settings.NumberOfCopies = 2 ' Set the number of copies to 2
settings.PrinterName = "MyPrinter" ' Set the name of the printer
settings.PaperMargins = New Margins(10, 10, 10, 10) ' Set margins to 10mm on each side
settings.Grayscale = True ' Print in grayscale

' Use the PrintSettings in the Print method
IronPrint.Printer.Print(document, settings)
$vbLabelText   $csharpLabel

Available Print Settings

Explore all available print settings options below:

  • DefaultSettings: Initializes a new instance of the IronPrint.PrintSettings class with default values.
  • PaperSize: Sets the paper size used by the printer. The default value is IronPrint.PaperSize.PrinterDefault.
  • PaperOrientation: Specifies the paper orientation (e.g., Portrait or Landscape). The default value is IronPrint.PaperOrientation.Portrait.
  • Dpi: Represents the intended print resolution in dots per inch. The default value is 300, a common setting used in commercial printing. Remarks: The actual DPI used for printing might be limited by the capabilities of the printer.
  • NumberOfCopies: Indicates the number of identical copies to be generated when printing a document. The default value is 1 copy. Remarks: In certain platforms, limitations may exist that prevent the accurate reproduction of multiple copies. In such cases, the specified value of IronPrint.PrintSettings.NumberOfCopies might be ignored, resulting in only one copy being printed.
  • PrinterName: Specifies the name of the printer to use for printing. The default value is null, meaning the current default printer of the operating system will be used. Remarks: If you choose the printer in a PrintDialog, this setting will be ignored. To obtain the available printer names, you can use IronPrint.Printer.GetPrinterNames or IronPrint.Printer.GetPrinterNamesAsync to fetch the printer name list.
  • PaperMargins: Sets the margins to use for printing in millimeters. The default value is null, indicating the use of the default margins provided by the printer.
  • Grayscale: Indicates whether to print in grayscale. Remarks: The default value is false, indicating an attempt to print in color.
  • Flatten: Flatten the PDF before printing, which is useful for displaying form field values and images. The default value is false, indicating that the PDF will be flattened before printing.
  • Tray: Printer tray used for the printing job. This allows users to specify a particular tray from which paper should be fed into the printer. If you choose the tray in a PrintDialog, this setting will be ignored. To obtain the available tray, you can use IronPrint.Printer.GetPrinterTrays(System.String) or IronPrint.Printer.GetPrinterTraysAsync(System.String). The default value is null, indicating the use of the default tray provided by the printer. This tray selection property is available only in Windows.

Preguntas Frecuentes

¿Cómo puedo configurar la configuración de impresión en C#?

Puede configurar la configuración de impresión en C# utilizando la biblioteca IronPrint. Primero, instancie la clase PrintSettings y establezca sus parámetros deseados, como el tamaño del papel, la orientación, el DPI y más. Después, pase el objeto PrintSettings configurado a los métodos Print o ShowPrintDialog.

¿Qué tamaños de papel están disponibles para imprimir?

IronPrint le permite establecer varios tamaños de papel a través de la propiedad PaperSize de la clase PrintSettings. Por defecto, está configurado en IronPrint.PaperSize.PrinterDefault, pero puede personalizarse a tamaños como A4, Carta y otros.

¿Puedo cambiar la orientación del documento impreso?

Sí, puede cambiar la orientación estableciendo la propiedad PaperOrientation en la clase PrintSettings. Soporta orientaciones Portrait y Landscape.

¿Cómo ajusto la resolución de impresión (DPI)?

En IronPrint, puede ajustar la resolución de impresión estableciendo la propiedad Dpi en la clase PrintSettings. La resolución por defecto es 300 DPI.

¿Es posible imprimir múltiples copias utilizando IronPrint?

Sí, al establecer la propiedad NumberOfCopies en la clase PrintSettings, puede especificar cuántas copias imprimir. Tenga en cuenta que algunas plataformas podrían tener limitaciones que afectan esta función.

¿Cómo puedo seleccionar una impresora específica para el trabajo de impresión?

Para seleccionar una impresora específica, establezca la propiedad PrinterName en la clase PrintSettings. Si no especifica una impresora, se usará la impresora predeterminada del sistema.

¿Puedo configurar los márgenes para mi impresión?

Sí, puede configurar los márgenes de impresión estableciendo la propiedad PaperMargins en la clase PrintSettings según los valores de milímetros deseados.

¿Cómo imprimo documentos en escala de grises?

Para imprimir en escala de grises, establezca la propiedad Grayscale en true en la clase PrintSettings. La configuración predeterminada es false, que intenta imprimir en color.

¿Qué hace la propiedad Flatten?

La propiedad Flatten en IronPrint se utiliza para aplanar un PDF antes de imprimir. Este proceso es beneficioso para asegurar que los campos de formulario y las imágenes se muestren correctamente en la impresión.

¿Cómo especificar bandeja de impresora?

Puede especificar una bandeja de impresora estableciendo la propiedad Tray en la clase PrintSettings. Sin embargo, si se selecciona una bandeja en un PrintDialog, esta propiedad será ignorada. IronPrint proporciona métodos como GetPrinterTrays para listar las bandejas disponibles.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 34,016 | Versión: 2025.11 recién lanzado