Jump to content

Recommended Posts

Hi,
I have a piece of code, which display a statement through the header function. How to "change" the code to open this data in pdf file?
 
 
 
  1. $query = "SELECT licznik, suma, technika FROM dane"
  2.  
  3. $result = $this->bean->db->query($query, true);
  4. $row = $this->bean->db->fetchByAssoc($result);
  5. if($row[licznik]==0) $row[licznik]=0;
  6. if($row[suma]==0) $row[suma]=0;
  7. if($row[technika]==0) $row[technika]=0;
  8.  
  9. $blad = "Licznik : ".str_pad($row[licznik],3,' ',STR_PAD_LEFT).
  10. '\n'.' Suma : '.str_pad($row[suma],5,' ',STR_PAD_LEFT).',00'.
  11. '\n'.' technika : '.str_pad($row[technika],5,' ',STR_PAD_LEFT).',00';
  12.  
  13.  
  14. Header('Location: index.php='.$this->bean->id."&error=".$blad);

 

Link to comment
https://forums.phpfreaks.com/topic/292104-changing-statement-into-pdf-file/
Share on other sites

<?php

 

require_once('/home/agentCRM_PDF/tcpdf/tcpdf.php');

 

 

$rekord = $_REQUEST['record']; 

$GLOBALS['log']->fatal(" Cart = ".$rekord."  user = ".$user->id);

 

  1. $query = "SELECT licznik, suma, technika FROM dane"
  2.  
  3. $result = $this->bean->db->query($query, true);
  4. $row = $this->bean->db->fetchByAssoc($result);
  5. if($row[licznik]==0) $row[licznik]=0;
  6. if($row[suma]==0) $row[suma]=0;
  7. if($row[technika]==0) $row[technika]=0;
  8.  
  9. $blad = "Licznik : ".str_pad($row[licznik],3,' ',STR_PAD_LEFT).
  10. '\n'.' Suma : '.str_pad($row[suma],5,' ',STR_PAD_LEFT).',00'.
  11. '\n'.' technika : '.str_pad($row[technika],5,' ',STR_PAD_LEFT).',00';
  12.  
  13.  
  14. Header('Location: index.php='.$this->bean->id."&error=".$blad);
 
?>
 
This is the whole code. It  works for me.
 
It displays in pop-up window
 
 
               Licznik: 0
               Suma: 0
               Technika: 0
 
I don't get errors but I don't know hot to make it pdf....

I have a lot of experience with generating PDFs ia a web interface, but this was with the use of custom PostScript files and a backend processor. This would be well outside what you are looking to do.

 

You'll need to run the output through an additional process to make it a PDF. There is built-in PDF handling in PHP (http://php.net/manual/en/book.pdf.php), but I don't think it is the easiest to work with. Fo rexample, you can't just send the output for PDF, you basically have to tell the code where to put each piece of information. For example, for the first line you would provide code to set the position on the page, set the font to use, the color of the font, and then pass the text to output. Then you would set the position for the 2nd line and send the text for that line. Unless you are going to build your own PDF framework, I don't think it is worth your time.

 

However, there are plenty of other frameworks/classes that are available which would be easier. I don't have on to suggest though. Alternatively, there are also applications out there that allow you to prepare a "page" using HTML and then pass that output to an application that will generate it into a PDF. Most of these (at least the ones that do a good job) cost money.

 

Here are a couple resources you can take a look at to see if any meet your needs:

http://www.tcpdf.org/

http://www.fpdf.org/

http://mpdf.bpm1.com/

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.