Ruby:如何输出PDF对象元素?

发布于 2025-01-03 14:39:17 字数 389 浏览 0 评论 0原文

我正在使用嵌入标签在rails视图中嵌入一个pdf文件,我已经用简单的html编写了它并且它工作正常,但我需要在rails约定中编写这个标签。 代码如下:-

<object data="file1.pdf#toolbar=0&amp;navpanes=0&amp;scrollbar=0" type="application/pdf" width="100%" height="720">
  <embed src="file2.pdf#toolbar=0&amp;navpanes=0&amp;scrollbar=0" type="application/pdf" width="100%" height="720" />
</object>

I am embedding a pdf file in rails view using embed tag, i have write it in simple html and its working fine but i need to write this tag in rails conventions.
The code is like:-

<object data="file1.pdf#toolbar=0&navpanes=0&scrollbar=0" type="application/pdf" width="100%" height="720">
  <embed src="file2.pdf#toolbar=0&navpanes=0&scrollbar=0" type="application/pdf" width="100%" height="720" />
</object>

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

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

发布评论

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

评论(1

瞳孔里扚悲伤 2025-01-10 14:39:17

Ruby 似乎使用 print 来输出到客户端......

print 'Hello World!'

没有“嵌入标签”,这是一个“对象元素”;使用正确的术语不仅让您在别人眼中显得更加专业,而且还大大提高了您以更少的步骤进行沟通的能力。 99.9% 的时候人们指的是一个元素,它是整个元素。对标签的一种非常罕见的正确引用可能是这样的:“在 XHTML 中,元元素是自闭合的还是有结束标签?” (例如<元/>或<元>)。

Internet Explorer(像往常一样)有一个错误,在某些情况下(例如使用您的代码)无法正确显示 Flash 对象,我不确定这是否适用于 PDF,但它们都是 Adob​​e 产品,因此最好在IE7是肯定的。您需要有一个电影参数元素。

这是与 Ruby 一起组合在一起的所有内容...

<object class="pdf" data="something.pdf" type="application/pdf">
 <param name="movie" value="something.pdf" />
 <p>This is alternative content that displays if the plugin is not suppoted.</p>
</object>

另一个非常重要的说明:您需要设置高度/宽度或至少设置最小高度和宽度,否则某些浏览器(例如 Firefox)将无法加载资源。事实上,当我更改网站上的主题时,如果尺寸在播放音乐的过程中发生变化,整个 Flash 对象都会重置。对于 PDF 来说,这并不是什么大问题,但如果它强制浏览器重新加载 PDF,则可能会惹恼您的访问者,而这一切都是为了确保您的访问者不会因为第一次就做对事情而感到恼火。

最后,替代内容是出现在对象元素内的任何 (X)HTML。如果客户端的浏览器尚不支持 PDF 插件,您可以添加一个下载链接。

希望这对您有所帮助,如果需要,请随时要求澄清。

It seems Ruby uses print to output to a client...

print 'Hello World!'

There is no "embed tag", that is an "object element"; using the correct terminology not only makes you look more professional to others though also greatly improves your ability to communicate in fewer steps. 99.9% of the time people are referring to an element, it is the whole element. A very rare correct reference to a tag would be something like, "In XHTML does the meta element self close or does it have an end tag?" (e.g. < meta / > or < meta >< / meta >).

Internet Explorer (as usual) has a bug that is unable to display flash objects correctly in certain situations such as with your code, I'm not sure if this applies to a PDF but they're both Adobe products so best to try this in IE7 to be sure. You need to have a movie parameter element.

Here is everything put together along with Ruby...

<object class="pdf" data="something.pdf" type="application/pdf">
 <param name="movie" value="something.pdf" />
 <p>This is alternative content that displays if the plugin is not suppoted.</p>
</object>

Another very important clarification: you need to have a height/width set or at least a minimum height and width set otherwise certain browsers (e.g. Firefox) will not load the resource. In fact when I change themes on my site if the dimensions change in the middle of the music playing the whole Flash object resets. Not such a big issue for a PDF though if it forces the browser to reload the PDF it may annoy your visitor and it's ALL about making sure your visitors aren't annoyed by doing things right the first time.

Lastly alternative content is any (X)HTML that appears inside the object element. You can add a link to download a PDF plugin if the client's browser doesn't already support one.

Hope this helps, feel free to ask for clarifications if need be.

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