如何在Jenkins工作中将汇合页面导出为PDF?

问题描述 投票:0回答:2

我正在使用shell脚本编写Jenkins作业,将Confluence中的页面导出为PDF,并在构建后将其存储为输出。我怎样才能做到这一点?

shell jenkins confluence
2个回答
0
投票

使用wkhtmltopdf执行从html到pdf的转换。

您还可以将现有网站转换为PDF

$wkhtmltopdf  https://wiki.jenkins.io/display/JENKINS/Confluence+Publisher+Plugin#space-menu-link-content demo.pdf

注意:从技术上讲,Google Chrome的渲染引擎是Blink,它是Webkit的一个分支。 Blink和Webkit之间有大约90%的公共代码,所以你应该得到类似的结果。

如果你得到错误

QXcbConnection: Could not connect to display 
Aborted (core dumped)

尝试安装

sudo apt-get install xvfb

然后尝试这个

 xvfb-run wkhtmltopdf  https://wiki.jenkins.io/display/JENKINS/Confluence+Publisher+Plugin#space-menu-link-content demo.pdf

然后,您将在jenkins工作区中找到此pdf文件作为输出。


0
投票

终于找到了解决方案:

curl -D- -u user:password -X GET -H "Content-Type: application/json" "<confluence_ url>/spaces/flyingpdf/pdfpageexport.action?pageId=123456789" > curl_ouput.txt
## Read response and extract URL for downloading file
FILE_LOCATION=$(grep "Location: " curl_ouput.txt | sed 's/Location: //g')
## Remove newline character at the end of the url
FILE_LOCATION=${FILE_LOCATION%?}
## Download PDF file
curl -D- -u user:password -X GET -H "Content-Type: text/html;charset=UTF-8" <confluence_url>${FILE_LOCATION} --output fileName.pdf
rm -f curl_ouput.txt
© www.soinside.com 2019 - 2024. All rights reserved.