Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mid-service
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
mid-service
Commits
8e0a5a58
Commit
8e0a5a58
authored
Dec 24, 2024
by
周亚武
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
url pdf打印
parent
dbbf101b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
src/main/java/com/mortals/xhx/module/print/service/PrintComponent/Base64PrintComponent.java
...le/print/service/PrintComponent/Base64PrintComponent.java
+7
-4
src/main/java/com/mortals/xhx/module/print/service/PrintComponent/NormalPrintComponent.java
...le/print/service/PrintComponent/NormalPrintComponent.java
+8
-3
No files found.
src/main/java/com/mortals/xhx/module/print/service/PrintComponent/Base64PrintComponent.java
View file @
8e0a5a58
...
...
@@ -2,6 +2,7 @@ package com.mortals.xhx.module.print.service.PrintComponent;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.extra.spring.SpringUtil
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.xhx.common.code.Base64TypeEnum
;
import
com.mortals.xhx.common.code.PrintTypeEnum
;
...
...
@@ -23,7 +24,7 @@ public class Base64PrintComponent extends BasePrintComponent {
}
@Override
public
void
print
(
ComponentCons
cons
)
{
public
Rest
<
Void
>
print
(
ComponentCons
cons
)
{
PrintService
printService
=
getPrintService
(
cons
);
//base64 转换成图片 等其它 data:image/jpg;base64,/9j/4AAQSkZJRgA
String
base64
=
cons
.
getBase64
();
...
...
@@ -35,7 +36,7 @@ public class Base64PrintComponent extends BasePrintComponent {
String
head
=
split
.
get
(
0
);
String
base64Content
=
split
.
get
(
1
);
if
(
Base64TypeEnum
.
BASE64_FILETYPE_JPG
.
getDesc
().
equalsIgnoreCase
(
head
)){
return
Rest
.
fail
(
"暂不支持该格式"
);
}
else
if
(
Base64TypeEnum
.
BASE64_FILETYPE_TXT
.
getDesc
().
equalsIgnoreCase
(
head
)){
String
destFile
=
filePath
+
File
.
separator
+
new
Date
().
getTime
()
+
"."
+
Base64TypeEnum
.
BASE64_FILETYPE_TXT
.
getValue
();
//Base64Util.decodeBase64(destFile,base64Content);
...
...
@@ -50,8 +51,10 @@ public class Base64PrintComponent extends BasePrintComponent {
Doc
doc
=
new
SimpleDoc
(
bytes
,
flavor
,
das
);
try
{
job
.
print
(
doc
,
pras
);
return
Rest
.
ok
();
}
catch
(
PrintException
e
)
{
throw
new
RuntimeException
(
e
);
// throw new RuntimeException(e);
return
Rest
.
fail
(
"打印错误"
);
}
//Base64Util.decodeBase64String()
...
...
@@ -62,7 +65,7 @@ public class Base64PrintComponent extends BasePrintComponent {
//判断base64文件类型 生成不同类型文件
return
Rest
.
ok
();
...
...
src/main/java/com/mortals/xhx/module/print/service/PrintComponent/NormalPrintComponent.java
View file @
8e0a5a58
package
com.mortals.xhx.module.print.service.PrintComponent
;
import
cn.hutool.extra.spring.SpringUtil
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.util.DataUtil
;
import
com.mortals.xhx.common.code.PaperTypeEnum
;
...
...
@@ -33,7 +34,7 @@ public class NormalPrintComponent extends BasePrintComponent {
}
@Override
public
void
print
(
ComponentCons
cons
)
{
public
Rest
<
Void
>
print
(
ComponentCons
cons
)
{
String
ticketType
=
SpringUtil
.
getProperty
(
"print.ticket"
);
//创建打印文档
Book
book
=
new
Book
();
...
...
@@ -109,13 +110,17 @@ public class NormalPrintComponent extends BasePrintComponent {
HashPrintRequestAttributeSet
pars
=
new
HashPrintRequestAttributeSet
();
pars
.
add
(
Sides
.
ONE_SIDED
);
// 设置单双页
printerJob
.
print
(
pars
);
return
Rest
.
ok
();
}
else
{
log
.
info
(
"打印失败,未找到名称为"
+
cons
.
getPrintername
()
+
"的打印机,请检查。"
);
throw
new
AppException
(
"打印失败,未找到名称为"
+
cons
.
getPrintername
()
+
"的打印机,请检查。"
);
return
Rest
.
fail
(
"打印失败,未找到名称为"
+
cons
.
getPrintername
()
+
"的打印机,请检查。"
);
// throw new AppException("打印失败,未找到名称为" + cons.getPrintername() + "的打印机,请检查。");
}
}
catch
(
PrinterException
e
)
{
log
.
error
(
"打印异常"
,
e
);
throw
new
AppException
(
e
.
getMessage
());
return
Rest
.
fail
(
"打印异常"
);
// throw new AppException(e.getMessage());
}
}
...
...
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