طباعة PDF إلى طابعة XPS
تعمل مقتطفات الشيفرة التالية أيضًا مع مكتبة Aspose.PDF.Drawing .
طباعة PDF إلى طابعة XPS في C#
يمكنك طباعة ملف PDF إلى طابعة XPS، أو أي طابعة افتراضية أخرى، باستخدام فئة PdfViewer . للقيام بذلك، قم بإنشاء كائن من فئة PdfViewer وافتح ملف PDF باستخدام طريقة BindPdf . يمكنك تعيين إعدادات طباعة مختلفة باستخدام فئات PrinterSettings و PageSettings . تحتاج أيضًا إلى تعيين خاصية PrinterName إلى طابعة XPS أو أي طابعة افتراضية أخرى قمت بتثبيتها.
أخيرًا، استخدم طريقة PrintDocumentWithSettings لطباعة PDF إلى طابعة XPS أو أي طابعة افتراضية أخرى. يوضح مقتطف الشيفرة التالي كيفية طباعة ملف 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 PrintToXpsPrinter ()
{
// 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 ();
// Set XPS/PDF printer name
ps . PrinterName = "Microsoft XPS Document Writer" ;
// 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 PrintToXpsPrinter ()
{
// 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 ();
// Set XPS/PDF printer name
ps . PrinterName = "Microsoft XPS Document Writer" ;
// 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 );
}
اختيار مصدر الورق حسب حجم صفحة PDF
منذ إصدار 24.4، أصبح من الممكن اختيار مصدر الورق حسب حجم صفحة PDF في مربع حوار الطباعة. يمكّن مقتطف الشيفرة التالي من اختيار درج الطابعة بناءً على حجم صفحة PDF.
يمكن تبديل هذه الميزة تشغيلًا وإيقافًا باستخدام واجهة PdfContentEditor .