Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vehicle-quality-review
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王飞
vehicle-quality-review
Commits
04558298
Commit
04558298
authored
Jan 19, 2024
by
盖献康
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
表格一个cell图文混合-demo、PDF写入器(工具类-待完善)
parent
8840ebf2
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
955 additions
and
131 deletions
+955
-131
PdfTestVO.java
...y-review/src/main/java/com/ruoyi/domain/vo/PdfTestVO.java
+59
-0
BookService.java
...y-review/src/main/java/com/ruoyi/service/BookService.java
+8
-0
BookServiceImpl.java
...src/main/java/com/ruoyi/service/impl/BookServiceImpl.java
+135
-21
BookController.java
...ty-review/src/main/java/com/ruoyi/web/BookController.java
+5
-1
PdfBaseWriter.java
...n/src/main/java/com/ruoyi/common/utils/PdfBaseWriter.java
+748
-0
PdfUtils.java
...common/src/main/java/com/ruoyi/common/utils/PdfUtils.java
+0
-109
No files found.
quality-review/src/main/java/com/ruoyi/domain/vo/PdfTestVO.java
0 → 100644
View file @
04558298
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
;
}
quality-review/src/main/java/com/ruoyi/service/BookService.java
View file @
04558298
...
...
@@ -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
;
}
quality-review/src/main/java/com/ruoyi/service/impl/BookServiceImpl.java
View file @
04558298
This diff is collapsed.
Click to expand it.
quality-review/src/main/java/com/ruoyi/web/BookController.java
View file @
04558298
...
...
@@ -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
();
}
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/PdfBaseWriter.java
0 → 100644
View file @
04558298
This diff is collapsed.
Click to expand it.
ruoyi-common/src/main/java/com/ruoyi/common/utils/PdfUtils.java
deleted
100644 → 0
View file @
8840ebf2
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
(
20
f
);
// 设置段落上空白
paragraph
.
setSpacingBefore
(
5
f
);
// 设置段落下空白
paragraph
.
setSpacingAfter
(
10
f
);
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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment