Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » Print labels in PDF
Print labels in PDF [message #1744] Mon, 20 October 2008 12:37 Go to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
I need to print a personal card for each person in a table.

Each A4 paper has 10 'boxes' divided into two columns of five elements. Each box will contain one persons data such as name, surname etc.
Is it possible to print a pdf with this format in radicore?
Re: Print labels in PDF [message #1745 is a reply to message #1744] Mon, 20 October 2008 13:13 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
Yes. You need to look at http://www.tonymarston.net/php-mysql/output-to-pdf.html#exam ple.invoice which also has sample code in the XAMPLE application (included in the Radicore download).

Re: Print labels in PDF [message #1746 is a reply to message #1744] Mon, 20 October 2008 13:18 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
Thanks Tony, I allready saw that but couldn't find the answer,is it really possible to print two different records in one line?
I mean, I have five lines with two labels per line, and I need a different person to be printed in each line.
If this is possible I'll take a look to that example more thoroughly.
Thanks again.
Re: Print labels in PDF [message #1747 is a reply to message #1746] Mon, 20 October 2008 15:08 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
If you take a look at the _cm_output_multi() method in radicore/xample/classes/x_person.class.inc you will see that the output is an array which may contain data from as many different records as you like. It is not restricted to one record per line - you can have multiple records on a single line as well as multiple lines for a single record. It all depends on what you put in the output array.

Re: Print labels in PDF [message #1748 is a reply to message #1744] Tue, 21 October 2008 05:45 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
Tony,
I've been struggling with this for quite a few hours and I want to be sure I'm doing it the correct way:
I have a list1 of persons (that may have been filtered by some criteria).
In this list1 I have a button with an output3 transaction that should print the labels (containing person data) in an A4 sheet, with two labels per line, five lines per sheet (one label is for each person).

My idea is to define one multi1 zone with the following field names:

name1
name2
.
.
name10

address1
address2
.
.
address10

Then in _cm_output_multi fill each with a persons data, and update the $where clause so that this records aren't considered anymore (so they aren't printed again).

Is this correct?

Re: Print labels in PDF [message #1749 is a reply to message #1748] Tue, 21 October 2008 06:04 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
If you want to print 2 labels per line then you need to define a line containing 2 labels, then output an array containing as many lines as necessary.

Take a look at http://www.tonymarston.net/php-mysql/output-to-pdf.html#exam ple.invoice which is produced from radicore/xample/classes/x_person_s04.class.inc. The INVOICE_TO and SHIP_TO boxes show how you can print two address labels on a single line, but to get multiple lines you need to look at the production of the item lines in the _cm_output_multi() method for the 'multi1' condition. There you can construct an array containing as many lines as you need before you return.


Re: Print labels in PDF [message #1750 is a reply to message #1744] Tue, 21 October 2008 08:14 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
Ok, more or less I got it.

Now I have problems printing the persons image in each label.

It seems as if there can only be one image per line.

If I put two images per line I get this error:
Fatal Error: Image file has no extension and no type was specified: fotos/firma (# 256).

Error in line 369 of file '/Applications/MAMP/htdocs/radicore/includes/std.pdf.class.inc'.

Script: /Radicore/ceae/fichas(output3).php

Any ideas on how to solve it?

[Updated on: Tue, 21 October 2008 09:08]

Report message to a moderator

Re: Print labels in PDF [message #1751 is a reply to message #1750] Tue, 21 October 2008 09:24 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
That error message is saying that when it comes to process the image it is looking for an extension such as '.jpg' or '.png' to identify the file type, but cannot find one. What is the value for 'pic1' and 'pic2' in your data array? It should be a string containing the name of the image file.

I have tried running 'person_output(pdf)2.php' in the XAMPLE application which includes an image, and I can successfully resize it by changing the values for 'imagewidth' and 'imageheight' in the $fieldspec array without any problem whatsoever. Can you step through with your debugger to see where it is getting the values that it is using?


Re: Print labels in PDF [message #1752 is a reply to message #1744] Tue, 21 October 2008 09:31 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
After _cm_output_multi:
outarray[0][pic1]=fotos/firma.jpg;
outarray[0][pic2]=fotos/20080921184905_firma.jpg;

somewhere between _cm_output_multi and printCell, the extension is being automatically removed (but only if there are two images per line, with one image it works).

I'll try to figure out where is the extension being removed with the debugger.
Re: Print labels in PDF [message #1753 is a reply to message #1744] Tue, 21 October 2008 10:03 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
Ok, I found it.
It was a problem with the field width, if the name of the picture is too long, it splits it into two lines, therefore it can't be rendered as it doesn't find the truncated picture name.

BTW: I'd like to hide the name of the file and show only the picture, is this possible?
Re: Print labels in PDF [message #1754 is a reply to message #1744] Tue, 21 October 2008 10:48 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
Another update, I modified std.pdf.class.inc so that it doesn't split the filename if it's an image:
if ($celldata['fieldspec']['subtype']!='image'){
            	if ($this->GetStringWidth($line) > $cell_width-2.25 ) {
            		// this line is too long for current cell
            		if ($last_split > 0) {
            			// truncate current line at last split character
            			if ($char == '_') {
            				$split_point = $ix - $last_split +1;
            			} else {
            		    	$split_point = $ix - $last_split;
            			} // if
            			$line = substr($line, 0, strlen($line) - $split_point);
            			if ($char == '_') {
            				$ix = $last_split -1;
            			} else {
            		    	$ix = $last_split;
            			} // f
            		} // if
            		$celldata['line_array'][] = trim($line);
            		$line = '';
            		$last_split = 0;
            	} // if
}


OTOH, I added this code:
$text='';

on line 1048 of the same file to hide the image name.
Re: Print labels in PDF [message #1755 is a reply to message #1753] Tue, 21 October 2008 11:00 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
The file name cannot be omitted with the current release, but I've updated my code to make this possible. Please see the attached file. You have two choices:
(1) Insert
'notext' => 'y'
into the $fieldspec array for the image.
(2) Insert
'notext' => 'y'
into the report struture file for the image.

Please note that the attached file contains ALL pending updates, so please read the notes in radicore/radicore-2008-xx-xx.txt


Re: Print labels in PDF [message #1757 is a reply to message #1754] Tue, 21 October 2008 11:20 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
I have a much better fix for that in the attached file. Basically it uses
$celldata['text']
for the image name instead of
$celldata['line_array'][0]


Re: Print labels in PDF [message #1761 is a reply to message #1744] Tue, 21 October 2008 14:37 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
I almost done, just one last thing:
The user filters the persons to be printed in the list1 transaction, from there a button prints the details of each person, but I've modified _cm_output_multi so that with the first call to _cm_output_multi, all the selected labels are printed in pairs.
Therefore what I'm getting right now is that all the labels are printed as many times as records are selected in list1.

So what I've done is define a variable called 'first_print=true' in the person class, and then:
	function _cm_post_fetchRow ($rowdata){
		if ($this->first_print){
			$this->first_print = false;
			return $rowdata;
		}else{
			return null;
		}
	}


Is this the correct way to achieve it?

[Updated on: Tue, 21 October 2008 14:45]

Report message to a moderator

Re: Print labels in PDF [message #1762 is a reply to message #1761] Tue, 21 October 2008 19:22 Go to previous message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
I don't know as I have nothing to test it against. I cannot tell if it works or not, or if there's a better way. If it works for you then that is all that is necessary.

Previous Topic: Help in New Window
Next Topic: PDF Document Margin Setup
Goto Forum:
  


Current Time: Mon Nov 18 05:27:36 EST 2024

Total time taken to generate the page: 0.01642 seconds