【问题标题】:Allowing <img> tags in Content-type: application/msword允许在 Content-type 中使用 <img> 标签:application/msword
【发布时间】:2011-01-26 10:14:22
【问题描述】:

现在,我一切都好。它根据我的 CSS (text-align: center;) 打印。
我唯一的问题是图像。这是 HTML 代码:

<table id="cert">  
    <td>  
        <tr><h1>Singapore Aviation Academy</h1></tr>  
        <tr><img src = "img/logo1.jpg" /></tr>  
        <tr><h2>Certificate of Completion </h2></tr>  
        <tr>is hereby granted to</tr>  
        <tr><?php echo "<b>".$row['fname']."&nbsp;&nbsp;".$row['lname']."</b>"; ?> </tr>  
        <tr>to certify that he/she has completed to satisfaction for</tr>  
        <tr><?php echo "<b>".$row1['course_title']."</b>"; ?></tr>  
    </td>  
</table>  

紧接着:

<?php       
//This php will enable documents to be embedded with Microsoft Word

header("Content-type: application/msword"); //Document will be embedded using the application, Microsoft Word  
header("Content-disposition: attachment; filename= \"Certificate for ".$row['fname']." ".$row['lname']."\""); //States the file name when opened to edit or view  
?>

问题在于&lt;img&gt; 标签。没有最后几行 PHP 代码,图像就会出现。有了它,图像就不会显示在 MS-Word 中了。

知道如何解决这个问题吗?

【问题讨论】:

  • 每当我看到有人试图将 HTML 标记作为 MS Office 文档传递出去时,我都会感到畏缩,只是在更改标题
  • &lt;img&gt; 标签与 MS Word 有什么关系?
  • @Mark Ba​​ker:这是我看到的第一条领带,但我的一部分灵魂已经死了......
  • 每当有人将 HTML 作为 MS Office 数据传递时,小猫都会发生这种情况:startrek.com/legacy_media/images/200506/ds9-437-arjin002/…

标签: php image ms-word content-type


【解决方案1】:

在 Word 中打开时不会显示图像,因为 Word 正在客户端桌面上运行并在本地查找图像...除非您为图像文件指定完整 URL,否则它不知道在您的服务器。

选项:

  • 修改您的 HTML,以便嵌入图像二进制文件而不是链接
  • 使用图片的完整网址
  • 创建一个“真实”的 Word 文档,正确嵌入图片而不是链接
  • 创建一个嵌入而不是链接或使用完整 URL 链接的图像的 PDF

【讨论】:

  • 我什至不确定如何创建完整的 PDF。我不断收到错误。
  • 对于诸如告诉全世界持有人有资格和安全驾驶飞机的证书之类的东西,我建议您使用 PDF(编辑起来更费力)而不是文档中的任何人世界可以编辑以显示自己的名字。
  • 你有什么链接可以让我浏览一下吗?我已经尝试了一些东西,但似乎没有任何效果。
  • devarticles.com/c/a/PHP/Use-PHP-to-Create-Dynamic-pdf-Files 第一篇文章我来谷歌搜索使用 php 创建 pdf...如果您在尝试创建 PDF 时遇到错误,请在 SO 上寻求有关细节的帮助
  • @Syed Abdul Rahman:要在 PHP 中创建 PDF,如果您能够执行程序,我推荐wkhtmltopdf,否则dompdf
猜你喜欢
  • 2019-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-12
  • 1970-01-01
  • 2021-10-15
  • 1970-01-01
  • 2013-04-12
相关资源
最近更新 更多