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