评论
:除了显示服务器之外,让PDFSharp在Mono上运行还有更多问题。我还必须更新apt源代码并安装Microsoft Core字体,因为我生成的报告使用它们。
我还必须使用PDFSharp的修改版本,它知道如何定位字体。幸运的是,我已经做到了:
https://github.com/daniellor/PDFsharp
相关代码如下:
https://github.com/daniellor/PDFsharp/blob/master/src/PdfSharp/Fonts/FontLocalizator.cs
有点黑客,你可能需要修改它,以适应您的设置,但它做的工作。只要创建一个MonoRelease构建并引用这个程序集,就可以了。
Dockerfile文件
FROM mono:latest
# Update the sources.list for apt-get so it knows where to download the Microsoft Core fonts.
RUN echo "deb http://gce_debian_mirror.storage.googleapis.com wheezy contrib non-free" >> /etc/apt/sources.list \
&& echo "deb http://gce_debian_mirror.storage.googleapis.com wheezy-updates contrib non-free" >> /etc/apt/sources.list \
&& echo "deb http://security.debian.org/ wheezy/updates contrib non-free" >> /etc/apt/sources.list
# Install Xvfb and the Microsoft core fonts
RUN apt-get update
RUN apt-get install -y xvfb ttf-mscorefonts-installer
# Configure Xvfb as a daemon.
ADD xvfb.init /etc/init.d/xvfb
RUN chmod +x /etc/init.d/xvfb
RUN update-rc.d xvfb defaults
EXPOSE 5000
ENV PORT 5000
ADD ./ /api
WORKDIR /api
RUN nuget restore -NonInteractive
RUN msbuild webapi.sln /p:Configuration=Release
# Start Xvfb and the Web Api
CMD (service xvfb start; export DISPLAY=:10; mono /api/MyProject/bin/Release/MyProject.exe port:$PORT)
xvfb。初始化
#!/bin/bash
#
# /etc/rc.d/init.d/xvfbd
#
# chkconfig: 345 95 28
# description: Starts/Stops X Virtual Framebuffer server
# processname: Xvfb
#
[ "${NETWORKING}" = "no" ] && exit 0
PROG="/usr/bin/Xvfb"
PROG_OPTIONS=":10 -ac"
PROG_OUTPUT="/tmp/Xvfb.out"
case "$1" in
start)
echo -n "Starting : X Virtual Frame Buffer "
$PROG $PROG_OPTIONS>>$PROG_OUTPUT 2>&1 &
disown -ar
;;
stop)
echo -n "Shutting down : X Virtual Frame Buffer"
killproc $PROG
RETVAL=$?
[ $RETVAL -eq 0 ] && /bin/rm -f /var/lock/subsys/Xvfb/var/run/Xvfb.pid
echo
;;
restart|reload)
$0 stop
$0 start
RETVAL=$?
;;
status)
status Xvfb
RETVAL=$?
;;
*)
echo $"Usage: $0 (start|stop|restart|reload|status)"
exit 1
esac
exit $RETVAL