프로그래밍 방식으로 문서 인쇄 또는 대화 상자 사용
이 문서에서는Aspose.WordsAPI을 사용하여 워드 프로세싱 문서를 인쇄하는 방법을 설명합니다. 또한 설정,인쇄 미리 보기 및 인쇄 진행 대화 상자가 있는 문서를 인쇄하는 방법을 보여 줍니다.
설정 및 인쇄 미리보기 대화 상자가 있는 문서 인쇄
문서 작업을 할 때 선택한 프린터로 문서를 인쇄해야 하는 경우가 많습니다. 인쇄 미리보기 대화 상자를 사용하여 인쇄된 문서가 어떻게 표시되는지 시각적으로 검사하고 관련 인쇄 옵션을 선택하는 것이 좋습니다.
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.WordsMultipagePrintDocument클래스를 구현하여 인쇄된 페이지에 문서가 표시되는 방식을 정의하여 사용자 지정 논리를 구현하도록 인쇄 작업을 미세 조정합니다. 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.
이 코드 예제의 결과는 다음과 같습니다:
/