Convert Word doc, docx and Excel xls, xlsx to PDF with PHP
使用正确的附件格式,如.doc、.pdf而非.jpg #生活技巧# #沟通技巧# #邮件礼仪#
Well my 2 cents when it comes to the topic word 2007 docx, word 97-2004 doc, pdf and all other types of MS Office wishing to be "converted from y to z but in real they don't wanna be". In my experience so far, conversion with LibreOffice or OpenOffice can't be relied on. Though .doc documents tend to be better supported than word 2007's .docx. In general it's very hard to convert the .docx to .doc without breaking anything.
.docx also tend to be extremely useful for templating where .doc is not for being binary.
The conversion from .doc to PDF was most of the time quite reliable. If you can still influence the design or content of the word document then this might be satisfying, but in my situation documents were supplied from foreign companies where even after generating the .docx templates, in some scenario's, the generated .docx had to be slightly modified with supplement text before it was generated to a PDF.
WINDOWS BASED!
All this hiccup made me come to the conclusion that the only true reliable conversion method I found was using the COM class in PHP and let the MS Word or Excel Application do all the work for you. I'll just give an example on converting .docx to .doc and/or PDF. If you do not have MS Office installed, you can download a trial version of 60 days which would give you enough room for testing purposes.
the COM.net extension is by default commented out in the php.ini, just search for the line php_com_dotnet.dll and uncomment it like so
extension=php_com_dotnet.dll
Restart the web server (IIS is not a pre, Apache will work just as well).
The code below is a demonstration on how easy it is.
$word = new COM("Word.Application") or die ("Could not initialise Object."); // set it to 1 to see the MS Word window (the actual opening of the document) $word->Visible = 0; // recommend to set to 0, disables alerts like "Do you want MS Word to be the default .. etc" $word->DisplayAlerts = 0; // open the word 2007-2013 document $word->Documents->Open('yourdocument.docx'); // save it as word 2003 $word->ActiveDocument->SaveAs('newdocument.doc'); // convert word 2007-2013 to PDF $word->ActiveDocument->ExportAsFixedFormat('yourdocument.pdf', 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false); // quit the Word process $word->Quit(false); // clean up unset($word);
This is just a small demonstration. I can just say that if it comes to conversion, this was the only real reliable option I could use and even recommend.
网址:Convert Word doc, docx and Excel xls, xlsx to PDF with PHP https://klqsh.com/news/view/344708
相关内容
PDF转Word转换器PDF转换器 – 在线免费转换PDF文件
Use AI Actions in File Explorer in Windows 11
Centimeters to feet and inches converter, Convert between cm and ft
好书推荐卡模板word和excel版免费下载(共6款精选模板)
Find your files in Windows
Convert United States Dollars (USD) and Euros (EUR): Currency Exchange Rate Conversion Calculator
Convert m to cm
Convert cm to feet and inches
Switching to Microsoft 365 Personal and Family Classic Plans
随便看看
- [题目]某兴趣小组的同学设计了一个“电流表 .如图所示.质量为m=0.01kg的匀质细金属棒MN的中点处通过一绝缘挂钩与一竖直悬挂的劲度系数k = 2.0 N/m的弹簧相连.在矩形区域abcd内有垂直纸面向外.大小B = 0.20 T的匀强磁场.与MN的右端N连接的一绝缘轻指针可指示标尺上的读数.MN的长度大于ab.当MN中没有电流通过且处于平衡状态时.MN与 题目和参考答案——青夏教育精英家教网——
- 基层工会成立的文体活动兴趣小组、文体协会等日常活动支出如何控制?丨每日一学(209)
- “呵护童艺,享受童趣”困境儿童成长小组
- 学校4个教职工协会入选“浙江省直属基层工会教职工文体活动优秀兴趣小组”
- 小学科学兴趣小组的活动总结范文(精选11篇)