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;
}
目录之chuck做成方法
最新推荐文章于 2021-08-16 22:57:06 发布