如何在 Jenkins 作业中将汇合页面导出为 PDF?
How to export a confluence page as PDF in Jenkins job?
我在 shell 脚本的帮助下编写 Jenkins 作业,以将 Confluence 中的页面导出为 PDF 并在构建后将其存储为输出。
我怎样才能做到这一点?
使用 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 文件作为输出。
终于找到解决办法了:
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
我在 shell 脚本的帮助下编写 Jenkins 作业,以将 Confluence 中的页面导出为 PDF 并在构建后将其存储为输出。 我怎样才能做到这一点?
使用 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 文件作为输出。
终于找到解决办法了:
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