Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Mar 31, 2021 12:15 pm

before print


Document docs = new Document();
docs.loadFromFile("test.docx");
PageFormat pf = new PageFormat();
Paper paper = new Paper();
paper.setSize(420, 396); // 1/72 inch
paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight()); // no margins
pf.setPaper(paper);

PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(docs, pf);
try {
printJob.print();
} catch (PrinterException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}

--------------------------------------------------------------------------------------------------------------------
i am using spire 3.9.0 free version for java

gunass36
 
Posts: 1
Joined: Sun Mar 21, 2021 11:54 pm

Thu Apr 01, 2021 10:15 am

Hello,

Thanks for your inquiry.
According to your printout, I suspect that this issue is because that the printer paper size you set is smaller than the actual paper size of your Word document, and the PrinterJob API does not support scaling the printed content according to the paper size, which results in only part of the content being printed out. Please refer to the following code to set the printer paper size based on the actual paper size. Feel free to contact us if you have further issues.
Code: Select all
        Document docs = new Document();
        docs.loadFromFile("Sample.docx");
        Section section=docs.getSections().get(0);

        PageFormat pf = new PageFormat();
        Paper paper = new Paper();
        paper.setSize(section.getPageSetup().getPageSize().getWidth(), section.getPageSetup().getPageSize().getHeight()); // 1/72 inch
        paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight()); // no margins
        pf.setPaper(paper);

        PrinterJob printJob = PrinterJob.getPrinterJob();
        printJob.setPrintable(docs, pf);
        try {
            printJob.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }


Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Fri Apr 09, 2021 9:30 am

Hello,

Greetings from E-iceblue!
Has the issue been solved now? Could you please give us some feedback at your convenience?

Sincerely,
Andy
E-iceblue support team
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.Doc