ITeye博客

java itext 清空PDF标签

reymont · 2011-05-11 10:55 · PDF · 编程语言 · Markdown

欢迎转载,请注明来自

http://reymont.iteye.com/blog/1039741

 

思路:使用itext-2.0.8,请自行下载。重新生成一个PDF文件,然后设置该文件的标签为空标签

 

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;

public class ClearBookmark {

    public static void main(String[] args) {
        String oldFile = "D:/download/1.pdf";
        String newFile = "D:/download/2.pdf";
        new ClearBookmark().setOutlines(oldFile, newFile);
    }

    public void setOutlines(String oldFile, String newFile) {
        try {
            // create a reader for a certain document
            PdfReader reader = new PdfReader(oldFile);

            // we create a stamper that will copy the document to a new file
            PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(
                    newFile));

            // read the outlines structure file
            // readOutlinesFile(outlinesFile);

            // set the outlines
            //stamp.setOutlines(createOutlines());
            stamp.setOutlines(new ArrayList());

            // closing PdfStamper will generate the new PDF file
            stamp.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }

    }

    public List createOutlines() {
        List list = new ArrayList();

        HashMap map = null;
        map = new HashMap();

        list.add(map);

        return list;
    }
}

 

欢迎转载,请注明来自

http://reymont.iteye.com/blog/1039741

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。