/**
* 添加艺术字
* @param cb
* @param page_width 页面宽度
* @param page_height 页面高度
* @param font_path 文字路径
* @param font_content 文字内容
* @param font_x 文字x坐标
* @param font_y 文字y坐标
* @param font_size 文字字号
* @param font_alignment 文字对齐方式
* @param font_rotate 文字旋转角度
* @param image_path 图片路径
* @param image_x 图片x坐标
* @param image_y 图片y坐标
* @param image_width 图片宽度
* @param image_height 图片高度
* @throws DocumentException
* @throws IOException
*/
public static void addArtText(PdfContentByte cb,float page_width,float page_height, String font_path, String font_content, float font_x, float font_y, float font_size, int font_alignment, float font_rotate, String image_path, float image_x, float image_y, float image_width, float image_height) throws DocumentException, IOException {
PdfTemplate pdfTemplate = cb.createTemplate(page_width,page_height);
float pt = 72f/25.4f;
pdfTemplate.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_CLIP);
BaseFont baseFont = BaseFont.createFont(font_path, "Identity-H", false);
pdfTemplate.beginText();
pdfTemplate.setFontAndSize(baseFont, font_size);
pdfTemplate.showTextAligned(font_alignment, font_content, font_x, font_y, font_rotate);
pdfTemplate.endText();
Image image = Image.getInstance(image_path);
pdfTemplate.addImage(image, image_width*pt, 0, 0,image_height*pt, image_x, image_y);
cb.addTemplate(pdfTemplate,0,0);
}
java itext5 插入一个艺术文字 (剪切蒙版)
于 2022-01-27 09:27:40 首次发布