چاپ یک سند به صورت برنامه ریزی شده یا با استفاده از دیالوگ ها
این مقاله نحوه چاپ یک سند پردازش متن با استفاده از Aspose.Words API را توصیف می کند. همچنین روش های چاپ یک سند با تنظیمات، پیش نمایش چاپ و دیالوگ های پیشرفت چاپ را نشان می دهد.
چاپ سند با تنظیمات و دیالوگ های پیش نمایش چاپ
هنگام کار با اسناد، اغلب لازم است آنها را به چاپگر انتخاب شده چاپ کنید. استفاده از یک دیالوگ پیش نمایش چاپ برای بررسی بصری نحوه ظاهر شدن سند چاپ شده و انتخاب گزینه های چاپ مربوطه مفید است.
Aspose.Words هیچ دیالوگ یا فرم داخلی ندارد اما کلاس AsposeWordsPrintDocument را اجرا می کند که هر دو جاوا را رد می کند.آوتچاپ.قابل چاپ و جاواآوتچاپ.قابل صفحه بندی
مثال زیر نشان می دهد که چگونه از این کلاس ها برای چاپ یک سند از Aspose.Words از طریق پیش نمایش چاپ و دایالوگ های تنظیمات استفاده کنید:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open the document. | |
Document doc = new Document(dataDir + "TestFile.doc"); | |
PrinterJob pj = PrinterJob.getPrinterJob(); | |
// Initialize the Print Dialog with the number of pages in the document. | |
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); | |
attributes.add(new PageRanges(1, doc.getPageCount())); | |
if (!pj.printDialog(attributes)) { | |
return; | |
} | |
// This object is responsible for rendering our document for use with the Java | |
// Print API. | |
AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc); | |
// Pass our document as pageable to the printer job. | |
pj.setPageable(awPrintDoc); | |
// Create an instance of the print preview dialog and pass the print dialog and | |
// our document. | |
// Note that AsposeWordsPrintDocument implements both the Pageable and Printable | |
// interfaces. If the pageable constructor for PrintPreviewDialog | |
// is used then the formatting of each page is taken from the document. If the | |
// printable constructor is used then Page Setup dialog becomes enabled | |
// and the desired page setting for all pages can be chosen there instead. | |
PrintPreviewDialog previewDlg = new PrintPreviewDialog(awPrintDoc); | |
// Pass the desired page range attributes to the print preview dialog. | |
previewDlg.setPrinterAttributes(attributes); | |
// Proceed with printing if the user accepts the print preview. | |
if (previewDlg.display()) | |
pj.print(attributes); |
چاپ چند صفحه در یک صفحه
Aspose.Words کلاس MultipagePrintDocument را اجرا می کند، برای تنظیم دقیق عملیات چاپ برای پیاده سازی منطق سفارشی شما با تعریف نحوه ظاهر شدن سند در صفحه چاپ شده. کلاس MultipagePrintDocument امکان چاپ چند صفحه بر روی یک ورق کاغذ را فراهم می کند.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Open the document. | |
Document doc = new Document(dataDir + "TestFile.doc"); | |
// Create a print job to print our document with. | |
PrinterJob pj = PrinterJob.getPrinterJob(); | |
// Initialize an attribute set with the number of pages in the document. | |
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); | |
attributes.add(new PageRanges(1, doc.getPageCount())); | |
// Pass the printer settings along with the other parameters to the print document. | |
MultipagePrintDocument awPrintDoc = new MultipagePrintDocument(doc, 4, true, attributes); | |
// Pass the document to be printed using the print job. | |
pj.setPrintable(awPrintDoc); | |
pj.print(); |
شما می توانید یک مثال از استفاده از کلاس MultipagePrintDocument را از Aspose.Words GitHub.
نتیجه این مثال کد در زیر نشان داده شده است:
/