java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Java 书签承前缩放验证

Java pdf文件书签承前缩放验证的设置方法

作者:Aimyone

很多朋友不知道是什么是书签承前缩放,简单说就是可以任意改变当前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">&#30446;&#24405;缩放到页面级别
	  <Title Page="2 XYZ 71 769 0" Action="GoTo" Open="True">3.2.S.7 &#31283;&#23450;&#24615;承前缩放
		  <Title>3.2.S.7.1 &#31283;&#23450;&#24615;&#24635;&#32467;</Title>实际大小
		  <Title Page="5 FitBH 842" Action="GoTo">3.2.S.7.2 &#19978;&#24066;&#21518;&#31283;&#23450;&#24615;&#26041;&#26696;&#21644;&#31283;&#23450;&#24615;&#25215;&#35834;</Title>适合可见
		  <Title Page="8 XYZ 71 523 0" Action="GoTo">3.2.S.7.3 &#31283;&#23450;&#24615;&#25968;&#25454;</Title>承前缩放
	  </Title>
  </Title>
  
  <Title Page="1 XYZ 0 842 0" Action="GoTo" Open="False">&#34920;&#30446;&#24405;</Title>承前缩放
  <Title Page="1 XYZ 0 842 0" Action="GoTo" Open="False">&#22270;&#30446;&#24405;</Title>承前缩放
</Bookmark>

aspose.pdf 官网指路 : https://docs.aspose.com/pdf/java/get-update-and-expand-bookmark/

到此这篇关于Java pdf文件书签承前缩放验证的文章就介绍到这了,更多相关Java 书签承前缩放验证内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文