将HTML页面转换为PDF时的视觉错误
在PDF渲染网站时,我有一个视觉错误。正如您在屏幕截图上看到的那样,图像发生了变化。但是在HTML上渲染这种转变并不存在。
要转换的网站的链接: https://betterhost-3fadc.web.web.app/
<article>
<div class="container"><img
src="https://www.electrodepot.fr/fstrz/r/s/www.electrodepot.fr/media/catalog/product/cache/1a40d1f945549a9ec18309b0a600e55c/P939881.jpg?frz-v=2690"><img
src="https://www.electrodepot.fr/media/catalog/product/cache/1a40d1f945549a9ec18309b0a600e55c/P959338.jpg"><img
src="https://www.alinea.com/fstrz/r/s/www.alinea.com/dw/image/v2/BCKM_PRD/on/demandware.static/-/Sites-ali_master/default/dwb3523209/images/27339299/POUBELLE-DAYA-27339299-F-1.jpg?sw=982&sh=982&sm=fit&sfrm=png&bgcolor=eef1eb&frz-v=103"><img
src="https://cdn.sklum.com/fr/1172047/distributeur-de-savon-en-verre-ovie.jpg"><img
src="https://www.alinea.com/fstrz/r/s/www.alinea.com/dw/image/v2/BCKM_PRD/on/demandware.static/-/Sites-ali_master/default/dw32eea630/images/27258507/BROSSE-WC-SPINA-27258507-F-1.jpg?sw=982&sh=982&sm=fit&sfrm=png&bgcolor=eef1eb&frz-v=103"><img
src="https://www.electrodepot.fr/fstrz/r/s/www.electrodepot.fr/media/catalog/product/cache/1a40d1f945549a9ec18309b0a600e55c/P963865.jpg?frz-v=2690"><img
src="https://cdn.sklum.com/fr/1172188/gobelet-en-verre-ovie.jpg"></div>
<cactus>
每个页面都在一个称为文章的块中。
article {
position: relative;
display: flex;
width: 827px;
height: 1170px;
overflow: hidden;
margin: 0px;
}
图像通过此CSS代码在2列中排列在2列中:
.container {columns: 2;width: 50%;column-gap: 0px;height: auto;}
web:
href =“ https://i.sstatic.net/8adkc.png” rel =“ nofollow noreferrer”>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要专用的打印样式表来制作可靠的PDF。使用媒体查询制作样式表进行打印。在您的标记中,在一个称为.page的容器中,将所有a4的所有内容都包含在一张a4中。然后在您的打印样式表中,使用@page探索以格式化PDF。
在print.css中
,应该在类=“ page”容器中停止布局的布局在两个页面上破裂。尝试在打印样式表中使用真实尺寸,以使所有内容都适合您所需的一页。您可以通过执行CTRL+P来查看打印预览,或者实际上从Chrome中保存到PDF来查看PDF的外观。
那应该从正确的方向开始。
编辑:其他一些指针
将其删除默认利润率,当打印
将页面容器设置为几乎与要打印的页面大小
You need a dedicated print style sheet to make reliable PDFs. use a media query to make a style sheet for print. In your markup have everything for one sheet of a4 in a container called something like .page. Then in your print style sheet, explore using @page to format the pdf.
in print.css
That should stop your layout within your class="page" container from breaking across two pages. Experiment with using real dimensions in your print style sheet to make everything fit on one page as you want. You can see what your pdf is going to look like by doing ctrl+p to see the print preview, or actually saving to pdf from chrome.
That should start you in the right direction.
EDIT: some other pointers
put this to take the default margins off when printing
Set your page container to nearly the size of the page you want to print