`
reymont
  • 浏览: 526006 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

java itext 清空PDF标签

    博客分类:
  • PDF
阅读更多

欢迎转载,请注明来自

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics