El proyecto PDFTOprinter permite imprimir archivos PDF usa PDFTOprinter Util. El paquete contiene pdftoprinter_m.exe y lo copia en la carpeta de salida antes del evento de compilación. También proporciona una clase PDFTPrinterprinter que ejecuta PDFTOPRINTER_M.EXE dentro de un método "Imprimir" en un proceso separado con un tiempo de espera predeterminado de 1 minuto (el tiempo de espera puede ser sobresaltado por el tercer argumento). El método "Imprimir" ejecuta una nueva instancia PDFTPRINTER_M.EXE por llamada. Por defecto, la nueva impresión no se iniciará mientras que la anterior instancia de PDFTOPRINTERPRINTER no está completa. Pero puede usar el nivel de concurrencia establecido usando el constructor con argumentos.
Nota: El nivel de concurrencia funciona dentro de la instancia de PdftoPrinterprinter.
Uso de la muestra:
Use una impresora local
var filePath = @"c:pathtopdffile.pdf" ;
var printerName = "Vendor Color Printer Name" ;
var printer = new PDFtoPrinterPrinter ( ) ;
printer . Print ( new PrintingOptions ( printerName , filePath ) ) ;Use la impresora de red con tiempo de espera
var filePath = @"c:pathtopdffile.pdf" ;
var networkPrinterName = @"\myprintserverprinter1" ;
var printTimeout = new TimeSpan ( 0 , 30 , 0 ) ;
var printer = new PDFtoPrinterPrinter ( ) ;
printer . Print ( new PrintingOptions ( networkPrinterName , filePath ) , printTimeout ) ;Use la impresora de red con 5 impresiones de concurrencia. En este caso, hasta 5 instancias de PdftoPrinter_M.Exe se iniciarán simultáneamente
var filePath = @"c:pathtopdffile.pdf" ;
var networkPrinterName = @"\myprintserverprinter1" ;
var allowedCocurrentPrintings = 5 ;
var printer = new PDFtoPrinterPrinter ( allowedCocurrentPrintings ) ;
for ( var i = 0 ; i < 10 ; i ++ )
{
wrapper . Print ( new PrintingOptions ( networkPrinterName , filePath ) ) ;
}Si necesita eliminar archivos después de imprimir, puede usar "CleanupFilesPrinter":
var filePath = @"c:pathtopdffile.pdf" ;
var networkPrinterName = @"\myprintserverprinter1" ;
var printer = new CleanupFilesPrinter ( new PDFtoPrinterPrinter ( ) ) ;
printer . Print ( new PrintingOptions ( networkPrinterName , filePath ) ) ; El paquete PDFTOprinter está disponible solo en máquinas de Windows. Si una aplicación hace referencia al marco Net5.0 y más tarde, se requiere cambiar "TargetFramework" a NET [Versión] .0-Windows en un archivo CSProj . P.ej
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
</PropertyGroup>
</Project>