Печать нескольких файлов RTF в Java

У меня есть список файлов RTF, загруженных с сервера.

Я хочу распечатать все эти файлы .rtf одним щелчком мыши без каких-либо диалогов печати или только один.

Пожалуйста, предложите, как мне это сделать.

Я использую Aspose для печати файлов RTF.

Пожалуйста, найдите прикрепленный ниже код для того же самого.

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.

Есть ли способ составить список Document и распечатать их все за раз.

Спасибо.


person Parth Soni    schedule 07.05.2014    source источник


Ответы (1)


Я работаю разработчиком социальных сетей в Aspose. Aspose.Words поддерживает автоматическую печать документов без отображения диалогового окна печати. Для этого вы можете использовать следующий код:

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); 
person Nausherwan Aslam    schedule 07.05.2014