當前位置:首頁 » 編程語言 » 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服務

熱點內容
阿里雲伺服器能用vmware嗎 發布:2024-04-25 13:33:23 瀏覽:731
1616源碼 發布:2024-04-25 13:33:19 瀏覽:80
奧維地圖伺服器地址怎麼填 發布:2024-04-25 12:40:04 瀏覽:965
低配置游戲玩哪個平台 發布:2024-04-25 12:35:04 瀏覽:559
glinux下載 發布:2024-04-25 12:30:09 瀏覽:84
安卓手機可以用的谷歌叫什麼 發布:2024-04-25 12:05:57 瀏覽:943
linux改變用戶所屬組 發布:2024-04-25 11:50:33 瀏覽:469
rsa加密演算法java代碼 發布:2024-04-25 11:40:07 瀏覽:883
如何改變拉桿箱上的初始密碼 發布:2024-04-25 11:17:23 瀏覽:799
內網掛代理虛擬機如何配置網卡 發布:2024-04-25 11:15:06 瀏覽:687