PHP 中快照的网页高度

发布于 2024-09-01 06:01:18 字数 151 浏览 10 评论 0原文

我们有一个可以拍摄某些网页快照的应用程序。它非常紧密地集成到代码中,因此我们还没有准备好合并另一个库。

但我们没有办法计算网页高度,所以我们最终拍摄了 8000 像素高度的快照。现在事实证明,插入 PDF 时会很麻烦。

有没有办法在PHP中找到网页的高度?

We have an application that takes snapshots of certain web pages. It's quite tightly integrated into the code, so we're not ready to incorporate another library.

But we don't have a way of being able to calculate the web page height, so we end up taking snaps of 8000px height. Which is now proving troublesome when inserted into PDFs.

Is there a way to find the height of the webpage in PHP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

街角卖回忆 2024-09-08 06:01:18

根据定义,不。只有在渲染后才能可靠地判断网页的高度,因为渲染引擎决定它将如何解释所提供的标记。

PHP 没有 HTML 渲染引擎,因此无法使用 PHP 来判断页面高度。

为此,您需要使用快照应用程序。只有该应用程序中内置的渲染器才能为您提供有关网页最终结果的高度的可靠信息。

不要忘记,即使在同一浏览器的不同版本(最突出的是 Internet Explorer)之间,页面高度也可能有所不同,具体取决于 margin padding等进行解释。

如果快照应用程序生成的图像底部空间太大,请考虑使用 ImageMagick 及其 -trim 选项可以删除图像中多余的空间。

By definition, no. You can reliably tell the height of a web page only after it has been rendered, because the rendering engine decides how it is going to interpret the markup provided.

PHP does not have a HTML rendering engine, so it's impossible to tell a page height using PHP.

You need to utilize your snapshot application for this. Only the renderer built into that app can give you reliable info about how tall the web page is going to be in the end result.

Don't forget the page height can vary even between different versions of the same browser (most prominently, Internet Explorer) depending on how margin padding etc. are interpreted.

If the images that the snapshot app produces have too much space to the bottom, consider using ImageMagick and its -trim option that can remove excess space from images.

得不到的就毁灭 2024-09-08 06:01:18

您能不能简单地将页面打印为 PDF 或其他文件格式,而不是截取巨大的屏幕截图?

Rather than taking a giant screenshot, could you not simply print the page to PDF or another file format?

原来是傀儡 2024-09-08 06:01:18

嗯,试试这个: http://www.php.net/manual /en/function.get-browser.php

不过,JavaScript 是一个更好的选择。

Hmm, try this: http://www.php.net/manual/en/function.get-browser.php

JavaScript is a much better option, though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文