将pdf转换为php中的html [英] pdf to html conversion in php

查看:138
本文介绍了将pdf转换为php中的html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的PHP脚本中,我想将pdf文件转换为html格式,并且在执行此操作时,不应干扰所生成的html文件内容....

in my php script i want to convert a pdf file to html format and while doing this the generated html file contents should not to be disturbed ....

我找到了 http://sourceforge.net/projects/pdftohtml/,但这是命令线工具,需要外壳访问权限.第二件事是生成的html文件内容受到干扰..

i found http://sourceforge.net/projects/pdftohtml/ but it is command line tool and need shell access. Second thing is generated html file content get disturbed..

推荐答案

可以从php执行shell命令吗?

Can the shell command be executed from php?

$rtn = exec ('CLI Command to execute', $emptyVartoCaptureOutput);

命令在外壳中执行,在运行php脚本的用户的上下文中运行(对于从apache Web服务器运行的脚本,_WWW或类似的脚本).提供第二个可选参数时,命令的所有输出都将捕获到数组中.

The command is executed in the shell, run under the context of the user running the php script (_WWW or similar for scripts run from apache webserver). All the output from the command is captured into an array when you supply the second optional argument.

似乎可以解决您的问题.

Seems like this might solve your problem.

针对您的评论:

您在原始帖子中引用的工具是您将要执行的命令行工具-您需要弄清楚要执行的确切命令,包括该命令的所有参数.

The tool you reference in your original post is the command line tool you would execute - you need to figure out the exact command to execute including any and all arguments for that command.

我不熟悉您引用的工具,但我怀疑它有多种选择.要查看的几个重要选项是生成的html的去向.我猜想它可以进入文件(这将要求_WWW拥有对目录的写权限,这具有巨大的安全风险)或输出到标准文件.当您使用php中的exec命令时,发送给std out的所有输出都将保存为一个数组,即每行的新元素,当您将exec函数传递给第二个可选参数时.因此,您应该能够从脚本中动态捕获和处理和/或显示输出的html.

I am not familiar with the tool you reference, but I suspect that it has various options. A couple of important options to look at are where the generated html goes. I would guess it can go either to a file (that would require _WWW to have write permissions to a directory which is a huge security risk) or to std out. When you use the exec command from php, any output sent to std out is saved as an array, a new element for each new line, when you pass the exec function an optional second parameter. Thus you should be able to capture and manipulate and / or display the outputted html dynamically from your script.

对于仅显示pdf格式的html的简单html页面,您可以执行以下操作:

For a simple html page that only displays the html from a pdf, you might do something like this:

<std header stuff omitted for brevity>
<?php
$rtn = exec('CLI Command to Execute -a option1 -b option2', $ouputted_html);
foreach ($ouputted_html as $val){
    echo $val . "\n";
}
?>
</body>
</html>

您可以使用echo implode("\ n",$ outputted_html);代替foreach循环来完成相同的任务,但是如果您选择利用它,则foreach循环可让您对每行进行一些控制.

You could use echo implode("\n", $outputted_html); in place of the foreach loop to accomplish the same, but the foreach loop allows you some control over each line if you choose to take advantage of it.

请注意,生成的html可能包含也可能不包含标头信息,您必须进行实验才能看到.显然,您可以添加标准html页面需要的内容,也可以减去(如果已经提供的话).

Note that the generated html may or may not contain header info, you will have to experiment and see. Obviously you can add what a standard html page needs or subtract if already provided.

因此,您现在就有了将pdf文件显示为html的基础,如果您需要有关该工具复杂性的特定帮助,建议您寻找专门针对该工具的论坛或列表服务,或者向开发人员寻求帮助( s)阅读文档和常见问题解答之后.

So you now have the basis for displaying the pdf files as html, if you need specific help with the intricacies of the tool, I suggest you seek out a forum or listserv dedicated to that tool or perhaps request help from the developer(s) after reading the docs and FAQs.

这篇关于将pdf转换为php中的html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆