baghel23 Posted April 27, 2022 Share Posted April 27, 2022 I am using the fpdf library for my project, and I'm using this to extend one of the drupal module. These lines $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World!'); $pdf->Output(); give me an error: FPDF error: Some data has already been output, can't send PDF I tried creating this in a separate file outside the drupal area name test.php and when viewed it worked. Anyone here know why this don't work? Or anyone here can point me a right pdf library which I can use in drupal to view HTML to PDF format. Quote Link to comment https://forums.phpfreaks.com/topic/314733-fpdf-problem/ Share on other sites More sharing options...
Barand Posted April 27, 2022 Share Posted April 27, 2022 Always put FPDF code in a script by itself. Link to that script to get the pdf file <a href='create_pdf.php'>Create PDF</a> The TCPDF library has a "WriteHTML()" function. Don't expect much by way of documentation for this library. Apart from the source code, I haven't found any yet. Quote Link to comment https://forums.phpfreaks.com/topic/314733-fpdf-problem/#findComment-1595743 Share on other sites More sharing options...
ginerjm Posted April 27, 2022 Share Posted April 27, 2022 Your script is poorly constructed. You are sending something to the client prior to the pdf content. No can do. Probably a blank line outside of php mode. One trick? Never Leave PHP mode in your scripts PS - what line does the error message give you? That IS the problem. Quote Link to comment https://forums.phpfreaks.com/topic/314733-fpdf-problem/#findComment-1595748 Share on other sites More sharing options...
ginerjm Posted April 27, 2022 Share Posted April 27, 2022 (edited) Where did you download the zip file from? Perhaps this can help you. http://www.fpdf.org/ And I noticed that you are using a less-than-common character set. Probably from looking at out-dated code examples. Switch to UTF-8. Edited April 27, 2022 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/314733-fpdf-problem/#findComment-1595753 Share on other sites More sharing options...
ginerjm Posted April 27, 2022 Share Posted April 27, 2022 Although now I have seen something in the FPDF docs that UTF-8 is not recommended. Hmmmm.... Quote Link to comment https://forums.phpfreaks.com/topic/314733-fpdf-problem/#findComment-1595754 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.