用Java打印多个RTF文件 [英] Print Multiple RTF Files in Java
问题描述
我有一个从服务器下载的RTF文件的列表.
I have a list of RTF files downloaded from the server.
我希望一次单击即可打印所有这些.rtf文件,而没有任何打印对话框或只有一个.
I want to print all these .rtf files at a single click without any print dialogues or only one.
请提出我该怎么做.
我正在使用Aspose打印rtf文件.
I am using Aspose to print rtf files.
请在下面找到相同的代码.
Please find the attached below code for the same.
import java.io.File;
import javax.print.attribute.AttributeSet;
import com.aspose.words.Document;
public class DocumentPrinter {
public static void main(String ar[]) throws Exception{
File folder = new File("D:\\projects\\emrs3\\PMS\\Claim\\PaperRTF");
File[] listOfFiles = folder.listFiles();
int j =3 ;
for (int i = 0; i <j ; i++) {
if (listOfFiles[i].isFile()) {
//System.out.println("File " + listOfFiles[i].getName());
Document doc = new Document(listOfFiles[i].getAbsolutePath());
doc.print();
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
}
}
上面的代码附带的问题是,由于我已将doc.print();
放入for循环中,因此始终要求进行打印对话.
Problem attached with the above code is it's always asking for a print dialogue as I have put doc.print();
it in a for loop.
有什么办法可以列出Document
并一次打印所有.
Is there any way I can make a list of Document
and print them all at a time.
谢谢.
推荐答案
我在Aspose担任社交媒体开发人员. Aspose.Words支持静默打印文档而不显示打印对话框.您可以使用以下代码来实现此目的:
I work as social media developer at Aspose. Aspose.Words supports silently printing the documents without showing the print dialog. You can use the following code to achieve this:
File folder = new File("D:\\projects\\emrs3\\PMS\\Claim\\PaperRTF");
File[] listOfFiles = folder.listFiles();
int j =3 ;
for (int i = 0; i <j ; i++) {
if (listOfFiles[i].isFile()) {
//System.out.println("File " + listOfFiles[i].getName());
Document doc = new Document(listOfFiles[i].getAbsolutePath());
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()));
// Create the Aspose.Words' implementation of the Java Pageable interface.
AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);
// Pass the document to the printer.
pj.setPageable(awPrintDoc);
// Print the document with the user specified print settings.
pj.print(attributes);
这篇关于用Java打印多个RTF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!