print css: fit in one page

丶灬走出姿态 提交于 2020-06-24 08:38:09

问题


In my page there's only one image. Kind of 1500x3000 px.
In the printer, I need that this image's maximum width to be the width of the page, so I did: width 100% in the css, and it works.
But the height... the old bullshit of height 100% will never work. Because it always will be 100% of the parent container, then someone must have height defined. Or html or body.
So, my question is: make this image fit in one page.
Any ideas?


回答1:


One way to do it would be to perform some calculations to find out what width would cause the length to be exactly one page, and then set your width in the CSS accordingly.




回答2:


If I understand this right, could you do

.OnePageImage { height: 100%; width: 600px; }

Where 600px (the width) is the total width of the page. Then the image would fit on one page (albeit with some distortion potentially). You could also add a css page break style to a div before and after the image, which is done like this:

.break { page-break-after:always; }

Then the code would look like this:

<div class="break"></div>
<img src="[your image src]" class="OnePageImage" />
<div class="break"></div>



回答3:


Ok sorry for putting the "solution" as a comment:

What I've ended up doing was assume that 99% of the clients (that's true) they use a single page size. So I put some warning in the print interface that will only work with the page size "X". too bad. but it's working out so far




回答4:


The only thing that limited the print output to a single page for me was setting the height in cm of a container element that wrapped the entire page, and also setting it's overflow to hidden. For some reason this didn't seem to work on the body element.

body > section { padding:0 !important; margin:0 !important; height:25.7cm !important; overflow:hidden !important; }

Incidentally, I had hoped that setting page-break-inside to avoid on the body or the container element might have been the solution to limiting to a single print page but that doesn't seem to have any effect at all.



来源:https://stackoverflow.com/questions/2435036/print-css-fit-in-one-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!