当前位置:首页 » 编程语言 » phpword转pdf

phpword转pdf

发布时间: 2022-09-27 18:47:45

php导出word和pdf文件

1首先下一个phpexcel

2下载完成的是一个压缩文件,解压放到你的项目目录里

3.下面进入代码;

4.
//引入PHPExcel库文件(路径根据自己情况)
include './phpexcel/Classes/PHPExcel.php';
//创建对象
$excel = new PHPExcel();
//Excel表格式,这里简略写了8列
$letter = array('A','B','C','D','E','F','F','G');
//表头数组
$tableheader = array('学号','姓名','性别','年龄','班级');

//填充表头信息
for($i = 0;$i < count($tableheader);$i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
}

5.
//表格数组
$data = array(
array('1','小王','男','20','100'),
array('2','小李','男','20','101'),
array('3','小张','女','20','102'),
array('4','小赵','女','20','103')
);
//填充表格信息
for ($i = 2;$i <= count($data) + 1;$i++) {
$j = 0;
foreach ($data[$i - 2] as $key=>$value) {
$excel->getActiveSheet()->setCellValue("$letter[$j]$i","$value");
$j++;
}
}

6.
//创建Excel输入对象
$write = new PHPExcel_Writer_Excel5($excel);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="testdata.xls"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');

7.打开页面,刷新的时候会弹出对话框,让你选择文件保存路径和文件名称,

8.打开表格后,数据和格式跟代码中的一致,说明PHP导出的Excel是正确的。如果出现错误,检查一下你的表格数组和数据数组吧。

⑵ php 怎么实现 word,excel 转为 pdf 格式

最简单的办法就是安装word和excel的pdf插件。很多时候安装包已经集成有该插件了,你看一下文件另存为那里是否能选择pdf类型,没有的话就下载并安装插件就行了非常简单。当然按照楼上的用虚拟打印机打印另存为pdf也是可以的。

⑶ php生成pdf 下载 同步还是异步

同步
首先需要安装wkhtmltopdf这个软件 需要执行shell_exec函数的php文件和安装的wkhtmltopdf.exe可执行文件在同一目录下,不然php找不到这个执行文件

shell_exec("wkhtmltopdf.exe --page-size A4 --outline 网页地址 pdf文件名");
--page-size 以A4纸的尺寸显示pdf内容
--outline 显示目录(网页中h1,h2来定)
网页地址 需要转成pdf的网页地址
pdf文件名 生成pdf的文件名,可以使用绝对路径

⑷ php word转pdf 有什么方法吗

PHP也可以实现导出Word文档为PDF的功能,不过要借助于第三方的类库,今天我们将为大家介绍PHP依靠com.sun.star.ServiceManager来转换Word为PDF文档的相关技巧。

PHP处理Word转PDF的示例代码:

02set_time_limit(0);
03functionMakePropertyValue($name,$value,$osm){
04$oStruct=$osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
05$oStruct->Name=$name;
06$oStruct->Value=$value;
07return$oStruct;
08}
09functionword2pdf($doc_url,$output_url){
10$osm=newCOM("com.sun.star.ServiceManager")ordie("请确认OpenOffice.org库是否已经安装. ");
11$args=array(MakePropertyValue("Hidden",true,$osm));
12$oDesktop=$osm->createInstance("com.sun.star.frame.Desktop");
13$oWriterDoc=$oDesktop->loadComponentFromURL($doc_url,"_blank",0,$args);
14$export_args=array(MakePropertyValue("FilterName","writer_pdf_Export",$osm));
15$oWriterDoc->storeToURL($output_url,$export_args);
16$oWriterDoc->close(true);
17}
18$output_dir="D:/temp/";
19$doc_file="D:/temps/test.doc";
20$pdf_file="test.pdf";
21$output_file=$output_dir.$pdf_file;
22$doc_file="file:///".$doc_file;
23$output_file="file:///".$output_file;
24word2pdf($doc_file,$output_file);
25?>

⑸ php 怎么实现 word,excel 转为 pdf 格式

你的这个php是图片格式,要转化成文档(Word.Excel.pdf)是转不成的,只能使用识别软件,才能办到,(识别软件正确率比较高的是清华紫光的,只是建议使用,我不是广告公司,我用的识别软件是清华紫光)

⑹ php word 转pdf 有哪些方法

1、 安装免费的openOffice软件,请至openoffice.org下载最新版本。
2、 JDK支持,请自行搜索下载最新版本JDK。

3、安装完openOffice后,在开始--运行中输入Dcomcnfg打开组件服务。在组件服务—计算机—我的电脑—DCOMP配置中,选择

在这两项上分别点击右键属性,打开属性面板如下图:

选择安全选项卡,分别在启动和激活权限和访问权限两项上点自定义,添加Everyone的权限。

选择标识选项卡,选择交互式用户。
4、 安装完openOffice后,请先打开一次确认可以正常运行软件,然后退出后用命令行运行以下命令。
先到安装目录下,例如:C:\Program Files\OpenOffice 4\program\
执行命令:
soffice -headless-accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
成功后即在后台运行了该软件。
5、 如果是php5.4.5以前版本,需要在php.ini里把com.allow_dcom = true打开,即去掉前面的分号。如果是以后版本,需要在php.ini 里增加一行扩展extension=php_com_dotnet.dll,然后检查php的ext目录中是否存在该dll文件,如果没有请自行下载对应版本的dll。然后重启apache或IIS服务器。
6、 代码实现
/**
* office文档转换为PDF类
* @author jinzhonghao <[email protected]> created 2015-04-23
*/

class office2pdf
{
private $osm;

public function __construct()
{
$this->osm = new COM("com.sun.star.ServiceManager")or die ("Please be sure that OpenOffice.org is installed.n");
}

public function MakePropertyValue($name,$value)
{
$oStruct = $this->osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}

public function transform($input_url, $output_url)
{
$args = array($this->MakePropertyValue("Hidden",true));

$oDesktop = $this->osm->createInstance("com.sun.star.frame.Desktop");

$oWriterDoc = $oDesktop->loadComponentFromURL($input_url,"_blank", 0, $args);

$export_args = array($this->MakePropertyValue("FilterName","writer_pdf_Export"));

$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
return $this->getPdfPages($output_url);
}

public function run($input,$output)
{
$input = "file:///" . str_replace("\\","/",$input);
$output = "file:///" . str_replace("\\","/",$output);
return $this->transform($input, $output);
}

/**
* 获取PDF文件页数的函数获取
* 文件应当对当前用户可读(linux下)
* @param [string] $path [文件路径]
* @return int
*/
public function getPdfPages($path)
{
if(!file_exists($path)) return 0;
if(!is_readable($path)) return 0;
// 打开文件
$fp=@fopen($path,"r");
if (!$fp)
{
return 0;
}
else
{
$max=0;
while(!feof($fp))
{
$line = fgets($fp,255);
if (preg_match('/\/Count [0-9]+/', $line, $matches))
{
preg_match('/[0-9]+/',$matches[0], $matches2);
if ($max<$matches2[0]) $max=$matches2[0];
}
}
fclose($fp);
// 返回页数
return $max;
}
}

}

⑺ 我使用php语言做word转pdf的时候报错

解决方法:
在把Word转换成Pdf过程中,首先是选择文件---打印---然后在打印机下拉框中选择“Pdf打印机”,然后选择确定,此时,选择保存位置,然后确定后Pdf打印做准备。
如果使用了系统字体以外的字体时,Pdf虚拟打印机就会报错提示,为你指出哪页哪页未能转换等等的错误信息,这些信息是在txt文本中呈现的。
下边来看看解决的办法,首先找到系统中“设备和打印机”的位置
点击“设备和打印机”进入设备和打印机界面。
在设备和打印机界面找到“Adobe PDF”虚拟打印机,然后点击右键,选择“打印首选项”。
在弹出的“Adobe PDF打印首选项”对话框中,取消“仅依靠系统字体;不使用文档字体”复选框,然后点击应用退出就OK了

⑻ PHP 中怎么实现OFFICE文件转换成PDF文件格式

贴个doc转pdf的
< ?php
set_time_limit(0);
function MakePropertyValue($name,$value,$osm){
$oStruct = $osm->Bridge_GetStruct
("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}
function word2pdf($doc_url, $output_url){
$osm = new COM("com.sun.star.ServiceManager")
or die ("Please be sure that OpenOffice.org
is installed.\n");
$args = array(MakePropertyValue("Hidden",true,$osm));
$oDesktop = $osm->createInstance("com.sun.star
.frame.Desktop");
$oWriterDoc = $oDesktop->loadComponentFromURL
($doc_url,"_blank", 0, $args);
$export_args = array(MakePropertyValue
("FilterName","writer_pdf_Export",$osm));
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
$output_dir = "D:/LightTPD/htdocs/";
$doc_file = "D:/LightTPD/htdocs/2.doc";
$pdf_file = "2.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
word2pdf($doc_file,$output_file);
?>

⑼ PHP怎么实现提取WORD的内容以及把WORD转换成PDF格式

有一家网络公司的业务就是用PHP制作PDF文件的,这个你就应该知道你这个问题不是一两个小程序能完成的。pear里面有个类库,可以利用TXT文件去生成PDF文件,而且有点小复杂,至于这么提取word的内容,不懂,期待高手~

⑽ PHP word转pdf

这个不是说的很清楚了吗
Please be sure that OpenOffice.org is installed

你直接安装上openoffice,启动 openoffice服务

热点内容
linuxshellif 发布:2024-05-04 17:09:47 浏览:16
算法精英挑战赛 发布:2024-05-04 17:09:08 浏览:739
河南电力公众号绑定密码是多少 发布:2024-05-04 17:08:55 浏览:331
手机上怎么打开压缩文件 发布:2024-05-04 17:03:57 浏览:172
word加密文件如何解密 发布:2024-05-04 17:02:57 浏览:289
php源码本地测试 发布:2024-05-04 16:57:17 浏览:801
c语言编译exe 发布:2024-05-04 16:57:16 浏览:974
国密算法获取 发布:2024-05-04 16:38:24 浏览:70
脚本精灵荒野乱斗 发布:2024-05-04 16:28:33 浏览:520
刚到的笔记本怎么看配置 发布:2024-05-04 16:26:58 浏览:4