目录之chuck做成方法

public static CtpositionDto ChunkCataLogCreate(String sourceFile,String titleName,Map<String, Integer> positionDto, Map<Integer, String> map) throws java.io.IOException, DocumentException {
        CtpositionDto positionDto1 =new CtpositionDto();
        BaseFont baseFont = BaseFont.createFont("C:\\Windows\\Fonts\\MSGOTHIC.TTC,1", BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
        Font font = new Font(baseFont, 12, Font.NORMAL);
        Document document = new Document();
        Paragraph paragraph01 = new Paragraph();// Chapter构造器不接受Anchor参数
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:\\pdf\\pdf\\20200108\\output6666.pdf"));
        document.open();
        document.newPage();
        PdfContentByte cb = writer.getDirectContent();
        PdfImportedPage newPage;
        PdfReader reader;
        reader = new PdfReader(sourceFile);
        int n = reader.getNumberOfPages();
        
        Chunk titleNames = new Chunk(titleName,font);
        titleNames.setNewPage();
        titleNames.setLineHeight(200f);
        Paragraph paragraph02=new Paragraph();
        paragraph02.add(titleNames);
        paragraph02.setFirstLineIndent(200f);
        document.add(paragraph02);
        for (Map.Entry<String, Integer> entry : positionDto.entrySet()) {
            if(map.containsValue(entry.getKey())){
                Paragraph paragraph = new Paragraph();
                document.add(paragraph);
                Chunk chunk0101 = new Chunk(entry.getKey(),font);
                chunk0101.setAction(PdfAction.gotoLocalPage(entry.getValue(), new PdfDestination(PdfDestination.FIT), writer));
                paragraph01.add(chunk0101);
                paragraph01.setFirstLineIndent(200f);
                paragraph01.setIndentationRight(10f);
                document.add(paragraph01);
                paragraph01.clear();
            }else{
                Chunk chunk0101 = new Chunk(entry.getKey(),font);
                Chunk chunk0102 = new Chunk(new DottedLineSeparator());
                Chunk chunk0103 = new Chunk((entry.getValue()+1) + "");
                chunk0101.setAction(PdfAction.gotoLocalPage(entry.getValue()+1, new PdfDestination(PdfDestination.FIT), writer));
                chunk0103.setAction(PdfAction.gotoLocalPage(entry.getValue()+1, new PdfDestination(PdfDestination.FIT), writer));
                paragraph01.add(chunk0101);
                paragraph01.add(chunk0102);
                paragraph01.add(chunk0103);
                paragraph01.setFirstLineIndent(200f);
                paragraph01.setIndentationRight(10f);
                document.add(paragraph01);
                paragraph01.clear();
            }
        }
        Image img = Image.getInstance("./src/main/java/jp/co/softbank/olmapi/common/circle.png"); 
        img.setAlignment(Image.LEFT | Image.TEXTWRAP);  
        img.scaleToFit(25, 25);//大小  
        for (Map.Entry<String, Integer> entry : positionDto.entrySet()) {
            if(map.containsValue(entry.getKey())){
                Paragraph paragraph = new Paragraph();
                document.add(paragraph);
                
                Chunk chunk0101 = new Chunk(img,15,-10);
                chunk0101.setAction(PdfAction.gotoLocalPage(entry.getValue(), new PdfDestination(PdfDestination.FIT), writer));
                paragraph01.add(chunk0101);
                paragraph01.setFont(font);
                paragraph01.add("あ");
                paragraph01.setFirstLineIndent(200f);
                paragraph01.setIndentationRight(10f);
                document.add(paragraph01);
                paragraph01.clear();
            }else{
                Chunk chunk0101 = new Chunk(entry.getKey(),font);
                Chunk chunk0102 = new Chunk(new DottedLineSeparator());
                Chunk chunk0103 = new Chunk((entry.getValue()+1) + "");
                chunk0101.setAction(PdfAction.gotoLocalPage(entry.getValue()+1, new PdfDestination(PdfDestination.FIT), writer));
                chunk0103.setAction(PdfAction.gotoLocalPage(entry.getValue()+1, new PdfDestination(PdfDestination.FIT), writer));
                paragraph01.add(chunk0101);
                paragraph01.add(chunk0102);
                paragraph01.add(chunk0103);
                paragraph01.setFirstLineIndent(200f);
                paragraph01.setIndentationRight(10f);
                document.add(paragraph01);
                paragraph01.clear();
            }
        }
        for (int page = 1; page <= n; page++) {
            document.newPage();
            newPage = writer.getImportedPage(reader, page);
            cb.addTemplate(newPage, 0, 0);
        }
        // レイアウト単ページモードを保存する
        writer.setViewerPreferences(PdfWriter.PageLayoutSinglePage);
        document.close();
        return positionDto1;
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值