简体   繁体   English

从html页面创建pdf

[英]Create a pdf from a html page

I've to edited a WP plugin to create a PDF document from a html page. 我要编辑一个WP插件,从html页面创建一个PDF文档。 I've to add a way to insert the images into pdf document. 我要添加一种方法将图像插入到pdf文档中。 A part of the plugin code is like this: 插件代码的一部分是这样的:

<div class="description"  style="margin:0 30px;">
            <?php
            $description = wpautop($this->data->description);
            $description = preg_replace("/\[[^\]]+\]/", '', $description);
            $description = explode('<p>', $description);
            foreach ($description as $value) {
                ?>

                <div class="pacchettino" style="padding-bottom: 20px;margin:0 30px;">
                    <?php 
                        echo $value 
                    ?>
                </div> 

            <?php
            }
            ?>

        </div>

In this way, only the text part is printed into the pdf document. 这样,只有文本部分被打印到pdf文档中。 I want to add the images also and I would to use the preg_match_all PHP function to extract the src attribute of every img tags in the following way: 我想添加图像,我将使用preg_match_all PHP函数以下列方式提取每个img标记的src属性:

<div class="description"  style="margin:0 30px;">
                <?php
                $description = wpautop($this->data->description);
                $match = preg_match_all('<img src=\"(*?)\">', $description, $match);

                $description = preg_replace("/\[[^\]]+\]/", '', $description);
                $description = explode('<p>', $description);
                foreach ($description as $value) {
                    ?>

                    <div class="pacchettino" style="padding-bottom: 20px;margin:0 30px;">
                        <?php 
                            echo $value 
                        ?>
                    </div> 

                <?php
                }
                ?>

            </div>

but $match is NULL. 但是$ match是NULL。 How can I take the string of html code to extact the img tag? 如何使用html代码字符串来取代img标签? Can you help me, please? 你能帮我吗?

使用fpdf和PHP,您可以从HTML代码创建.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM