2017-01-11 15 views
2

我必須從我的WP網站的產品詳細信息頁面創建PDF文檔,並從頁面中提取所有HTML代碼以推斷img和表格標籤。 我安裝了一個插件來從頁面創建一個PDF文檔,但是imagese和表格沒有被插入:只有文本被插入到文檔中。從PHP頁面中提取HTML代碼以推斷一些圖像

該插件是woocommercePrintProduct,我已經編輯了它的代碼以將圖像插入到PDF文檔中。應當修改的功能如下:

div class="descrizione" style="margin:0 30px;"> 
      <div class="colonnaSx" style="float:left;width:350px;margin-right:30px"> 
       <div class="pacchettino"> 
        <?php if(get_field('descrizione_prod')): ?> 
         <h3>DESCRIPTION</h3> 
         <p><?php the_field('descrizione_prod'); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="pacchettino"> 
        <?php if(get_field('forma')): ?> 
         <h3>SHAPE</h3> 
         <p><?php the_field('forma'); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="pacchettino"> 
        <?php if(get_field('posa')): ?> 
         <h3>INSTALLATION</h3> 
         <p><?php the_field('posa'); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="pacchettino"> 
        <?php if(get_field('conduttore')): ?> 
         <h3>CONDUCTOR</h3> 
         <p><?php the_field('conduttore'); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="pacchettino"> 
        <?php if(get_field('isolante')): ?> 
         <h3>INSULATION</h3> 
         <p><?php the_field('isolante'); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="pacchettino"> 
        <?php if(get_field('guaina')): ?> 
         <h3>SHEAT</h3> 
         <p><?php the_field('guaina'); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="pacchettino"> 
        <?php if(get_field('sforzo_massimo_di_tiro')): ?> 
         <h3>MAX MECHANICAL STRESS</h3> 
         <p><?php the_field('sforzo_massimo_di_tiro'); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="pacchettino"> 
        <?php if(get_field('guainetta')): ?> 
         <h3>INTERNAL SHEATH</h3> 
         <p><?php the_field('guainetta'); ?></p> 
        <?php endif; ?> 
       </div> 
      </div> 

      <div class="colonnaDx" style="float:right;width:350px;"> 
       <div class="pacchettino"> 
        <?php if(get_field('marchiatura')): ?> 
         <h3>MARCHIATURA</h3> 
         <p><?php the_field('marchiatura'); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="pacchettino"> 
        <?php if(get_field('colore')): ?> 
         <h3>COLORE</h3> 
         <p><?php the_field('colore'); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="pacchettino"> 
        <?php if(get_field('tensione_di_esercizio')): ?> 
         <h3>TENSIONE DI ESERCIZIO</h3> 
         <p><?php the_field('tensione_di_esercizio'); ?></p> 
        <?php endif; ?> 
       </div> 

     <?php /* 
     <table class="description"> 
      <?php 
      $description = wpautop($this->data->description); 
      $description = preg_replace("/\[[^\]]+\]/", '', $description); 
      $description = explode('<p>', $description); 
      foreach ($description as $value) { 
      ?> 
       <tr> 
        <td style="padding-bottom: 20px;"> 
         <?php echo $value ?> 
        </td> 
       </tr> 
       <?php 
      } 
      ?> 

     </table> 

     */ 
     ?> 

     <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> 


     <?php 

     return ob_get_clean(); 

    } 

我想提取從細節產品頁面的html代碼,然後推斷img標籤和intert他們到文檔中。

你能幫助我嗎?

+0

插件的名稱是什麼? –

+0

插件是woocommercePrintProduct,我編輯了它的代碼以在PDF文檔中插入圖像 –

回答

0

對此有很多更簡單的解決方案。

我推薦WKHTMLtoPDF,它是開源的,沒有瀏覽器,沒有應用程序,只是命令行,非常簡單。 http://wkhtmltopdf.org/downloads.html

如何使用: 在

wkhtmltopdf {website} {filename to save as} 

例從上面 打開命令提示符 類型的鏈接安裝後:

wkhtmltopdf http://google.com google.pdf 

用戶手冊: http://wkhtmltopdf.org/usage/wkhtmltopdf.txt

有是num其他很多程序甚至在線工具都可以完全按照您的要求進行操作,許多甚至是開源的,就像上面那樣。當你可以免費獲得瓶子時,沒有必要將一個方形的釘子裝入圓孔中。

相關問題