Commit 04558298 authored by 盖献康's avatar 盖献康

表格一个cell图文混合-demo、PDF写入器(工具类-待完善)

parent 8840ebf2
package com.ruoyi.domain.vo;
import lombok.Builder;
import lombok.Data;
/**
* PDF的测试VO类
* @author gxk
*/
@Data
@Builder
public class PdfTestVO {
/**
* 测试编号
*/
private String testNumber;
/**
* 样品编号
*/
private String sampleNumber;
/**
* 检测项目
*/
private String testItem;
/**
* 风险等级
*/
private String riskLevel;
/**
* 测试方法
*/
private String testMethod;
/**
* 测试结果
*/
private String testResult;
/**
* 漏洞危害
*/
private String vulnerabilityHazard;
/**
* 测试详情
*/
private String testDetails;
/**
* 修复建议
*/
private String repairSuggestion;
}
......@@ -37,4 +37,12 @@ public interface BookService extends IService<Book> {
* @throws Exception
*/
void generateTempPDF(HttpServletResponse response) throws Exception;
/**
* 测试生成PDF
* @param os
* @return
* @throws Exception
*/
Document testGeneratePDF(OutputStream os) throws Exception;
}
......@@ -84,8 +84,12 @@ public class BookController extends BaseController {
public void download(HttpServletResponse response) {
response.setHeader("content-disposition","attachment;fileName="+"ReceiptPrinter.pdf");
try {
// demo-API选软
// bookService.generateItextPdfDocument(response.getOutputStream());
bookService.generateTempPDF(response);
// demo-模板
// bookService.generateTempPDF(response);
// demo-动态表格
bookService.testGeneratePDF(response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
......
package com.ruoyi.common.utils;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import java.io.IOException;
/**
* PDF工具类
* @author gxk
*/
public class PdfUtils {
/**
* 标题
* @param content
* @return
* @throws IOException
* @throws DocumentException
*/
public static Paragraph createTitle(String content) throws IOException, DocumentException {
Font font = new Font(getBaseFont(), 24, Font.BOLD);
Paragraph paragraph = new Paragraph(content, font);
paragraph.setAlignment(Element.ALIGN_CENTER);
return paragraph;
}
/**
* H1标题
* @param content
* @return
* @throws IOException
* @throws DocumentException
*/
public static Paragraph createChapterH1(String content) throws IOException, DocumentException {
Font font = new Font(getBaseFont(), 22, Font.BOLD);
Paragraph paragraph = new Paragraph(content, font);
paragraph.setAlignment(Element.ALIGN_LEFT);
return paragraph;
}
/**
* H2标题
* @param content
* @return
* @throws IOException
* @throws DocumentException
*/
public static Paragraph createChapterH2(String content) throws IOException, DocumentException {
Font font = new Font(getBaseFont(), 18, Font.BOLD);
Paragraph paragraph = new Paragraph(content, font);
paragraph.setAlignment(Element.ALIGN_LEFT);
return paragraph;
}
/**
* 段
* @param content
* @return
* @throws IOException
* @throws DocumentException
*/
public static Paragraph createParagraph(String content) throws IOException, DocumentException {
Font font = new Font(getBaseFont(), 12, Font.NORMAL);
Paragraph paragraph = new Paragraph(content, font);
paragraph.setAlignment(Element.ALIGN_LEFT);
// 设置左缩进
paragraph.setIndentationLeft(12);
// 设置右缩进
paragraph.setIndentationRight(12);
// 设置首行缩进
paragraph.setFirstLineIndent(24);
// 行间距
paragraph.setLeading(20f);
// 设置段落上空白
paragraph.setSpacingBefore(5f);
// 设置段落下空白
paragraph.setSpacingAfter(10f);
return paragraph;
}
/**
* 表格内容
* @param content
* @return
* @throws IOException
* @throws DocumentException
*/
public static PdfPCell createCell(String content) throws IOException, DocumentException {
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
Font font = new Font(getBaseFont(), 12, Font.NORMAL);
cell.setPhrase(new Phrase(content, font));
return cell;
}
/**
* 字体
* @return
* @throws IOException
* @throws DocumentException
*/
public static BaseFont getBaseFont() throws IOException, DocumentException {
return BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment