java中的接口是类吗
403
2022-08-25
Java pdf文件书签承前缩放验证的设置方法
目录1,什么是书签承前缩放?2,如何设置书签承前缩放?3,代码3.1书签结构:3.2代码3.3控制台输出:4,书签的xml文件导出4.1代码4.2导出文件:
1,什么是书签承前缩放?
设置了承前缩放,当你手动将page4缩放到145%,然后点击书签1,书签1定位到的page1的缩放比例也是145%
2,如何设置书签承前缩放?
使用工具:
承前缩放书签设置:
其他类型书签设置:
3,代码
3.1 书签结构:
3.2 代码
import com.aspose.pdf.*;
public class bookmark {
public static void main(String[] args) {
// Open document
Document pdfDocument = new Document("D:\\chromeDownload\\测试版2.pdf");
OutlineCollection outlines = pdfDocument.getOutlines();
for (OutlineItemCollection outlineItem : (Iterable
double soureceZoom = -1;
if (outlineItem.getDestination() != null) {
soureceZoom = getAppointmentZoom(outlineItem.getDestination());
} else if (outlineItem.getAction() != null) {
soureceZoom = getAppointmentZoom(outlineItem.getAction());
}
if(soureceZoom == -1){
System.out.println("书签必须承前缩放,书签名:" + outlineItem.getTitle() + ",缩放因子: " + soureceZoom);
// System.out.println("Title : " + outlineItem.getTitle() + ",缩放因子: " + soureceZoom);
if (outlineItem.size()>0){
checkBookmark(outlineItem);
}
}
private static void checkBookmark(OutlineItemCollection Outlines) {
private static double getAppointmentZoom(IAppointment appointment) {
if (appointment instanceof XYZExplicitDestination) {
XYZExplicitDestination destination = (XYZExplicitDestination) appointment;
return destination.getZoom();
} else if (appointment instanceof GoToAction) {
GoToAction goToAction = (GoToAction) appointment;
if (goToAction.getDestination() instanceof XYZExplicitDestination) {
XYZExplicitDestination destination = (XYZEhttp://xplicitDestination) goToAction.getDestination();
return destination.getZoom();
} else if (appointment instanceof GoToRemoteAction) {
GoToRemoteAction goToRemoteAction = (GoToRemoteAction) appointment;
if (goToRemoteAction.getDestination() instanceof XYZExplicitDestination) {
XYZExplicitDestination destination = (XYZExplicitDestination) goToRemoteAction.getDestination();
return -1;
}
3.3 控制台输出:
注意:承前缩放的因子为 0;
4,书签的xml文件导出
4.1 代码
import com.aspose.pdf.Document;
import com.aspose.pdf.facades.PdfBookmarkEditor;
import java.io.FileNotFoundException;
public class AsposeTest {
public static void main(String[] args) throws FileNotFoundException {
Document document6 = new Document("D:\\测试版2.pdf");
exportBookmarksToXML(document6);
}
public static void exportBookmarksToXML(Document document) throws FileNotFoundException {
PdfBookmarkEditor pdfBookmarkEditor = new PdfBookmarkEditor();
pdfBookmarkEditor.bindPdf(document);
pdfBookmarkEditor.exportBookmarksToXML("D:\\测试版2.xml");
pdfBookmarkEditor.getDocument().save();
}
4.2 导出文件:
aspose.pdf 官网指路 : https://docs.aspose.com/pdf/java/get-update-and-expand-bookmark/
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~