最近的需求是要打印pdf,然後 用aspose 轉換pdf 後,發現 打印的時候 橫板也打印成豎版了,所以我需要知道 文件是否是橫板。
找了很久 然後發現網上現在沒有 說如果獲取 aspose 文件方向的 ,自己 瞎幾把試出來了 ^^ 分享出來 給大家:
@Test
public void testAsposeConvertDocx2Pdf() throws Exception{
String filename = "C:\\User\\Desktop\\aspose測試模板測試12.pdf";
String docNmae = "C:\\Users\\Desktop\\測試模板1.docx";
// String docNmae = "C:\\Users\\Liz\\Desktop\\test.xls";
File pdfFile = new File(filename);
FileOutputStream os = new FileOutputStream(pdfFile);
com.aspose.words.Document doc = new Document(docNmae);
// SaveOptions saveOptions = SaveOptions.createSaveOptions(SaveFormat.PDF);
// saveOptions.setPrettyFormat(true);
// saveOptions.setUseAntiAliasing(true);
// saveOptions.setUseHighQualityRendering(true);
SectionCollection sections = doc.getSections();
for(Section section:sections){
int a =Orientation.LANDSCAPE;//橫向
int b = Orientation.PORTRAIT;//豎向
section.getPageSetup().getOrientation();
}
doc.save(os,SaveFormat.PDF);
}