[英]Problem centering an image with : “margin : auto and display block” and parsing from XHTML to PDF using FlyingSaucer (Itext5)
我正在嘗試使用FlyingSaucer將帶有居中圖像的xhtml解析為PDF。
圖像使用css居中:
img.center {
display: block;
margin-bottom: 1px;
margin-left: auto;
margin-right: auto;
margin-top: 1px;
}
並且在瀏覽器上顯示時居中。 codePen鏈接
問題是,當我嘗試使用相同的xhtml文件和FlyingSaucer Library創建PDF時:圖像不再居中。
PDFRenderer.renderToPDF(htmlFile, "pdf_file.pdf");
我嘗試了幾種不同的方法,但似乎都無法正常工作。
對我有用的唯一方法是在img中添加width屬性。
但是, xhtml是外部Web服務提供的輸入,不能更改 。
在文件接收后添加width屬性是可行的,但是很臟(您可以在下面的github存儲庫中找到示例代碼)
您是否有想法在不更改html或css的情況下以與瀏覽器相同的方式在PDF中顯示此圖像?
https://github.com/Shask/FlyingSaucerXHTMLToPdfBug
PS:我很高興更改解析庫,因此到目前為止,我嘗試了其他版本的FlyingSaucer(使用Itext5,另一個使用OpenPDF)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.