1

Wordpress の投稿内のコンテンツから動的に PDF を作成したいと思います (以下では少し簡略化されています)。 「レシピ」と呼ばれるものは、 DOMPDFdivに送信したいものです(投稿全体ではありません)。

<div class="post">
    <div>
        <!-- some stuff I don't want in the PDF -->
    </div>
    <div class="recipe">
        <?php more_fields('recipe-name'); ?>
        <?php more_fields('recipe-method'); ?>
        <a href="<?php /*something here that calls DOMPDF, 
                         delivers the contents of #recipe, and causes
                         render and stream of PDF to browser.*/ ?>"
    class="print-recipe">Get a PDF of this recipe.</a>
    </div>
</div>

これまでPHPライブラリを使用したことがなく、これを行う方法が欠けているようです。ドキュメンテーションはこちら。喜んで手伝ってくれる人に前もって感謝します。

4

3 に答える 3

3

対応するレシピ ID が与えられたときに PDF を生成する別のスクリプトを作成し、現在の HTML ページからそれにリンクする必要があります。1 つのページですべてを実行しようとしているため、苦労しているようです。

私はWordpressに特に精通していないので、バッファを使用してHTMLを出力することをお勧めします: (未テスト)

レシピ_pdf.php

<?
  /* wordpress initializers go here */
  require_once("dompdf_config.inc.php"); // or whatever your path is

  $id = $_GET['id']; //requested recipe ID
  /* fetch recipe data here */

  ob_start(); // begin buffering PDF content
?>


**output recipe HTML to be used for PDF generation here**


<?

  $html = ob_get_clean();  // grab buffered content and stop buffering

  //create and output the PDF as a stream (download dialog)
  $dompdf = new DOMPDF();
  $dompdf->load_html($html);
  $dompdf->render();
  $filename = "your-recipe-filename.pdf";
  $dompdf->stream($filename);

?>

レシピ HTML ファイル

...
<div class="recipe">
  <?php more_fields('recipe-name'); ?>
  <?php more_fields('recipe-method'); ?>
  <a href="recipe_pdf.php?id=<? // output recipe ID ?>">
    Get a PDF of this recipe.
  </a>
</div>
...
于 2011-01-25T08:25:43.317 に答える
0

jQuery を使用している場合は、次のようにレシピ html を選択できます。

$('.recipe').html();

dompdfライブラリページへのアクチンリンクを含むフォームを作成するだけです

于 2011-01-25T08:01:52.200 に答える
0

見ている Web サイトでリンクをクリックすると、問題の HTML ファイルへのパスを入力として dompdf.php スクリプトが呼び出されます。リンク先は「プレビュー」というiframeです。あなたが考えているのであれば、ページ自体の中で実際に変換を行っているわけではありません。

于 2011-01-24T14:53:53.727 に答える