I need to print on 2 columns label paper.

So I do not found how to show more than one node per line.

Is it possible to print labels like this:

Name / Adress | Name / Adress
------------------------------------------
Name / Adress | Name / Adress
...

CommentFileSizeAuthor
#9 inventarioQR.pdf145.54 KBmbria
#9 inventarioExport.txt18.12 KBmbria

Comments

hunziker’s picture

The support for such things is not that good, but you could do it as follow:

Place the elements on the PDF relative to last writing position and define a width for the elements. When the elements should be printed out of the page, a new line is started.

But this is rudimentary and not really stable solution. To support such printing you should use some custom code, which ensures a correct line break after two records. This can be done in the render before field. Something like this should do the job:

<?php
$this->record++;
if ($this->record%2 == 0) {
   $x = $this->lMargin;
   $y += 50; // <-- define here some height of your element
}
?>

The and tags can be omitted, but for better code style it is useful here.

ledom’s picture

Thanks to show me the way.

Here is what I do:

Position relative to: Field Self
Position y: 100

PHP Code Before Output:

$this->record++;
//One line with two columns
if ($this->record%2 == 0) {
   //move to right column
   $x = 100;
   //move to previous line
   $y -= 100; 
}

PHP Code After Output :

if ($this->record%2 == 0) {
   //go back to left column
   $x = $this->lMargin;
}

It works fine for the first page, but on second page there is only on entry then it overwrite second and next entries on the first page. I do not understand why it go back to first page when I use Field Self

EDIT: tested dev version > same problem. Using Last Writen Position semmes to solve the overwrite first page.

ledom’s picture

Unable to get it working for more of one page. It would be good if drupal can generate directly pdf labels but finally I found another way to get it.

If someone is interested:
- Use Views bonus CSV to create a CSV from the view
- Use the linux tool Glabel to import CSV and print labels

hunziker’s picture

Status: Active » Closed (won't fix)

For labels with an external solution the approach mentioned by ledom is well. If you are familiar with OpenOffice, you could also using the serial printing functionality of it. (This works also on different architectures than linux.)

hozt’s picture

Would it be possible to have a Grid Format for this module? This would allow for us to create multi-column views for printing sheets of labels.

Thanks for this great module!

amirimran’s picture

I guess that is possible, i needed same thing in one of my project, so i have created some custom code which allows me to draw data in grids, i can have 2 or more columns. i will try to post that as patch and would love to see the comments on that one.

For now i have raw code in multiple files which i need to clean up so it won't become sort of offensive for this module lovers :)

mbria’s picture

amirimran, do you mind to publish your raw code?

I'm in a 4 columns layout for label printing and your code looks like the best approach.

Cheers,
m.

amirimran’s picture

Hi, i would gladly but at the moment i am trying to make it more clean so it becomes easy to understand and use.

I have used pdf un formatted as base but i think it can be done more efficiently on base of pdf table.

well, if you think you can hold off till this weekend i may have more useful version for you. what do you think?

mbria’s picture

Version: 6.x-1.0-rc1 » 6.x-1.x-dev
StatusFileSize
new18.12 KB
new145.54 KB

Sorry for my silence amirimran.

Yes amirimran, if you found a clean solution for this and you publish, it would be nice because my approach is far from been elegant or complete. :-)

With the following piece of code and a little bit tunning (to fit your label layout) you can print labels of any number of columns.

Known bugs?
Plenty of them:

  • It only prints your first page, but the rest are buggy.
  • Last line of labels is not printed.
  • ...

I attach a PDF with the results.

Those are my settings:

BASIC settings:

  • Style: PDF unformatted
  • Row style: PDF Fields
  • Items to display: Unlimited

PDF settings:

  • Path: list/material...
  • Menu: No menu
  • Attach to: Page
  • PDF Page Settings: A4
  • PDF Fonts Settings: FreeSans at 6 pt
  • PDF Template Settings: Yes
  • CSS File: None

And this is the tricky part, at "PDF Fields" this is the code:

Position relative to: Last writing position.
Position relative to corner: Top Left

PHP Code Before Output:

//Item counter:
$this->record++;

//Number of columns:
$maxCols=13;

//Label size: 25mmx45mm
$width = 25;
$height = 45;

//A temporary solution for something that looks like a bug in the module: 
//While Page margins "top" works fine, "left" margin has no effect.
$xInit = 18;

//Label separation ("padding")
$xMargin = 1.8;
$yMargin = 10;

//Which column are we processing?
$col = $this->record%$maxCols;

//First column is special:
if ($col == 1) {
   $x = ($xMargin/2) + $xInit;
   $y += $yMargin/2;
}
else {
   //Last column is also special:
   if ($col == 0) {
       $x  = $width*($maxCols-1) + $xMargin*($maxCols-2) + $xMargin/2 + $xInit;
       $y -= $height;
   }
   else {
       $x  = $width*($col-1) + $xMargin*($col-2) + $xMargin/2 + $xInit;
       $y -= $height;
   }
}

PHP Code After Output:

if ($this->record%$maxCols == 0) {
   //go back to left column
   $x = $this->lMargin + $xMargin;
   $y += $yMargin;
}

I'm not proud, but will do the job till I find a definitive solution.

I also attach an export of my view, just in case other like to test.

nonzod’s picture

My ugly solution

PHP Code Before Output:

$this->record++;
$w = 63.5;
$h = 38.1;
$numCols = 3;
$perPage = 21;
$offsetX = 5;
$offsetY = 5;

$item = $this->record % $perPage;
if($item == 0)
	$item = $perPage;

$col = $item % $numCols;
$row = ceil($item / $numCols);

if ($col == 1) {
	$x = $offsetX;
}
if ($col == 2) {
	$x = $offsetX + $w;
}
if ($col == 0) {
	$x = $offsetX + ($w*2);
}

if($row == 1) {
	$y = $offsetY;
}
else {
	$y = $offsetY + (($row - 1) * $h);
}

// Debug
//$content = $this->record.':['.$x.','.$y.']';
//print $this->record.':['.$x.','.$y.']';

PHP Code After Output:

if($item == $perPage)
  $this->AddPage('P', 'A4');
Makku01’s picture

@nonzod: thank you for your code. It works really good. Except for the last row on a page. When this label comes exceeds a certain y coordinate near the bottom of the page, it only prints the first label of the last row[x] and then skips to the next page. On page two it now prints the missing label of the row[x] on the desired coordinates and then it evalutes ($item == $perPage) as true and creates a new page.

Do you have any idea how to solve this?
Thanks in advance!

vegansupreme’s picture

Makku01, I've had success setting the page bottom margin to some negative number. It should be okay to use even a large number.