Word print direction problem when one word contains different direction

Hi,

When I using aspose print word, and it maybe contain two different page direction in on word, then the print output is wrong. likes

Here is my code:

ResultView<InputStream> one = httpUtilt.downloadFile("report/data/v1/downloadReportDocuments",
                           token, request.getId());
Document doc = new Document(one.getContent());

PrinterJob pj = PrinterJob.getPrinterJob();
pj.setJobName(request.getFileName());
PrintService[] services = PrinterJob.lookupPrintServices();
if (services.length > 0)
{
    for (PrintService service : services)
    {
        if (service.getName().equalsIgnoreCase(request.getPrinterName()))
        {
            try
            {
                pj.setPrintService(service);
            }
            catch (PrinterException e)
            {
                e.printStackTrace();
            }
        }
    }
}

// Initialize the Print Dialog with the number of pages in the document.
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
if (request.getPages() == null || request.getPages().isEmpty())
{
    attributes.add(new PageRanges(1, doc.getPageCount()));
}
else
{
    String[] pages = request.getPages().split(",");
    List<int[]> ranges = new ArrayList<>();
    for (int j = 0; j < pages.length; j++)
    {
        String temp = pages[j];
        if (temp != null && !temp.isEmpty())
        {
            if (temp.contains("-"))
            {
                String[] tempAttr = temp.split("-");
                ranges.add(new int[] { Integer.parseInt(tempAttr[0]),
                                                        Integer.parseInt(tempAttr[1]) });
            }
            else
            {
                int pageIndex = Integer.parseInt(temp);
                ranges.add(new int[] { pageIndex, pageIndex });
            }
        }
    }

    // Convert to 2d array
    int[][] rangeArrays = new int[ranges.size()][2];
    for (int j = 0; j < ranges.size(); j++)
    {
        rangeArrays[j] = ranges.get(j);
    }

    attributes.add(new PageRanges(rangeArrays));
}

// 创建AsposeWordsPrintDocument对象
AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);
// 将AwPrintDocument对象设置为要打印的内容
pj.setPageable(awPrintDoc);
pj.print(attributes);

Here is word:

工艺规程.docx (140.5 KB)

Is there any way to auto detect page direction to print

@GusGus Except the page direction your document has different page sizes. So different paper size should be used for printing. You can use PageSetup.FirstPageTray and PageSetup.OtherPagesTray properties.

By the way while printing the document using MS Word on my side and single paper tray printer, the results similar to Aspose.Words printing result.

You can use PageInfo to get each page size and orientation and then use different printer setting for different pages.

Document doc = new Document("C:\\Temp\\in.docx");

for(int i=0; i<doc.getPageCount(); i++)
{
    PageInfo info = doc.getPageInfo(i);
    // .........
}

Thanks for your advise, but cloud you provider more codes for this? and cloud I shrink the big page size to A4 when printing?

@GusGus I am afraid there is no way to scale pages upon printing the document. You can try using renderToSize or renderToScale method to render the page to the required size and then sent the rendered image to the printer.

ok, and how about direction? the document have two directions . should I split the document by section,and printer one by one

@GusGus You can print set of pages with different directions using different printer settings.

Is there code samples for this? I have no ideal when the page related.

@GusGus In your code you specify the pages range using the following attribute:

attributes.add(new PageRanges(1, doc.getPageCount()));

You should first analyze the document pages using the code like this:

for (int i = 0; i < doc.getPageCount(); i++)
{
    PageInfo info = doc.getPageInfo(i);
    // Get width and height of the page.
    double widht = info.getWidthInPoints();
    double height = info.getHeightInPoints();

    // .....
}

And specify range of pages with portrait orientation, print them, and then when orientation is changed use different print settings and so on.

Thanks, but I found one problem, the doc attachment. I found the Orientation is wrong.

doc.getSections().get(1).getPageSetup().getOrientation()==doc.getSections().get(0).getPageSetup().getOrientation()

but in my office software, it shows different.


@GusGus
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-27311

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.