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 书签承前缩放验证内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!