duanpo7796 2018-01-29 08:05
浏览 230

PHP中的Docx到pdf转换自动添加新行 - PHPWord

I am converting docx file to pdf using PHP library PHPOffice and PHPWord. I am using TCPDF as PDF writer.

My code is as below

include_once 'Sample_Header.php';
include_once '../vendor/tecnickcom/tcpdf/tcpdf.php';

\PhpOffice\PhpWord\Settings::setPdfRendererPath('../vendor/tecnickcom/tcpdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');

$temp = \PhpOffice\PhpWord\IOFactory::load('files/sampledocument.docx');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($temp , 'PDF');
$xmlWriter->save('results/sampledocument.pdf', TRUE);

Its working fine and generating correct pdf file only if docx file is containing plain text without any style changes(i.e color, text-bold). But if docx file containing stylings then in pdf its starting from new line.

For example docx file contains

Hello World

This is showing correct in pdf file. But if docx file contains as below ("H" and "W" is bold here)

**H**ello **W**orld

Its showing in pdf as below (Instead of showing in one line its showing in multiple lines)

H
ello
W
orld

Please let me know you any one is having solution for this. Thanks in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?