-1

I have a textarea on my site that users can insert and edit text and thus has formatting and spacing. I would like for the user to push a button and generate a pdf of this textarea with the same format. I have tried allot to resolve this . Are there any good ways to do this in PHP? .

here is my code.

<script type="text/javascript" src="ckeditor/ckeditor.js"></script>

<form action="new_pdf_test.php" method="post" name="frm1">

<textarea cols="80" id="editor1" name="editor1" rows="10" ></textarea>

<script type="text/javascript">

CKEDITOR.replace( 'editor1' );

</script>

<input type="submit" name="pdf_btn" id="pdf_btn" value="Generate PDF" />

</form>

when user click on "Generate PDF" button page redirect other page to generate PDF. next page code is following.

<?php
require('fpdf.php');

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$pdf->Cell(40,10,$_POST['editor1']);
$pdf->Output();
?>

It creating PDF but not in right way and format. Plz suggest any good way to do this.

Alex Chamberlain
  • 4,147
  • 2
  • 22
  • 49
harish
  • 1
  • 1
  • 1

2 Answers2

0

I guess the FPDF add-on HTML conversion will help here:

This class allows to convert HTML to PDF. It was designed to export my blog entries to PDFs.

It has a lot of features. The important ones for your situation should be:

  • support for bold, italics, underlined text
  • support for headlines <h1>, <h2>, <h3> and <h4>
  • support for images
  • basic support for tables
  • full support for lists <li>
  • full support for <blockquote>
  • support for <br>, <br /> and <p>
  • support for <hr> and <hr />
insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
0

Just adding to the previous answer. I agree FPDF is a great tool. However, the FPDF website can be a bit difficult to learn off - I know I had a few problems when first trying to use it!!

I have recently created a blog just to help people get their heads around the basics of FPDF as it's a bit of a different way to thinking than your usual PHP coding! If you are interested in reading it you can find it at http://www.limelightonline.co.nz/blog/create-dynamic-pdf-with-php-tutorial/

I'd be happy to help out if you have any questions or get stuck at all :D

Cheers, Shay