public class PDFDoc extends TextDoc
这个类封装 PDF 文档相关的操作,通过 iText 实现。 如果需要水印、印章等特殊效果,请参考 PDFProcess 类。
| 限定符和类型 | 类和说明 |
|---|---|
protected class |
PDFDoc.PaginationEventHandler |
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
FONT_FAMILY_HEI |
static int |
FONT_FAMILY_SONG |
protected InputStream |
templateInputStream |
encoding, outputStream, pageMarginBottom, pageMarginLeft, pageMarginRight, pageMarginTop, pageSize| 构造器和说明 |
|---|
PDFDoc(InputStream templateInputStream,
OutputStream outputStream) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addHrule(Attributes attrs)
水平线
|
void |
addImage(Attributes attrs)
添加一个图片
|
void |
close()
关闭文档
|
boolean |
isOpen()
文档是否打开
|
void |
newPage()
换页
|
boolean |
open()
打开文档
|
void |
setBlockDefault(com.janeluo.easypdf.BlockType blockType,
int fontFamily,
int fontSize,
com.janeluo.easypdf.FontStyle fontStyle,
com.itextpdf.layout.property.TextAlignment alignment,
float indent,
float lineSpaceBefore,
float lineSpaceAfter)
设置块默认属性
这个函数一次性设置所有的块默认属性,如果需要单独设置某一个属性,
请使用下面的 setBlockDefaultXXX() 函数。
|
void |
setBlockDefaultAlignment(com.janeluo.easypdf.BlockType blockType,
com.itextpdf.layout.property.TextAlignment alignment)
设置块的默认对齐方式
|
void |
setBlockDefaultFontFamily(com.janeluo.easypdf.BlockType blockType,
int fontFamily)
设置块的默认字体家族
|
void |
setBlockDefaultFontSize(com.janeluo.easypdf.BlockType blockType,
int fontSize)
设置块的默认字体大小
|
void |
setBlockDefaultFontStyle(com.janeluo.easypdf.BlockType blockType,
com.janeluo.easypdf.FontStyle fontStyle)
设置块的默认字体风格
|
void |
setBlockDefaultIndent(com.janeluo.easypdf.BlockType blockType,
float indent)
设置块的默认首行缩进距离
|
void |
setBlockDefaultLineSpaceAfter(com.janeluo.easypdf.BlockType blockType,
float lineSpaceAfter)
设置段后空间
|
void |
setBlockDefaultLineSpaceBefore(com.janeluo.easypdf.BlockType blockType,
float lineSpaceBefore)
设置段前空间
|
void |
setPageMargin(int left,
int right,
int top,
int bottom)
设置页面边距
|
void |
setPageSize(com.itextpdf.kernel.geom.PageSize pageSize)
设置页面大小
|
void |
writeBlock(String blockName,
List<TextChunk> chunkList)
添加一块内容到 PDF 文档,块可以为 Title、Section、等等,
参考类前面的数组定义
|
void |
writeTable(TextTable table)
添加表格
|
setEncodingpublic static final int FONT_FAMILY_HEI
public static final int FONT_FAMILY_SONG
protected InputStream templateInputStream
public PDFDoc(InputStream templateInputStream, OutputStream outputStream)
public void setPageSize(com.itextpdf.kernel.geom.PageSize pageSize)
TextDocsetPageSize 在类中 TextDocpublic void setPageMargin(int left,
int right,
int top,
int bottom)
TextDocsetPageMargin 在类中 TextDocpublic void setBlockDefault(com.janeluo.easypdf.BlockType blockType,
int fontFamily,
int fontSize,
com.janeluo.easypdf.FontStyle fontStyle,
com.itextpdf.layout.property.TextAlignment alignment,
float indent,
float lineSpaceBefore,
float lineSpaceAfter)
blockType - 块类型fontFamily - 字体家族fontSize - 字体大小fontStyle - 字体风格alignment - 对齐方式indent - 首行缩进距离public void setBlockDefaultFontFamily(com.janeluo.easypdf.BlockType blockType,
int fontFamily)
blockType - 类型fontFamily - 字体public void setBlockDefaultFontSize(com.janeluo.easypdf.BlockType blockType,
int fontSize)
blockType - 类型fontSize - 字体大小public void setBlockDefaultFontStyle(com.janeluo.easypdf.BlockType blockType,
com.janeluo.easypdf.FontStyle fontStyle)
blockType - 类型fontStyle - 字体样式public void setBlockDefaultAlignment(com.janeluo.easypdf.BlockType blockType,
com.itextpdf.layout.property.TextAlignment alignment)
blockType - 类型alignment - 对齐方式public void setBlockDefaultIndent(com.janeluo.easypdf.BlockType blockType,
float indent)
blockType - 类型indent - 首航缩进大小public void setBlockDefaultLineSpaceBefore(com.janeluo.easypdf.BlockType blockType,
float lineSpaceBefore)
blockType - 类型lineSpaceBefore - 行上面空行大小public void setBlockDefaultLineSpaceAfter(com.janeluo.easypdf.BlockType blockType,
float lineSpaceAfter)
blockType - 类型lineSpaceAfter - 下面空行大小public void writeBlock(String blockName, List<TextChunk> chunkList)
writeBlock 在类中 TextDocblockName - 块类型名,例如 title, section 等等chunkList - 本块的内容,一个块包含多个 chunk,它们通过列表保存public void addHrule(Attributes attrs)
TextDocpublic void addImage(Attributes attrs)
public void writeTable(TextTable table)
TextDocwriteTable 在类中 TextDoctable - 表格Copyright © 2021. All rights reserved.