-1

I have a HTML code like this:

<div id="invoice"> 
  <div id="invoice-header"> <img alt="Mainlogo_large" class="logo screen" src="http://colosus.com/invoice/images/freeagent_logo.png"> 
    <!-- hCard microformat --> 
    <div class="vcard" id="company-address"> 
      <div class="fn org"><strong>KIOSBAN.COM</strong></div> 
      <div class="adr"> 
        <div class="street-address">Gedung Atlantica Lt.4<br>
          Jl. Kuningan Barat No. 7, Mampang<br> 
        </div> 
        <!-- street-address --> 
        <div class="locality">Indonesia</div> 
        <div id="company-postcode"><span class="region">Jakarta Selatan</span> <span class="postal-code">12710</span></div> 
      </div> 
      <!-- adr --> 
      <div class="email">fajar@kiosban.com</div> 
    <div id="sales-tax-reg-number">Fajar tampan</div> 
    </div> 
    <!-- company-address vcard --> 
  </div> 
  <!-- #invoice-header --> 
  <div id="invoice-info"> 
    <h2>Invoice <strong>INV001</strong></h2> 
    <h3>21 February 2008</h3> 
    <p id="payment-terms">Payment Terms: 30 days</p> 
    <p id="payment-due">Payment due by 21 March 2008</p> 
    <p id="payment-total">£2643.75</p>
  </div> 
  <!-- #invoice-info --> 
  <div class="vcard" id="client-details"> 
    <div class="fn">John Doe</div> 
    <div class="org">Client Company</div> 
    <div class="adr"> 
      <div class="street-address"> Client Street Address<br> 
        Street Address 2<br> 
        Street Address 3<br> 
      </div> 
      <!-- street-address --> 
      <div class="locality">LOCALITY</div> 
      <div id="client-postcode"><span class="region">Region</span> <span class="postal-code">MV2 8SX</span></div> 
      <div id="your-tax-number">SALES TAX: 193528491</div>
    </div> 
    <!-- adr --> 
  </div> 
  <!-- #client-details vcard --> 
  <table id="invoice-amount"> 
    <thead> 
      <tr id="header_row"> 
        <th class="quantity_th">Quantity</th> 
        <th class="left details_th">Details</th> 
        <th class="unitprice_th">Unit Price (£)</th> 
        <th class="salestax_th">VAT</th> 
        <th class="subtotal_th">Net Subtotal (£)</th> 
      </tr> 
    </thead> 
    <tfoot> 
      <tr id="discount_tr"> 
        <td colspan="2">&nbsp;</td> 
        <td colspan="2" class="item_r">10% Discount</td> 
        <td class="item_r">£250.00</td> 
      </tr> 
      <tr id="net_total_tr"> 
        <td colspan="2">&nbsp;</td> 
        <td colspan="2" class="item_r">Net Total</td> 
        <td class="item_r">2250.00</td> 
      </tr> 
      <tr id="vat_tr"> 
        <td colspan="2">&nbsp;</td> 
        <td colspan="2" class="item_r">VAT</td> 
        <td class="item_r">393.75</td> 
      </tr> 
      <tr id="total_tr"> 
        <td colspan="2">&nbsp;</td> 
        <td colspan="2" class="total" id="total_currency"><span class="currency">GBP </span> Total</td> 
        <td class="total">£2643.75</td> 
      </tr> 
    </tfoot> 
    <tbody> 
      <tr class="item odd"> 
        <td class="item_l">1 Day</td> 
        <td class="item_l">Details of project activity to be billed </td> 
        <td class="item_r">500.00</td> 
        <td class="item_r">17.5%</td> 
        <td class="item_r">500.00</td> 
      </tr> 
      <tr class="item"> 
        <td class="item_l">2 Days</td> 
        <td class="item_l">Other Details of project activity to be billed </td> 
        <td class="item_r">1000.00</td> 
        <td class="item_r">17.5%</td> 
        <td class="item_r">1000.00</td> 
      </tr> 
      <tr class="item odd"> 
        <td class="item_l">2 Days</td> 
        <td class="item_l">More d etails of project activity to be billed </td> 
        <td class="item_r">1500.00</td> 
        <td class="item_r">17.5%</td> 
        <td class="item_r">1000.00</td> 
      </tr> 
    </tbody> 
  </table> 
  <!-- invoice-amount --> 
  <div id="invoice-other"> 
    <h2>Other Information</h2> 
    <div id="company-reg-number"><strong>Company Registration Number:</strong> 9273109</div>  
    <div id="contract-number"><strong>Contract/PO:</strong> PO 87227643</div> 
  </div> 
  <!-- invoice-other --> 
  <div id="payment-details"> 
    <h2>Payment Details</h2> 
    <div id="bank_name">Bank Name</div> 
    <div id="sort-code"><strong>Bank/Sort Code:</strong> 32-75-97</div> 
    <div id="account-number"><strong>Account Number:</strong> 28270761</div> 
    <div id="iban"><strong>IBAN:</strong> 973547</div> 
    <div id="bic"><strong>BIC:</strong> 220197</div> 
    <div id="payment-reference"><strong>Payment Reference:</strong> INV001</div> 
  </div> 
  <!-- payment-details --> 
  <div id="comments">Payment should be made by bank transfer or cheque made payable to John Smith.</div> 
  <!-- comments --> 
</div>

My question is: how to convert that HTML code only element inside <div id='invoice'>bla bla bla</div> or maybe just the specified url of that page (ex: localhost/invoice/index.php) to a downloadable pdf?

I've been searching many pdf class libraries but I can't find a solution.

Can anyone give me a solution, idea or possible approach?

Charles
  • 50,943
  • 13
  • 104
  • 142
Wawan Brutalx
  • 603
  • 6
  • 15
  • 27
  • possible duplicate of [Convert HTML + CSS to PDF with PHP?](http://stackoverflow.com/questions/391005/convert-html-css-to-pdf-with-php) – Charles Dec 11 '12 at 08:51
  • Most of the HTML to PDF converters can't target a specific document fragment. Options: 1) use a print-specific stylesheet to hide the other DIVs; 2) write some code to parse the document and pull out the desired DIV; 3) use JS to grab the desired DIV and send it to the PDF rendering script. – BrianS Jan 11 '13 at 03:07

5 Answers5

1

You can use this service http://pdfmyurl.com/ to have PDF downloaded for urls, like having them in this format - http://pdfmyurl.com/?url=http://facebook.com

Ashfame
  • 1,731
  • 1
  • 25
  • 42
1

I would recommend using Zend_Pdf, it can be given a page which is used as the template for the PDF and you can do all sorts of PDF stuff.

CE_REAL
  • 384
  • 5
  • 13
0

Try TCPDF http://www.tcpdf.org/ . It is a php class for generating pdfs. Read http://www.tcpdf.org/examples/example_006.phps

user7282
  • 5,106
  • 9
  • 41
  • 72
0

Try mPDF it is a great and easy to use tool. And you can take a look on this quick start tutorial smaizys.com

Amr
  • 4,809
  • 6
  • 46
  • 60
0

I suggest to used DOMPDF.

[https://github.com/dompdf/dompdf][1]

it had huge problems with tables. I factored out my large nested tables and it helped (before it was just consuming up to 128M of memory then dying--thats my limit on memory in php.ini) but it makes a complete mess of tables and doesn't seem to get images. The tables were just basic stuff with some border styles to add some lines at various points;

Fel
  • 354
  • 2
  • 12