PDF 인쇄 작업 - 파사드
기본 프린터에 PDF 파일 인쇄하기 - 프린터 및 페이지 설정 사용
먼저 문서를 이미지로 변환한 다음 프린터에서 인쇄합니다.
기본 프린터에 PDF 파일을 인쇄할 수 있는 PdfViewer 클래스의 인스턴스를 생성하고, BindPdf 메서드를 사용하여 문서를 열고 필요한 설정을 변경합니다. 이 예제는 A4 형식과 세로 방향을 사용합니다. PrinterSettings 에서 가장 먼저 인쇄할 프린터의 이름을 설정해야 합니다. 그렇지 않으면 기본 프린터로 인쇄됩니다. 다음으로 필요한 복사본 수를 입력합니다.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingPDFFile ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Create PdfViewer object
using ( var viewer = new Aspose . Pdf . Facades . PdfViewer ())
{
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Create objects for printer and page settings and PrintDocument
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
var prtdoc = new System . Drawing . Printing . PrintDocument ();
// Set printer name
ps . PrinterName = prtdoc . PrinterSettings . PrinterName ;
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingPDFFile ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Create PdfViewer object
using var viewer = new Aspose . Pdf . Facades . PdfViewer ();
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Create objects for printer and page settings and PrintDocument
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
var prtdoc = new System . Drawing . Printing . PrintDocument ();
// Set printer name
ps . PrinterName = prtdoc . PrinterSettings . PrinterName ;
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
}
인쇄 대화 상자를 표시하려면 다음 코드 조각을 사용하십시오.
소프트 프린터에 PDF 인쇄하기
파일로 인쇄하는 프린터가 있습니다. 이를 사용하려면 가상 프린터의 이름을 설정하고, 이전 예제와 유사하게 설정을 합니다.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingPDFToSoftPrinter ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Create PdfViewer object
using ( var viewer = new Aspose . Pdf . Facades . PdfViewer ())
{
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Do not convert document pages to images
viewer . PrintAsImage = false ;
// Create objects for printer and page settings and PrintDocument
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Set printer name
ps . PrinterName = "HP Universal Printing PS (v7.0.0)" ;
// Or set the PDF printer
// ps.PrinterName = "Adobe PDF";
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingPDFToSoftPrinter ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Create PdfViewer object
using var viewer = new Aspose . Pdf . Facades . PdfViewer ();
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Do not convert document pages to images
viewer . PrintAsImage = false ;
// Create objects for printer and page settings and PrintDocument
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Set printer name
ps . PrinterName = "HP Universal Printing PS (v7.0.0)" ;
// Or set the PDF printer
// ps.PrinterName = "Adobe PDF";
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
}
인쇄 대화 상자 숨기기
Aspose.PDF for .NET는 인쇄 대화 상자를 숨기는 기능을 지원합니다. 이를 위해 PrintPageDialog 속성을 사용하십시오.
다음 코드 조각은 인쇄 대화 상자를 숨기는 방법을 보여줍니다.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingPDFHidePrintDialog ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Create PdfViewer object
using ( var viewer = new Aspose . Pdf . Facades . PdfViewer ())
{
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Create objects for printer and page settings
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Set XPS/PDF printer name
ps . PrinterName = "OneNote for Windows 10" ;
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingPDFHidePrintDialog ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Create PdfViewer object
using var viewer = new Aspose . Pdf . Facades . PdfViewer ();
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printin
viewer . PrintPageDialog = false ;
// Create objects for printer and page settings
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Set XPS/PDF printer name
ps . PrinterName = "OneNote for Windows 10" ;
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
}
색상 PDF를 회색조로 XPS 파일로 인쇄하기
색상 PDF 문서는 PdfViewer 를 사용하여 회색조로 XPS 프린터에 인쇄할 수 있습니다. 이를 위해 PdfViewer.PrintAsGrayscale 속성을 true 로 설정합니다. 다음 코드 조각은 PdfViewer.PrintAsGrayscale
속성의 사용법을 보여줍니다.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingPDFAsGrayscale ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Create PdfViewer object
using ( var viewer = new Aspose . Pdf . Facades . PdfViewer ())
{
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Print the file as grayscale
viewer . PrintAsGrayscale = false ;
// Create objects for printer and page settings
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Set XPS/PDF printer name
ps . PrinterName = "OneNote for Windows 10" ;
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingPDFAsGrayscale ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Create PdfViewer object
using var viewer = new Aspose . Pdf . Facades . PdfViewer ();
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Print the file as grayscale
viewer . PrintAsGrayscale = false ;
// Create objects for printer and page settings
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Set XPS/PDF printer name
ps . PrinterName = "OneNote for Windows 10" ;
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
}
PDF를 PostScript로 변환하기
PdfViewer 클래스는 PDF 문서를 인쇄할 수 있는 기능을 제공하며, 이 클래스를 사용하여 PDF 파일을 PostScript 형식으로 변환할 수도 있습니다. PDF 파일을 PostScript로 변환하려면 먼저 PS 프린터를 설치하고 PdfViewer
를 사용하여 파일로 인쇄하면 됩니다.
다음 코드 조각은 PDF를 PostScript 형식으로 인쇄하고 변환하는 방법을 보여줍니다.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingPDFToPostScript ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Create PdfViewer object
using ( var viewer = new Aspose . Pdf . Facades . PdfViewer ())
{
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Do not convert document pages to images
viewer . PrintAsImage = false ;
// Create objects for printer and page settings and PrintDocument
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Set printer name
ps . PrinterName = "HP Universal Printing PS (v7.0.0)" ;
// Set output file name and PrintToFile attribute
ps . PrintFileName = dataDir + "PdfToPostScript_out.ps" ;
ps . PrintToFile = true ;
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingPDFToSoftPrinter ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Create PdfViewer object
using var viewer = new Aspose . Pdf . Facades . PdfViewer ();
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Do not convert document pages to images
viewer . PrintAsImage = false ;
// Create objects for printer and page settings and PrintDocument
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Set printer name
ps . PrinterName = "HP Universal Printing PS (v7.0.0)" ;
// Set output file name and PrintToFile attribute
ps . PrintFileName = dataDir + "PdfToPostScript_out.ps" ;
ps . PrintToFile = true ;
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
}
인쇄 작업 상태 확인하기
PDF 파일은 PdfViewer 클래스를 사용하여 물리적 프린터와 Microsoft XPS 문서 작성기 모두에 인쇄할 수 있으며, 인쇄 대화 상자를 표시하지 않습니다. 큰 PDF 파일을 인쇄할 때 프로세스가 오랜 시간이 걸릴 수 있으므로 사용자는 인쇄 프로세스가 완료되었는지 또는 문제가 발생했는지 확신할 수 없습니다. 인쇄 작업의 상태를 확인하려면 PrintStatus 속성을 사용하십시오. 다음 코드 조각은 PDF 파일을 XPS 파일로 인쇄하고 인쇄 상태를 가져오는 방법을 보여줍니다.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CheckingPrintJobStatus ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Instantiate PdfViewer object
using ( var viewer = new Aspose . Pdf . Facades . PdfViewer ())
{
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Do not convert document pages to images
viewer . PrintAsImage = false ;
// Create Printer Settings object
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Specify the printer name
ps . PrinterName = "Microsoft XPS Document Writer" ;
// Set output file name and PrintToFile attribute
ps . PrintFileName = dataDir + "CheckingPrintJobStatus_out.xps" ;
ps . PrintToFile = true ;
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
// Check the print status
if ( viewer . PrintStatus != null )
{
// An exception was thrown
if ( viewer . PrintStatus is Exception ex )
{
// Get exception message
Console . WriteLine ( ex . Message );
}
}
else
{
// No errors were found. Printing job has completed successfully
Console . WriteLine ( "Printing completed without any issue." );
}
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CheckingPrintJobStatus ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Instantiate PdfViewer object
using var viewer = new Aspose . Pdf . Facades . PdfViewer ();
// Bind PDF document
viewer . BindPdf ( dataDir + "PrintDocument.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Do not convert document pages to images
viewer . PrintAsImage = false ;
// Create Printer Settings object
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Specify the printer name
ps . PrinterName = "Microsoft XPS Document Writer" ;
// Set output file name and PrintToFile attribute
ps . PrintFileName = dataDir + "CheckingPrintJobStatus_out.xps" ;
ps . PrintToFile = true ;
// Set PageSize (if required)
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
// Set PageMargins (if required)
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print document using printer and page settings
viewer . PrintDocumentWithSettings ( pgs , ps );
// Check the print status
if ( viewer . PrintStatus != null )
{
// An exception was thrown
if ( viewer . PrintStatus is Exception ex )
{
// Get exception message
Console . WriteLine ( ex . Message );
}
}
else
{
// No errors were found. Printing job has completed successfully
Console . WriteLine ( "Printing completed without any issue." );
}
}
단면 및 양면 모드로 페이지 인쇄하기
특정 인쇄 작업에서 PDF 문서의 페이지는 양면 또는 단면 모드로 인쇄할 수 있지만, 단일 인쇄 작업 내에서 일부 페이지는 단면으로, 일부 페이지는 양면으로 인쇄할 수는 없습니다. 그러나 요구 사항을 충족하기 위해 서로 다른 페이지 범위와 PrintingJobSettings 객체를 사용할 수 있습니다. 다음 코드 조각은 PDF 파일의 일부 페이지를 단면으로 인쇄하고 일부 페이지를 양면으로 인쇄하는 방법을 보여줍니다.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
struct PrintingJobSettings
{
public int ToPage { get ; set ; }
public int FromPage { get ; set ; }
public string OutputFile { get ; set ; }
public Aspose . Pdf . Printing . Duplex Mode { get ; set ; }
}
private static void PrintingPagesInSimplexAndDuplexMode ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
int printingJobIndex = 0 ;
string outputDir = dataDir ;
var printingJobs = new List < PrintingJobSettings >();
// Create multiple printing jobs to print different page ranges with different duplex settings
var printingJob1 = new PrintingJobSettings ();
printingJob1 . FromPage = 1 ;
printingJob1 . ToPage = 3 ;
printingJob1 . OutputFile = outputDir + "PrintPageRange_p1-3_out.xps" ;
printingJob1 . Mode = Aspose . Pdf . Printing . Duplex . Default ;
printingJobs . Add ( printingJob1 );
PrintingJobSettings printingJob2 = new PrintingJobSettings ();
printingJob2 . FromPage = 4 ;
printingJob2 . ToPage = 6 ;
printingJob2 . OutputFile = outputDir + "PrintPageRange_p4-6_out.xps" ;
printingJob2 . Mode = Aspose . Pdf . Printing . Duplex . Simplex ;
printingJobs . Add ( printingJob2 );
PrintingJobSettings printingJob3 = new PrintingJobSettings ();
printingJob3 . FromPage = 7 ;
printingJob3 . ToPage = 7 ;
printingJob3 . OutputFile = outputDir + "PrintPageRange_p7_out.xps" ;
printingJob3 . Mode = Aspose . Pdf . Printing . Duplex . Default ;
printingJobs . Add ( printingJob3 );
// Create PdfViewer object
using ( var viewer = new Aspose . Pdf . Facades . PdfViewer ())
{
// Bind PDF document
viewer . BindPdf ( dataDir + "Print-PageRange.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Create objects for printer and page settings
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Set printer name
ps . PrinterName = "Microsoft XPS Document Writer" ;
// Set output file name and PrintToFile attribute
ps . PrintFileName = Path . GetFullPath ( printingJobs [ printingJobIndex ]. OutputFile );
ps . PrintToFile = true ;
// Set parameters for the first print job
ps . FromPage = printingJobs [ printingJobIndex ]. FromPage ;
ps . ToPage = printingJobs [ printingJobIndex ]. ToPage ;
ps . Duplex = printingJobs [ printingJobIndex ]. Mode ;
ps . PrintRange = Aspose . Pdf . Printing . PrintRange . SomePages ;
// Set paper size and margins
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
ps . DefaultPageSettings . PaperSize = pgs . PaperSize ;
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Chain other print jobs at the end of the finished job
viewer . EndPrint += ( sender , args ) =>
{
if (++ printingJobIndex < printingJobs . Count )
{
// Set the next print job parameters
ps . PrintFileName = Path . GetFullPath ( printingJobs [ printingJobIndex ]. OutputFile );
ps . FromPage = printingJobs [ printingJobIndex ]. FromPage ;
ps . ToPage = printingJobs [ printingJobIndex ]. ToPage ;
ps . Duplex = printingJobs [ printingJobIndex ]. Mode ;
// Run the next print job
viewer . PrintDocumentWithSettings ( pgs , ps );
}
};
// Run the first print job
viewer . PrintDocumentWithSettings ( pgs , ps );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
struct PrintingJobSettings
{
public int ToPage { get ; set ; }
public int FromPage { get ; set ; }
public string OutputFile { get ; set ; }
public Aspose . Pdf . Printing . Duplex Mode { get ; set ; }
}
private static void PrintingPagesInSimplexAndDuplexMode ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
int printingJobIndex = 0 ;
string outputDir = dataDir ;
var printingJobs = new List < PrintingJobSettings >();
// Create multiple printing jobs to print different page ranges with different duplex settings
var printingJob1 = new PrintingJobSettings ();
printingJob1 . FromPage = 1 ;
printingJob1 . ToPage = 3 ;
printingJob1 . OutputFile = outputDir + "PrintPageRange_p1-3_out.xps" ;
printingJob1 . Mode = Aspose . Pdf . Printing . Duplex . Default ;
printingJobs . Add ( printingJob1 );
PrintingJobSettings printingJob2 = new PrintingJobSettings ();
printingJob2 . FromPage = 4 ;
printingJob2 . ToPage = 6 ;
printingJob2 . OutputFile = outputDir + "PrintPageRange_p4-6_out.xps" ;
printingJob2 . Mode = Aspose . Pdf . Printing . Duplex . Simplex ;
printingJobs . Add ( printingJob2 );
PrintingJobSettings printingJob3 = new PrintingJobSettings ();
printingJob3 . FromPage = 7 ;
printingJob3 . ToPage = 7 ;
printingJob3 . OutputFile = outputDir + "PrintPageRange_p7_out.xps" ;
printingJob3 . Mode = Aspose . Pdf . Printing . Duplex . Default ;
printingJobs . Add ( printingJob3 );
// Create PdfViewer object
using var viewer = new Aspose . Pdf . Facades . PdfViewer ();
// Bind PDF document
viewer . BindPdf ( dataDir + "Print-PageRange.pdf" );
// Set attributes for printing
// Print the file with adjusted size
viewer . AutoResize = true ;
// Print the file with adjusted rotation
viewer . AutoRotate = true ;
// Do not produce the page number dialog when printing
viewer . PrintPageDialog = false ;
// Create objects for printer and page settings
var ps = new Aspose . Pdf . Printing . PrinterSettings ();
var pgs = new Aspose . Pdf . Printing . PageSettings ();
// Set printer name
ps . PrinterName = "Microsoft XPS Document Writer" ;
// Set output file name and PrintToFile attribute
ps . PrintFileName = Path . GetFullPath ( printingJobs [ printingJobIndex ]. OutputFile );
ps . PrintToFile = true ;
// Set parameters for the first print job
ps . FromPage = printingJobs [ printingJobIndex ]. FromPage ;
ps . ToPage = printingJobs [ printingJobIndex ]. ToPage ;
ps . Duplex = printingJobs [ printingJobIndex ]. Mode ;
ps . PrintRange = Aspose . Pdf . Printing . PrintRange . SomePages ;
// Set paper size and margins
pgs . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
ps . DefaultPageSettings . PaperSize = pgs . PaperSize ;
pgs . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Chain other print jobs at the end of the finished job
viewer . EndPrint += ( sender , args ) =>
{
if (++ printingJobIndex < printingJobs . Count )
{
// Set the next print job parameters
ps . PrintFileName = Path . GetFullPath ( printingJobs [ printingJobIndex ]. OutputFile );
ps . FromPage = printingJobs [ printingJobIndex ]. FromPage ;
ps . ToPage = printingJobs [ printingJobIndex ]. ToPage ;
ps . Duplex = printingJobs [ printingJobIndex ]. Mode ;
// Run the next print job
viewer . PrintDocumentWithSettings ( pgs , ps );
}
};
// Run the first print job
viewer . PrintDocumentWithSettings ( pgs , ps );
}
단일 인쇄 작업에서 여러 PDF 문서 인쇄하기
때때로 여러 관련 문서를 함께 단일 인쇄 작업으로 인쇄해야 할 필요가 있습니다. 이렇게 하면 이러한 문서가 다른 사용자의 출력과 섞이지 않도록 보장되며, 특히 원격 네트워크 프린터에서 그렇습니다. Aspose.PDF는 PdfViewer 클래스의 정적 PrintDocuments
메서드를 통해 공유 프린터 설정으로 단일 인쇄 작업에서 임의의 수의 문서를 인쇄하는 것을 지원합니다. 인쇄할 문서는 파일 경로, 문서 스트림 또는 Document 객체로 제공할 수 있습니다.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingMultipleDocumentsInSingleJob ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Paths to documents to be printed
var path1 = dataDir + "PrintDocument.pdf" ;
var path2 = dataDir + "Print-PageRange.pdf" ;
var path3 = dataDir + "35925_1_3.xps" ;
// Set up printer and page settings
var printDocument = new System . Drawing . Printing . PrintDocument ();
Aspose . Pdf . Printing . PrinterSettings printerSettings = new Aspose . Pdf . Printing . PrinterSettings ();
printerSettings . PrinterName = printDocument . PrinterSettings . PrinterName ;
Aspose . Pdf . Printing . PageSettings pageSettings = new Aspose . Pdf . Printing . PageSettings ();
pageSettings . PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ;
pageSettings . Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 );
// Print multiple documents in a single print job
Aspose . Pdf . Facades . PdfViewer . PrintDocuments ( printerSettings , pageSettings , path1 , path2 , path3 );
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void PrintingMultipleDocumentsInSingleJob ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdfFacades_Printing ();
// Paths to documents to be printed
var path1 = dataDir + "PrintDocument.pdf" ;
var path2 = dataDir + "Print-PageRange.pdf" ;
var path3 = dataDir + "35925_1_3.xps" ;
// Set up printer and page settings
var printDocument = new System . Drawing . Printing . PrintDocument ();
Aspose . Pdf . Printing . PrinterSettings printerSettings = new Aspose . Pdf . Printing . PrinterSettings
{
PrinterName = printDocument . PrinterSettings . PrinterName
};
Aspose . Pdf . Printing . PageSettings pageSettings = new Aspose . Pdf . Printing . PageSettings
{
PaperSize = Aspose . Pdf . Printing . PaperSizes . A4 ,
Margins = new Aspose . Pdf . Devices . Margins ( 0 , 0 , 0 , 0 )
};
// Print multiple documents in a single print job
Aspose . Pdf . Facades . PdfViewer . PrintDocuments ( printerSettings , pageSettings , path1 , path2 , path3 );
}