首頁 > 軟體

Java pdf檔案書籤承前縮放驗證的設定方法

2022-02-24 16:00:34

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 書籤承前縮放驗證內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!


IT145.com E-mail:sddin#qq.com