Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
5a6e3f13
Commit
5a6e3f13
authored
Oct 26, 2021
by
张辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test gen pdf
parent
3f77bf3e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
0 deletions
+54
-0
pom.xml
community-service/pom.xml
+5
-0
SearchController.java
...java/com/tanpu/community/controller/SearchController.java
+7
-0
PagePdfGenUtils.java
...c/main/java/com/tanpu/community/util/PagePdfGenUtils.java
+42
-0
No files found.
community-service/pom.xml
View file @
5a6e3f13
...
...
@@ -23,6 +23,11 @@
<!-- <artifactId>tanpu-biz-common</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>
io.github.fanyong920
</groupId>
<artifactId>
jvppeteer
</artifactId>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-boot-starter
</artifactId>
...
...
community-service/src/main/java/com/tanpu/community/controller/SearchController.java
View file @
5a6e3f13
...
...
@@ -8,6 +8,7 @@ import com.tanpu.community.api.beans.qo.TopicDetailQo;
import
com.tanpu.community.api.beans.req.search.ThemeFullSearchReq
;
import
com.tanpu.community.api.beans.resp.ThemeFullSearchResp
;
import
com.tanpu.community.manager.ThemeManager
;
import
com.tanpu.community.util.PagePdfGenUtils
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -36,4 +37,10 @@ public class SearchController {
return
CommonResp
.
success
(
resp
);
}
@GetMapping
(
"/testGenPdf"
)
public
CommonResp
testGenPdf
(
@RequestParam
(
"url"
)
String
url
)
{
PagePdfGenUtils
.
genPdf
(
url
);
return
CommonResp
.
success
();
}
}
community-service/src/main/java/com/tanpu/community/util/PagePdfGenUtils.java
0 → 100644
View file @
5a6e3f13
package
com
.
tanpu
.
community
.
util
;
import
com.ruiyun.jvppeteer.core.Puppeteer
;
import
com.ruiyun.jvppeteer.core.browser.Browser
;
import
com.ruiyun.jvppeteer.core.browser.BrowserFetcher
;
import
com.ruiyun.jvppeteer.core.page.Page
;
import
com.ruiyun.jvppeteer.options.LaunchOptions
;
import
com.ruiyun.jvppeteer.options.LaunchOptionsBuilder
;
import
com.ruiyun.jvppeteer.options.PDFOptions
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.ArrayList
;
@Slf4j
public
class
PagePdfGenUtils
{
public
static
void
genPdf
(
String
url
)
{
try
{
BrowserFetcher
.
downloadIfNotExist
(
null
);
ArrayList
<
String
>
argList
=
new
ArrayList
<>();
LaunchOptions
options
=
new
LaunchOptionsBuilder
()
.
withExecutablePath
(
"/usr/bin/google-chrome"
)
.
withArgs
(
argList
)
.
withHeadless
(
true
)
.
build
();
argList
.
add
(
"--no-sandbox"
);
argList
.
add
(
"--disable-setuid-sandbox"
);
Browser
browser
=
Puppeteer
.
launch
(
options
);
Page
page
=
browser
.
newPage
();
page
.
goTo
(
url
);
PDFOptions
pdfOptions
=
new
PDFOptions
();
pdfOptions
.
setPath
(
"/biz/tmp/test.pdf"
);
byte
[]
pdfBytes
=
page
.
pdf
(
pdfOptions
);
page
.
close
();
browser
.
close
();
}
catch
(
Exception
e
)
{
log
.
error
(
"error in genPdf for {}, error: {}"
,
url
,
e
);
}
}
}
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