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
ac26adaf
Commit
ac26adaf
authored
1 year ago
by
周亚武
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
url打印
parent
fa19d220
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
5 deletions
+36
-5
src/main/java/com/mortals/xhx/ManagerApplication.java
src/main/java/com/mortals/xhx/ManagerApplication.java
+8
-0
src/main/java/com/mortals/xhx/busiz/web/ApiController.java
src/main/java/com/mortals/xhx/busiz/web/ApiController.java
+1
-2
src/main/java/com/mortals/xhx/module/print/service/PrintComponent/UrlPrintComponent.java
...odule/print/service/PrintComponent/UrlPrintComponent.java
+21
-0
src/test/java/httpclient/print/PrintTest.java
src/test/java/httpclient/print/PrintTest.java
+6
-3
No files found.
src/main/java/com/mortals/xhx/ManagerApplication.java
View file @
ac26adaf
package
com.mortals.xhx
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.framework.service.impl.LocalCacheServiceImpl
;
import
com.mortals.framework.springcloud.boot.BaseWebApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.web.servlet.ServletComponentScan
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
//@SpringBootApplication(scanBasePackages = {"com.mortals"},exclude= {DataSourceAutoConfiguration.class})
@SpringBootApplication
(
scanBasePackages
=
{
"com.mortals"
},
exclude
={
DataSourceAutoConfiguration
.
class
})
...
...
@@ -13,6 +16,11 @@ import org.springframework.context.ApplicationContext;
//@ImportResource(locations = {"classpath:config/spring-config.xml"})
public
class
ManagerApplication
extends
BaseWebApplication
{
@Bean
public
ICacheService
cacheService
()
{
return
new
LocalCacheServiceImpl
();
}
public
static
void
main
(
String
[]
args
)
{
/* SpringApplication.run(ManagerApplication.class, args);*/
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/mortals/xhx/busiz/web/ApiController.java
View file @
ac26adaf
...
...
@@ -51,8 +51,7 @@ public class ApiController extends BaseAbstractApiController {
ApiResp
<
Object
>
assessResp
=
handle
(
JSON
.
toJSONString
(
reqMap
),
"busizAssessmentReqHandler"
);
return
assessResp
;
case
BUSIZ_PRINT:
ApiResp
<
Object
>
rest
=
handle
(
JSON
.
parseObject
(
reqJson
,
new
TypeReference
<
Map
<
String
,
Object
>>()
{
}),
"busizPrintReqHandler"
);
ApiResp
<
Object
>
rest
=
handle
(
JSON
.
parseObject
(
reqJson
,
PrintReq
.
class
),
"busizPrintReqHandler"
);
return
rest
;
case
BUSIZ_PRINTLIST:
//获取打印机列表
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/mortals/xhx/module/print/service/PrintComponent/UrlPrintComponent.java
View file @
ac26adaf
...
...
@@ -5,6 +5,13 @@ import cn.hutool.http.HttpUtil;
import
com.mortals.xhx.common.code.PrintTypeEnum
;
import
lombok.extern.slf4j.Slf4j
;
import
javax.print.*
;
import
javax.print.attribute.DocAttributeSet
;
import
javax.print.attribute.HashDocAttributeSet
;
import
javax.print.attribute.HashPrintRequestAttributeSet
;
import
javax.print.attribute.PrintRequestAttributeSet
;
import
javax.print.attribute.standard.Copies
;
@Slf4j
public
class
UrlPrintComponent
extends
BasePrintComponent
{
...
...
@@ -14,12 +21,26 @@ public class UrlPrintComponent extends BasePrintComponent {
@Override
public
void
print
(
ComponentCons
cons
)
{
PrintService
printService
=
getPrintService
(
cons
);
//通过网络下载附件地址
byte
[]
fileBytes
=
HttpUtil
.
downloadBytes
(
cons
.
getUrl
());
//获取文件后缀
String
suffixName
=
FileUtil
.
getSuffix
(
cons
.
getUrl
());
log
.
info
(
"file lens:{}"
,
fileBytes
.
length
);
log
.
info
(
"file suffixName:{}"
,
suffixName
);
//打印文件
DocFlavor
flavor
=
DocFlavor
.
BYTE_ARRAY
.
AUTOSENSE
;
DocPrintJob
job
=
printService
.
createPrintJob
();
PrintRequestAttributeSet
pras
=
new
HashPrintRequestAttributeSet
();
DocAttributeSet
das
=
new
HashDocAttributeSet
();
pras
.
add
(
new
Copies
(
1
));
Doc
doc
=
new
SimpleDoc
(
fileBytes
,
flavor
,
das
);
try
{
job
.
print
(
doc
,
pras
);
}
catch
(
PrintException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/httpclient/print/PrintTest.java
View file @
ac26adaf
...
...
@@ -29,8 +29,9 @@ public class PrintTest {
@Before
public
void
init
(){
//domain="http://127.0.0.1:8037";
domain
=
"http://192.168.0.43:8037"
;
// domain="http://127.0.0.1:8037";
// domain="http://192.168.0.43:8037";
domain
=
"http://127.0.0.1:80"
;
}
@Test
...
...
@@ -123,7 +124,7 @@ public class PrintTest {
@Test
public
void
testPrintBase64
()
{
File
file
=
new
File
(
"
F
:\\test.txt"
);
File
file
=
new
File
(
"
G
:\\test.txt"
);
String
prefix
=
"txt"
;
// base64文件内容
...
...
@@ -134,12 +135,14 @@ public class PrintTest {
printReq
.
setPrintertype
(
PrintTypeEnum
.
PRINT_BASE64
.
getValue
());
printReq
.
setBase64
(
base64String
);
printReq
.
setPrintername
(
"NPI607A1C (HP LaserJet Professional M1213nf MFP)"
);
//printReq.setPrinterpaperwidth("140");
String
url
=
domain
+
"/GetHardWareInfo"
;
HashMap
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"GetType"
,
"71"
);
params
.
put
(
"PrinterJson"
,
JSON
.
toJSONString
(
printReq
));
log
.
info
(
"PrinterJson:"
+
JSON
.
toJSONString
(
printReq
));
String
rest
=
HttpUtil
.
post
(
url
,
params
);
log
.
info
(
"打印响应结果:"
+
rest
);
}
...
...
This diff is collapsed.
Click to expand it.
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