Melissafleet Posted April 26, 2013 Share Posted April 26, 2013 (edited) I have installed the FPDF library, and inserted this in the page: <?php require(TEMPLATEPATH . '/fpdf.php'); $pdf = new FPDF('P','mm','A4'); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(0,10,'PHP - The Good Parts!'); $pdf->Output(); ?> It starts creating the pdf, but then an error pops up saying "file does not begin with '%PDF' ?What could be causing this error? Edited April 26, 2013 by Melissafleet Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/ Share on other sites More sharing options...
Barand Posted April 26, 2013 Share Posted April 26, 2013 Perhaps something is being output, maybe whitespace, before the %PDF Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426710 Share on other sites More sharing options...
Melissafleet Posted April 26, 2013 Author Share Posted April 26, 2013 Thank you. I have removed the spaces (line spaces) in between but am still receiving the error? <?php require(TEMPLATEPATH . '/fpdf.php'); $pdf = new FPDF('P','mm','A4'); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(0,10,'PHP - The Good Parts!'); $pdf->Output(); ?> Thank you Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426713 Share on other sites More sharing options...
Barand Posted April 26, 2013 Share Posted April 26, 2013 With addition of 1 line if worked fine for me <?php define('TEMPLATEPATH','c:/php/fpdf'); // <--- added this require(TEMPLATEPATH . '/fpdf.php'); $pdf = new FPDF('P','mm','A4'); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(0,10,'PHP - The Good Parts!'); $pdf->Output(); ?> How do you define TEMPLATEPATH? Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426714 Share on other sites More sharing options...
Melissafleet Posted April 26, 2013 Author Share Posted April 26, 2013 I am using Wordpress, so I thought that it would find the location of FPDF automatically using TEMPLATEPATH... I assume that is incorrect? Should I replace your path (c:/php).. etc with the direct path to that file in my cPanel? Thank you so much for your help Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426717 Share on other sites More sharing options...
Barand Posted April 26, 2013 Share Posted April 26, 2013 Is that pdf code in a file of its own? Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426719 Share on other sites More sharing options...
Melissafleet Posted April 26, 2013 Author Share Posted April 26, 2013 It's in a Wordpress page on its own. I have installed a plugin that allows me to insert php directly in the page code editor (exec-php) http://bluesome.net/post/2005/08/18/50/ Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426726 Share on other sites More sharing options...
Jessica Posted April 26, 2013 Share Posted April 26, 2013 What is the content of that file? It can't have anything output that is NOT pdf. Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426727 Share on other sites More sharing options...
Melissafleet Posted April 27, 2013 Author Share Posted April 27, 2013 The content is supposed to output the text "The Good Parts". I have tried it again, and not it displays a message that says "Failed to load PDF document" ? Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426844 Share on other sites More sharing options...
Jessica Posted April 27, 2013 Share Posted April 27, 2013 yeah, text is not PDF output. Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426846 Share on other sites More sharing options...
Barand Posted April 27, 2013 Share Posted April 27, 2013 The code I posted in reply 4 was in a file on its own. You haven't said if yours is. It worked fine - see attached Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426847 Share on other sites More sharing options...
Melissafleet Posted April 27, 2013 Author Share Posted April 27, 2013 (edited) With addition of 1 line if worked fine for me <?php define('TEMPLATEPATH','c:/php/fpdf'); // <--- added this require(TEMPLATEPATH . '/fpdf.php'); $pdf = new FPDF('P','mm','A4'); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(0,10,'PHP - The Good Parts!'); $pdf->Output(); ?> How do you define TEMPLATEPATH? The code I posted in reply 4 was in a file on its own. You haven't said if yours is. It worked fine - see attached Hi Barand. Yes it is in a file of it's own. I edited the path a bit, as I noticed that my folder was named differently to yours, and now it looks as if it is starting to create the document, but then It says " Failed to load PDF" document? Thank you for your reply <?php define('TEMPLATEPATH','c:/fpdf17'); // <--- added this require(TEMPLATEPATH . '/fpdf.php'); $pdf = new FPDF('P','mm','A4'); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(0,10,'PHP - The Good Parts!'); $pdf->Output(); ?> Edited April 27, 2013 by Melissafleet Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426875 Share on other sites More sharing options...
Barand Posted April 27, 2013 Share Posted April 27, 2013 Can your browser open other PDF files? Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1426877 Share on other sites More sharing options...
Abigail111 Posted August 20, 2013 Share Posted August 20, 2013 The following method shows how to create PDF document .You can try again: public static void SaveDocumentFile(REDocument document, string filePath);public static void SaveDocumentFile(BaseImage image, string filePath, BaseEncoder enc);public static void SaveDocumentFile(List<BaseImage> images, string filePath, BaseEncoder enc);public static void SaveDocumentFile(REDocument document, string filePath, BaseEncoder enc); Quote Link to comment https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/#findComment-1445940 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.