时间:2022-10-11 12:12:38 | 栏目:JAVA代码 | 点击:次
换句话来说
设置了承前缩放,当你手动将page4缩放到145%,然后点击书签1,书签1定位到的page1的缩放比例也是145%
使用工具:
承前缩放书签设置:
其他类型书签设置:
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; }
注意:承前缩放的因子为 0;
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(); }
<?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/