1

I'm familiar with creating wordpress plugins. I tried hard to make fpdf plugin to create pdf file from php contents, but IT didn't work

I now that : require_once("fpdf.php"); should comes at the top of my file, and I think that is my main problem

below is how to create a simple pdf file from php script using fpdf:

require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();

What I should do to make it work?

usama sulaiman
  • 2,013
  • 4
  • 24
  • 37

2 Answers2

1

If you are sure the problem in require('fpdf.php'); then use full file path as follows

define( 'MYPLUGINNAME_PATH', plugin_dir_path( __FILE__ ) );
require MYPLUGINNAME_PATH . 'fpdf.php';
Datta Parad
  • 709
  • 3
  • 11
0

The question is, how do you convert your html to pdf output? To get your PDF to look like your webpage, that is, with all the html+css, I don't believe this library will do it.

If you just want to get the post_content from a post, and put it into a pdf, you could do this:

To create a plugin:

You'll need to add a folder to /wp-content/plugins/ and create your plugin file in that folder:

/wp-content/plugins/fpdf/fpdf.php

/*
Plugin Name: fpdf
Description: Post to PDF
*/

// Here's where you'll write your code.
$post = get_post( $post_id );

require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,$post->post_content);
$pdf->Output();

This would output a pdf on every page load, after you activate the plugin, which is not likely what you're looking for...

Michael Lewis
  • 4,252
  • 6
  • 28
  • 39
  • Thanks @Mike I tried but it didn't work for me, I post another post [here](http://stackoverflow.com/q/17956251/909456) for my fill question – usama sulaiman Jul 30 '13 at 20:18