很多朋友不知道是什么是书签承前缩放,简单说就是可以任意改变当前pdf文档缩放比例,点击书签后不影响其缩放比率,本文给大家介绍下Java pdf文件书签承前缩放验证的设置方法,感兴趣的朋友一起看看吧
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<OutlineItemCollection>) outlines) {
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 = (XYZExplicitDestination) 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 导出文件:
<?xml version="1.0" encoding="iso_8859_1"?>
<Bookmark>
<Title Open="True">目录缩放到页面级别
<Title Page="2 XYZ 71 769 0" Action="GoTo" Open="True">3.2.S.7 稳定性承前缩放
<Title>3.2.S.7.1 稳定性总结</Title>实际大小
<Title Page="5 FitBH 842" Action="GoTo">3.2.S.7.2 上市后稳定性方案和稳定性承诺</Title>适合可见
<Title Page="8 XYZ 71 523 0" Action="GoTo">3.2.S.7.3 稳定性数据</Title>承前缩放
</Title>
</Title>
<Title Page="1 XYZ 0 842 0" Action="GoTo" Open="False">表目录</Title>承前缩放
<Title Page="1 XYZ 0 842 0" Action="GoTo" Open="False">图目录</Title>承前缩放
</Bookmark>
aspose.pdf 官网指路 : https://docs.aspose.com/pdf/java/get-update-and-expand-bookmark/
到此这篇关于Java pdf文件书签承前缩放验证的文章就介绍到这了,更多相关Java 书签承前缩放验证内容请搜索编程学习网以前的文章希望大家以后多多支持编程学习网!
沃梦达教程
本文标题为:Java pdf文件书签承前缩放验证的设置方法
基础教程推荐
猜你喜欢
- java基础知识之FileInputStream流的使用 2023-08-11
- springboot自定义starter方法及注解实例 2023-03-31
- Java并发编程进阶之线程控制篇 2023-03-07
- java实现多人聊天系统 2023-05-19
- Java实现线程插队的示例代码 2022-09-03
- ConditionalOnProperty配置swagger不生效问题及解决 2023-01-02
- JDK数组阻塞队列源码深入分析总结 2023-04-18
- Java实现查找文件和替换文件内容 2023-04-06
- Java数据结构之对象比较详解 2023-03-07
- Java文件管理操作的知识点整理 2023-05-19