As of yet, I've not found an up-to-date/working solution in Drupal 7 to have the same functionality that Views PDF offers, WHILE allowing me to position my fields exactly onto where an Avery template would print off Mailing Labels. I attached the Avery template I'm using-- this is where I need the fields arranged. The other attachment shows how the output of my fields need to be positioned/arranged.

My question to anyone who can help:
Is this arrangement possible with Views PDF?

Thank you for your time, I look forward to any responses.

Comments

Issue tags:+PHP, +images, +overlap, +positioning, +on top of

There have been multiple posts about column unformatted layouts, posts about grid layout, and many good suggestions that would make this module super powerful. If I knew much about module development, I wouldn't mind helping out on a module like this because it looks to be - already - a powerful module, but what it could potentially become is far greater. Right now, it is hard to work with, but patience brought me good results.

I was able to achieve an exact replica of my sample_of_arrangement.png above on just ONE column.. the posts with PHP snippets about multi-column hacks didn't work for me (was for D6 I believe, this is D7)-- all it did was alternate one on the left, then one on the right on each row. This works fine though because the labels can be flipped in the printer to use the other side.

I was forced to use Last Writing Position because when the position was relative to Field:self, my fields would overlap using default settings. However, Last Writing Position made each of my records have double y position (no idea), even though the height of each & the y position had been set up correctly, so I used a customized php snippet to force my columns up (cut the y in half):

<?php
$this
->record++;
if (
$this->record != NULL) { // target all records (many ways to do this)
$y=$y - 1.337; // same as writing $y-=1.337; I believe...
}
?>

1.337 was my height of each row in inches (pretty leet number if I must say so)

Doing so allowed me to put them in place and is perfect on every page. I used an exposed filter in block to make a generator. (Man I wish others would be open about how they do things, especially when a module's UI is so tough to use). So there you go, hope I helped someone out.

Status:Active» Fixed

Title:Positioning Field Output for Avery Mailing LabelsPositioning Field Output for Columns
Status:Fixed» Active
StatusFileSize
new84.9 KB
new149.78 KB

My client wanted another type of Avery mailing labels-- but this one required 3 columns. I needed to figure this column thing out. I searched this issue queue in and out for some help on columns and found very little, so I thought I'd help someone out by explaining how I succeeded in hacking this. I'd also appreciate some help with my very last issue with this column layout (hence why I am opening this up as a Support Request again).

First, view 5960_template.pdf... this is the template I'm using to fit the labels onto.

Now, see how I was able to do this in this picture: mailing_labels_bottom_2.png.

The normal positioning is:

|1|
|2|
|3|
|4|
|5|
|6| etc.

But I needed:

|1|2|3|
|4|5|6| etc.

The positioning of column 1 is always in place, so I never had to write code for the fields in column 1. All I had to do was manually move the X and Y for each record in columns 2 and 3, but each label on one page had to be done IN ORDER (not in one conditional IF statement containing a bunch of OR's) because the positions are relative to each other, hence why the code is so long. I made field 1 relative to its Last Writing Position and in the PHP before output, I wrote:

<?php
$this
->record++;
$r=$this->record;
// First Column is already in position, so we skip to columns 2 & 3 on row 1:
   
if ($r == 2||(($r-28) % 28) == 2) {
   
$x=$x+2.75;
   
$y=$y-1;
}
    if (
$r == 3||(($r-28) % 28) == 3) {
   
$x=$x+5.5;
   
$y=$y-1;
}
// First Column is already in position, so we skip to columns 2 & 3 on row 2:
   
if ($r == 5||(($r-28) % 28) == 5) {
   
$x=$x+2.75;
   
$y=$y-1;
}
    if (
$r == 6||(($r-28) % 28) == 6) {
   
$x=$x+5.5;
   
$y=$y-1;
}
// First Column is already in position, so we skip to columns 2 & 3 on row 3:
   
if ($r == 8||(($r-28) % 28) == 8) {
   
$x=$x+2.75;
   
$y=$y-1;
}
    if (
$r == 9||(($r-28) % 28) == 9) {
   
$x=$x+5.5;
   
$y=$y-1;
}
// First Column is already in position, so we skip to columns 2 & 3 on row 4:
   
if ($r == 11||(($r-28) % 28) == 11) {
   
$x=$x+2.75;
   
$y=$y-1;
}
    if (
$r == 12||(($r-28) % 28) == 12) {
   
$x=$x+5.5;
   
$y=$y-1;
}
// First Column is already in position, so we skip to columns 2 & 3 on row 5:
   
if ($r == 14||(($r-28) % 28) == 14) {
   
$x=$x+2.75;
   
$y=$y-1;
}
    if (
$r == 15||(($r-28) % 28) == 15) {
   
$x=$x+5.5;
   
$y=$y-1;
}
// First Column is already in position, so we skip to columns 2 & 3 on row 6:
   
if ($r == 17||(($r-28) % 28) == 17) {
   
$x=$x+2.75;
   
$y=$y-1;
}
    if (
$r == 18||(($r-28) % 28) == 18) {
   
$x=$x+5.5;
   
$y=$y-1;
}
// First Column is already in position, so we skip to columns 2 & 3 on row 7:
   
if ($r == 20||(($r-28) % 28) == 20) {
   
$x=$x+2.75;
   
$y=$y-1;
}
    if (
$r == 21 || (($r-28) % 28) == 21) {
   
$x=$x+5.5;
   
$y=$y-1;
}
// First Column is already in position, so we skip to columns 2 & 3 on row 8:
   
if ($r == 23||(($r-28) % 28) == 23) {
   
$x=$x+2.75;
   
$y=$y-1;
}
    if (
$r == 24||(($r-28) % 28) == 24) {
   
$x=$x+5.5;
   
$y=$y-1;
}
// First Column is already in position, so we skip to columns 2 & 3 on row 9:
   
if ($r == 26||(($r-28) % 28) == 26) {
   
$x=$x+2.75;
   
$y=$y-1;
}
    if (
$r == 27||(($r-28) % 28) == 27) {
   
$x=$x+5.5;
   
$y=$y-1;
}
/* The issue: first Column is already in position, so we skip to columns 2 & 3 on row 10:
But columns 2 & 3 on row 10 (for some reason) make these two records move to the next page.
For now, I don't know how to make them stay on the previous page, so I had them start on column 1 on the NEXT page.
*/
?>

Here's what each IF statement is saying, for example:

<?php
if ($r == 21 || (($r-28) % 28) == 21)
?>

This code reads out 21 or every number after 21 that would have 28 added onto it. It would tell me: 21 ... 49 ... 77 ... 105 ... 133 ... and every other number +28 continuing.... example:

<?php
for($r=0;$r<500;$r++){
   if(
$r == 21 || (($r-28) % 28) == 21)
   {
        echo
$r . "\n";
   }
}
?>

Outputs:

20
48
76
104
132
160
188
216
244
272
300
328
356
384
412
440
468
496

But why 28? There's 30 labels per sheet, but I'm starting the code on record 2, so every 28 records continuing falls on a new page in the same spot. That is why I used modulus to define "every 28 record's position" on every possible continuing page.

The Problem!

The last two labels on each sheet are output to the next page. How do I bump them back?

Columns 2 & 3 on row 10 (for some reason) make these two records move to the next page. For now, I don't know how to make them stay on the previous page, so I had them start on column 1 on the NEXT page. It would be a waste of 2 labels per page (which isn't a HUGE deal), but it would be really nice to know what I'm doing wrong.

Hope I helped some people out, and I hope that someone can help me out.

This was an interesting issue, i had to do the same thing. so i created some custom code. i am in process of cleaning up this.

When done, we will have a new Format Type, we can call it Grid or Columns (this will show on the page where you see PDF unformatted and PDF Table)

When this new type selected you can display your data in one or more grids, for example with my test code i can have 2 or more columns on my pdf.

If anyone is too hungry i can post him the raw code, otherwise i will clean up and would post as patch so it can become more useful.

@ amirimran: i am in desperate need of this functionality for D6. Could you please post your code if it's suitable?
Thanks a lot in advance!

@amirimran, also looking for grid code if it's available.

Did you find a solution for this yet?

@Makku01,

amirimran and I reached a very temporary solution that does not involve a patch, but a module rewrite, hacking several Views PDF files, even creating some new ones (like views_pdf_plugin_style_grid.inc), making them render the HTML with table markup. I contacted him back in the late winter time to see if he could assist in helping me use his work for my project. Come May, we were able to incorporate "letter sized" pages with two different column types: (one with 3 columns, and one with 2 columns). I am not very experienced with modding, so I donated a small amount of money to help progress that development. It is a very hackish solution and I would advise against using it right now because Views PDF is hard to use enough the way it is, but using this custom module requires you to set it up in the right order for correct installation. In addition, each Views PDF render logs thousands of errors in the Drupal console because TCPDF needs all tags to be complete-- it still works beautifully after many days of hacking the code, but it isn't a clean solution. I'll be able to help a little more later on, but I have to leave town now. The code needs to be cleaned up, but I'd be very happy to attach it here if someone wants to work on it. Most of the work is in one .inc file: views_pdf_plugin_row_fields.inc. Using this approach is all experimentation because half of the work is still in the GUI (but it's hard to know what works in the GUI-- everything is a surprise). If the GUI doesn't do the change, you have to try and hack it in views_pdf_plugin_row_fields.inc. At the end, I was able to finish two projects for a client on a development website.

If you are interested, (or would like to contribute to cleaning this code and maybe getting it incorporated into a development project), let me know and I'll clean the code up just a bit and attach it here, (I'll be back Wed).

Yes, Please attach it.

StatusFileSize
new21.08 KB
new25.85 KB
new46.07 KB

Attached is the Views PDF 7.x-1.0-rc1 column customization worked on by amirimran & myself. It can render 2 & 3 column type :

New Format Options

It would be great to have someone fix this up and create a patch for this, seriously.
I am not knowledgeable enough to do this and your help would be really appreciated by many.

IMPORTANT NOTE about changes.txt: These notes were made almost all the way through the development (which was AFTER we added the 2 column type and BEFORE we added the 3 column type), I analyzed the code of the original 7.x-1.0-rc1 files and compared it to what amirimran had made. The only other thing I know he did was create views_pdf_plugin_style_grid_2.inc for the 3 column layout. I'm sure there is a line or two different in several other files (linking the 3 column layout in), but hopefully these 99% of changes help whoever would like to contribute to this project in development. If you have a question about how something works, contact amirimran because he is the one who created the framework of this addition.

Installation:
1. Replace with current module folder (required until someone makes a patch).
2. Create a new view (Normal Page) and feel free to disable it because you won't be using it.
3. Create a new PDF Page.
4. Change format to 2 or 3 column format (seen in screenshot above).

To use, you will be using the GUI & modifying views_pdf_plugin_row_fields.inc. You will find that it is frustrating and cumbersome to work with, but entirely possible with enough patience.

Let us know if someone decides to fix this up or if this helped you.

Thanks

For this particular functionality I am getting a failed to load document ?

Is there any reason this would be happening?

thanks

Nick

Okay with some trial and error I was able to get ti to work. But I am only able to show the title field ?
Any reason this might be happening?

thanks !

Now there are no fields showing up?

I am only ablt to display field content:title in my pdf?
I have 3 other fields I am trying to show integer,post date, and a link none of these show up at all in the pdf ?

thanks,

Nick

Category:support» feature

Could you create a patch for the changes against the 7.x-1.x-dev version? That would make it easier to test and debug.

@Lsoesen

I would create a patch but I didnt create this version of the module and I contacted both ownage and amirimran via personal contact form and they did not respond ? I can confirm that this version of the module only displays content:title field with my example. I can post my view if that would help. Let me know thanks

naeluh Nick

I cannot assist in making a patch for two reasons:
1) I don't have the experience to make a patch correctly
2) Unfortunately I also don't have ANY free time-- my life is very hectic right now

For anyone that would like to make a patch, it wouldn't be hard and I encourage you to try which is why I'm giving you every bit of information I can. My changes.txt file above was created by comparing the original 7.x-1.0-rc1 files to the custom module using http://www.quickdiff.com/

Using a tool like Quick Diff is one way you can see where all the changes are in these files. Again, do not use changes.txt to make the patch because it was not updated for the 3 column structure. changes.txt shows the module's changes only when the 2 column structure was in place, as I noted before. Since the 3 column structure was introduced, a few more files were created and a bit more code was appended on a few of the files. That is why the custom module I attached in comment #10 will have to be compared to the original using a tool like quick diff (or whatever you use). Luckily, there aren't that many files to look through.

----

In my case, I used this to create mailing labels, and you will see my hard coded HTML styling in the tables on views_pdf_plugin_row_fields.inc for both grid types (2 column & 3 column). This is to fit my specific templates of Avery #5960 & #5962.

In my view, I have groups of labels made into different displays within the view (otherwise rendering them all at once would cause the server to get overloaded, especially when you're like me and you have >2 thousand labels to generate-- they have to be done in sets, or groups, (or in views called displays) hence the G1 in my attachments standing for Group 1). So the only difference between all of my displays is the offset variable to tell it to render the next so many labels. The first display: Page, can be disregarded. This was created upon installation (see installation step 2 as I posted above in comment #10).

Avery #5960 (3 column, 10 rows, 30 labels per page):

http://www.avery.com/avery/en_us/Templates-%26-Software/Templates/Labels...
^In the link above, I downloaded their PDF template and used it in Views PDF as a template to align my labels. I then disabled the template when it was ready to go.

If you would like to see my #5960 view, see attachment: 5960_G1_View_Options.png
My View Export: Avery_5960_3_Column_10_Rows_View_Export.txt
My Field Setup: 5960_field_setup.png

Note: For in this view, under PDF_Fields - "Settings" set every field relative to Last Writing Position.
Playing with other variables sometimes works (like Bold, font choice, and size).

Sample of my output for Avery # 5960 (blurred because of sensitive information):
Avery #5960 Render Sample

Avery #5962 (2 column, 7 rows, 14 labels per page):

http://www.avery.com/avery/en_us/Templates-&-Software/Templates/Labels/A...
^In the link above, I downloaded their PDF template and used it in Views PDF as a template to align my labels. I then disabled the template when it was ready to go.

If you would like to see my #5962 view, see attachment: 5962_G1_View_Options.png
My View Export: Avery_5962_2_Column_7_Rows_View_Export.txt
My Field Setup: 5962_field_setup.png

Note: For in this view, under PDF_Fields - "Settings" set Photo relative to Page, while every field to Last Writing Position.
Playing with other variables sometimes works (like Bold, font choice, and size).

Sample of my output for Avery # 5962 (blurred because of sensitive information):
Avery #5962 Render Sample

---

The hard part is the code framework, which is already in place; it just needs to be cleaned up now.

Any place in the views_pdf_plugin_row_fields.inc that I have specified specific markup to my case, like table column (<td>) widths and row (<tr>) heights should be incorporated into a GUI setting for this module. A few more features to incorporate into the GUI would be allowing the change of the table cells background colors, cell spacing, and cell padding. For me, those were the ones that came in handy and was the only way I could fit these labels exactly in position-- but let me remind you, it took LOTS of patience. If incorporated into the GUI and worked on, this will speed up the process and give users much more power in Views PDF. TCPDF is very strict on the number of HTML attributes it allows-- looking into the documentation you can find these tags. The ones I read about were the following, but there are more:

  • text-decoration
  • color
  • background-color
  • font-size names (x-small, x-small, small, medium, large, x-large, xx-large)
  • text-indent
  • page-break-before
  • page-break-after
  • page-break-inside
  • line-height (limited)
  • borders
  • width & height (on images)
  • catch-all
  • font-stretch
  • letter-spacing
  • border-spacing (tables only)
  • padding (tables only)

Conclusion:

These are my exact examples in using both of these new grid types and I hope it answers all questions-- it's all I know, and even though in a buggy stage, it's useful for my clients in production use. Hopefully someone can merge it into the module because having a Table structure as its own grid setup is, in my opinion, vital for the future of Views PDF. It is literally the most flexible way to place your content using the TCPDF rendering engine.

So the code from #10 is the most up to date code at the moment, right?

Yes, that is what I am using right now.

I'm using 3 column grid thanks to code in #10, but it will only render fields in multiples of 3. If I have 4 or 5 fields, it only renders the first 3; 10 fields, it only shows 9, etc. Are other people getting this same behavior? Any known work arounds?

I think I've figured out another solution to the problem in #3.

In PDF page settings, set the bottom margin to a negative value. -3 works for me.
Set field positioning relative to PAGE
Set Height as desired. The example in #3 would probably use 1.

Add this code to PHP Code Before Output (without the leading PHP tag)

<?php
$this
->record++;
$initr=$this->record;
//set top margin
$topmargin=.5;
// change this number to the number of items per page
$r=($initr % 30);
if (
$r==0) {
//also change this to items per page
$r=30;
}
   
//column 1
   
if (($r % 3) == 1) {
   
$x=.25;
   
$y=((floor($r/3)+1)*$h)-($h-$topmargin);
}
   
//column 2
   
if (($r % 3) == 2) {
   
$x=2.75;
   
$y=((floor($r/3)+1)*$h)-($h-$topmargin);
}
   
//column 3
   
if (($r % 3) == 0) {
   
$x=5.5;
   
$y=((floor($r/3)+1)*$h)-((2*$h)-$topmargin);
}
?>

Then add this code to PHP Code After Output

<?php
//change this to number of items per page
if ($r == 30) {
$this->AddPage();
}
?>

This code is pretty easy to adjust if you want more or fewer items per page, or change the spacing.

Wow, thank you for that solution, vegasupreme.

I haven't tested it yet, but it goes to show how a powerful concept can be simply implemented.

My solution in #3 was my favorite and most clean of the two solutions minus that last 2 label issue, so if your solution will easily offer column & row spacing (margins), i'd say most people will be able to skip the table mod all together. With the table mod, cell spacing & cell padding was all I could work with and the only thing that saved me on getting each column to match the width of the labels (so long text wouldn't still spill over off the end of the labels). But with your method, by specifying the x positioning alongside a column width (accounting for the width of labels), this might be possible.

StatusFileSize
new102.15 KB

I can now verify that #21 does in fact work very well! Thank you vegansupreme. Can I have a few minutes of your time to explain the only issue I'm having?

See my attachment (a zipped PDF, for security reasons).

There are 30 of these labels per sheet, just like your example and now I've been able to add USPS Intelligent Mail barcodes as well, (which is a feature built into TCPDF). Here is my ONLY issue: the barcode for the last record on each page (record 30) is insisting on inserting itself on the NEXT page. I've highlighted this barcode with yellow to point it out for you. Barcodes are simply arranged with X & Y coordinates, but it seems the positioning is irrelevant with this last record (30). Any value the Y is set to on record 30 will keep it on the next page-- I even tried putting in a negative value to push it back on to the previous page, but it only disappears if you do this.

How can I place this barcode into its right position?

Here is what I have:

Everything BUT the barcode is written together as one field-- (I could not find a way to render the barcodes AND write them together with the address, so X & Y positioning is all I could do).

Full Address Field:
- (This is a combination of about 8 different fields rewritten as one).
- Relative to Page
- Height of 1"
- Code Before & After is the same as your example, except I have a larger .75 top margin; (I bumped up the top margin to give the barcode room on the label).

Barcode Field:
- As you know, there is no "barcode" field to add in Views so I instead added in my "zip code" field because I'd be requiring it after the hyphen in the barcode calculation anyway.
- Relative to Page
- Height of anything (just to make it show up)
- Code Before:
In the TCPDF examples, example_027 shows how they insert this barcode on line 263:

<?php
$pdf
->write1DBarcode('01234567094987654321-01234567891', 'IMB', '', '', '', 15, 0.6, $style, 'N');
?>

Note: I was required to trim out any zip code's hyphens with the "str_replace" function.
So I did this for each record in order to position them properly with X & Y:

<?php
$initr
=$this->record;
$r=($initr % 30);
// Barcode style used for all regular barcodes
$barstyle = array (
   
'border' => false,
   
'text' => false, // if true prints text below the barcode
   
'font' => 'helvetica', // font name for text
   
'fontsize' => 2, // font size for text
   
);
// Barcode style to highlight the culprit barcode (record 30) in yellow
$barstyle2 = array (
   
'border' => false,
   
'text' => false, // if true prints text below the barcode
   
'font' => 'helvetica', // font name for text
   
'fontsize' => 2, // font size for text
'bgcolor' => array(255,255,128)
    );
// Row 1 holding each record's X & Y coordinates
if ($r == 1) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 2) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 3) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '.58', '', 0.15, 0.015, $barstyle, '');}
// Row 2 holding each record's X & Y coordinates
elseif ($r == 4) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '1.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 5) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '1.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 6) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '1.58', '', 0.15, 0.015, $barstyle, '');}
// Row 3 holding each record's X & Y coordinates
elseif ($r == 7) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '2.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 8) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '2.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 9) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '2.58', '', 0.15, 0.015, $barstyle, '');}
// Row 4 holding each record's X & Y coordinates
elseif ($r == 10) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '3.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 11) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '3.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 12) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '3.58', '', 0.15, 0.015, $barstyle, '');}
// Row 5 holding each record's X & Y coordinates
elseif ($r == 13) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '4.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 14) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '4.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 15) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '4.58', '', 0.15, 0.015, $barstyle, '');}
// Row 6 holding each record's X & Y coordinates
elseif ($r == 16) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '5.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 17) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '5.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 18) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '5.58', '', 0.15, 0.015, $barstyle, '');}
// Row 7 holding each record's X & Y coordinates
elseif ($r == 19) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '6.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 20) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '6.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 21) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '6.58', '', 0.15, 0.015, $barstyle, '');}
// Row 8 holding each record's X & Y coordinates
elseif ($r == 22) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '7.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 23) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '7.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 24) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '7.58', '', 0.15, 0.015, $barstyle, '');}
// Row 9 holding each record's X & Y coordinates
elseif ($r == 25) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '8.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 26) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '8.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 27) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '8.58', '', 0.15, 0.015, $barstyle, '');}
// Row 10 holding each record's X & Y coordinates
elseif ($r == 28) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '9.58', '', 0.15, 0.015, $barstyle, '');}
elseif (
$r == 29) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '9.58', '', 0.15, 0.015, $barstyle, '');}
else {
$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '9.58', '', 0.15, 0.015, $barstyle2, '');}
?>

I have been working on these barcodes all day for about 4 days straight and am SO CLOSE, but cannot figure this little issue out. I hope you know that I really appreciate your help on this.

Thanks

@ownage, Just so I'm clear, In your PDF view, you've only got 2 PDF fields: all the address info combined into one, and the barcode, which must be rendered separately, in another.

Does the the address field have $this->AddPage(); in the "after" field? If so, try removing it from there and moving it to after the barcode output. Or maybe try rearranging the the order of the fields in your view.

I'm guessing it renders address #1, then barcode #1 etc… address #30—$this->AddPage(); then barcode #30, on the next page.

Hope that helps!

StatusFileSize
new7.96 KB

@vegansupreme, yes, you are clear with your first statement. Thanks for getting back to me so quick!

Cutting the "PHP Code After Output" from the "Address field" into the "Barcode" field makes everything overlap on one page: http://tinyurl.com/tcpdf-mailing-labels-2

Let's keep going on your ideas though, here is my order of fields:
TCPDF Order of Fields

You mentioned rearranging them, I tried this before and had some weird results. To test this out once more, let me make a note that I also fixed the "PHP Code After Output" back again (from above). So I just switched the fields described in the image above, and that actually changed the issue in a positive way! Wow!

Take a look: http://tinyurl.com/tcpdf-mailing-labels-3

Now, all that is wrong is the last record going to that position. This has to be due to my "else" statement at the end of all the elseif's:

<?php
else {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '9.58', '', 0.15, 0.015, $barstyle2, '');}
?>

There was a reason I resorted to using "else" though, because I couldn't identify that last record doing this traditional approach:
<?php
elseif ($r == 30) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 5.75, '9.58', '', 0.15, 0.015, $barstyle2, '');}
?>

^^ If I do that, the barcode vanishes on the 30th label for every sheet AND the last record of the document.

It seems there is a correlation here; I think all I need to do is identify the last record of the document. Do you know how to do that? I think you posted on that once didn't you? lol

@ownage, I'm still stumped on finding the last record.

Is there a function in TCPDF to get current page, or go to a specific page? If so, maybe you could use your code/view from #23, but tell record 30 to be rendered on the previous page. Then you would probably have to move back to the current/next page in order to avoid either inserting blank pages, or rendering everything on the same page.

@vegansupreme,

I'm thinking there's an easier solution-- something I would be able to add to my elseif statements that can target the last record.

For instance, you have the variables of use in your code:
$r = Records for each page (1-30)
$initr = Records for entire document. Say you have 46 labels, it would show 1-46.

Being able to use that, wouldn't there be a way to call the end of the $initr array using PHP?

http://stackoverflow.com/questions/3687358/best-way-to-get-last-element-...

I honestly don't know PHP well enough to do this very quick, but I'm trying...

Like if we could add something like this:

<?php
$last
= end($initr); // Put something like this at the top...
// Then something like this for each record. (This probably is not correct syntax)...
elseif (($r == 4) || ($initr[4] == $last)) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '1.58', '', 0.15, 0.015, $barstyle, '');}
elseif ((
$r == 5) || ($initr[5] == $last)) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '1.58', '', 0.15, 0.015, $barstyle, '');}
?>

I don't know even if that would work, but it seems possible. The only part that I'd see stopping it from working is the else statement at the end (which calls everything else), cause that seems to be calling the 30th record on each page AND the very last record. You seem good at PHP, am I making any sense?

@ownage,

I get what you mean, but honestly, I think you know more PHP than I do. Maybe the key to figuring this out is to look into "record" as in

$this->record++;
$r=$this->record;

Could you find the last item of record? I'm not sure what record even is. Is it an array?

@ownage,

I've just gotten my own project that involved rendering more than one views field into the PDF, and lining up the two fields. After some trial and error, I've gotten something that seems to work. I still haven't figured out how to get the last record but ended up not needing it for this.

Maybe you've already figured this out, and maybe this is totally obvious to a developer, but it wasn't obvious to a designer such as myself:

Only 1 field should have $this->record++; I put it in the first field.

Any variables apply to all fields. So if you have $r=$this->record; it could interfere if you're using $r in another field. I used $r and $initr for one field, and $r2 and $initr2 for the other field, but probably could have just as easily streamlined the code to use the same variable for each field. I wanted to keep the two fields independent, at least in the "trial and error" phase.

Thanks vegansupreme. I did figure out a solution that works for me thanks to your advice to reposition my fields.

The last issue I had was targeting the last record so I could position the barcode accordingly. The code was always making the very last label have an $ititr value of "0" regardless of which column it ended in. In addition, this barcode simply didn't render at all, but it was only an issue with the "last" label.

Since I'm rendering out a certain number of labels in each group, (600 labels at a time, which is 20 pages of 30 labels per sheet), each group of labels ends at the end of the 20th page in the 3rd column.

The only problem left was that the last group never had a full 20 pages and will indeed end in a random column...

Here's my work around: my labels are ordered with zipcode ascending, so I made a fake label with the zipcode "99999" so that one mock label could be at the end. Therefore, it didn't matter if it rendered a barcode.. one label will have to be voided, which isn't a big deal when you're dealing with about 2000 labels.

Hi

Great thread, I'm looking for a grid solution for viewspdf for a long time.
Do I need to add the php code from #21 for every single field?

I have tried all the above solutions of adding php code "PHP CODE BEFORE OUTPUT" and "PHP CODE AFTER OUTPUT", I have given my fields a width and height but nothing seems te work

It's like the php-code is not processed...

@maxplus
You would need to put the code on each field that you want to appear as a grid. It's helpful to combine multiple fields into one using rewrite.
The PHP isn't working at all for me either since upgrading to 1.0/dev. See #1513490: Fatal error: Call to undefined function php_eval()
In order for PHP to work, I need to use rc1.

@vegansupreme

You are exactly right, the php code only works with the rc1 release and not with the current stable release.
I was also thinking of combining fields but then you lose control over positioning...

Thanks for your quick reply but my goal is only to create two view result rows on one Page and then start a new Page. I even dont need columns .
I have multiple fields including one image field that all should be positioned the same Way for every view row but I cannot seem to manage that...

Any advice?

The 3 column code can be modified to 2 columns. Just change all the 3s to 2s and get rid of the column 2 section. you'll have to adjust the spacing to your needs, of course. Would you want a fixed number of items per page?

StatusFileSize
new91.89 KB

Hi vegansupreme,

I just need a fixed number of items on one page: 2 items on one page.
I also don't need colums, so it is just one column

I tried your code from #21 and entered $r=2 but I don't manage to get rid of the column uneeded code.
=> what is the best way to change this to get a one column and txo items per page view with the ablity to set all the positions of all the different fields (my view has 7 fields)?
=> can I use 7 times the same php code (for every single field) and only change the x and y coordinates (and height and width)?

I attached a screenshot how it should look

Many thanks for the great quick help!

maxplus,
Because you're not doing columns, you could specify exact coordinates for each item on the page. I used a little math in #21 to calculate the correct y position for subsequent rows.
This code should work for you. Just change $x/y=?; to whatever x/y values work for your field. Also see #29 about rendering multiple fields. I'm not sure if you can use the same variables ($r, and $initr) for different fields. I had some problems when I tried. I ended up using $r2 and $initr2 for the second field and so on.

<?php
$this
->record++;
$initr=$this->record;
$r=($initr % 2);
if (
$r==0) {
    
//also change this to items per page
    
$r=2;
}
    if ((
$r % 2) == 1) {
   
$x=?;
   
$y=?;
}
    if ((
$r % 2) == 0) {
   
$x=?;
   
$y=?;
}
?>

Then add this code to PHP Code After Output, **but only to the last field.

if ($r == 2) {
$this->AddPage();
}
?>

Hi vegansupreme,

you pointed me in the right direction.

The things I always did wrong where:
1. adding "$this->record++;" to every field
2. using the same $r and $rinit variables with every field
3. adding a page break to every field with "$this->AddPage();"

Now it works because
1. I only add "$this->record++;" to the php code of the first field
2. Use different $r and $rinit variables for every field
3. Only add a page break at php-code-after of the last field

Thank you very much for your help.

The only thing that does not work for the moment is rendering a link field to a QR-code with the Mobile Tools module.
It seems that Views pdf doesnt support this display type.
In node view my QR code is displayed correctly with the same formatter I use in my views pdf view.

maxplus,
check out http://tcpdf.org TCPDF, and therefore Views PDF can render QR codes w/o using mobile codes. If you see something like $pdf-> just change to $this->

But this is probably getting off topic.

Version:7.x-1.0-rc1» 7.x-1.x-dev
Status:Active» Patch (to be ported)

Ok, let's set as a patch that needs port to the current 7.x-dev, so somebody can try to take a crack at it one day.

FYI, I just spent like 2 days trying to figure out why my new labels (3rd set) weren't breaking onto a new page; they were rather overlapping on the 1st page, even with the negative bottom margin and same math instilled. Found a work around by taking the code out of the "PHP After" and writing one extra conditional statement in the "PHP Before" so here is the code-- hope it helps someone:

<?php
$this
->record++;
$initr=$this->record;
//set top margin
$topmargin=1.3;
// Change this number to the number of items per page
$r=($initr % 6);
if (
$r==0) {
// Also change this to items per page
$r=6;
}
   
//column 1
   
if (($r % 2) == 1) {
   
$x=.27;
   
$y=((floor($r/2)+1)*$h)-($h-$topmargin);
}
   
//column 2
   
if (($r % 2) == 0) {
   
$x=4.27;
   
$y=((floor($r/2)+1)*$h)-((2*$h)-$topmargin);
}
if (
$r == 1 && $initr != 1) {
$this->checkPageBreak($this->PageBreakTrigger + 1);
}
?>

The coding talked about in this thread has now been effective for the following column layouts:

  1. 3 columns, 10 rows (30 items per page)
  2. 2 columns, 7 rows (14 items per page)
  3. 2 columns, 3 rows (6 items per page)

Cool deal!

Priority:Normal» Major
Status:Patch (to be ported)» Needs work
Issue tags:+accepted feature request

Ok needs works this feature ... Let me first handle some other Critial Issues. Thanks.

Priority:Major» Normal
Issue tags:+#views_pdf_7.x-2.x

Tagging for the next version.

Version:7.x-1.x-dev» 7.x-2.x-dev
Status:Needs work» Active

Issue summary:View changes

more

Hello,

i want to create a pdf with 16 labels (2 columns / 8rows). I use pdf unformatted display with pdf fields.
I tested the proposed code in #40 but without success. I get a blank page if I generates the pdf with this error :

PHP Fatal error:  Using $this when not in object context in /srv/data/web/vhosts/www.mysite.com/htdocs/modules/php/php.module(80) : eval()'d code on line 2

I use the 1.x-dev release. For me, this version fixes errors with php 5.4. Should I use a different version?
Should I insert the code for all fields? In before field ?

Thank you for your help.

I have only tested this code in post #40 with PHP v5.3.3 on the 7.x-1.0-rc1.

No idea which of the reasons has caused your issue. Unfortunately, this module takes a lot of playing around before things work out to your advantage.

If you can maybe suppress the errors by trying out the rc1 and need some tips, basically you're making every field relative to one field in each record, and having proper ordering of fields for rewritten content in Views. The job for most mailing label cases is to rewrite one field to display all of your content, using mostly: basic HTML, tables, spans, and bgcolor="######" to see your element's boundaries.

For example, this is my [field_cinfo_full_name] field rewritten to include all address information positioned above it:

<i><b>[field_cinfo_full_name]</b><br>
[field_cinfo_address]<br>
[field_cinfo_city], [field_cinfo_state] [field_cinfo_zip]</i>

That [field_cinfo_full_name] field is the one you insert the #40 code into the "PHP Before," under Views' FORMAT: Show "Settings." Ensure that [field_cinfo_full_name] is relative to "Page" and all other fields are relative to [field_cinfo_full_name]. In the code, tweak the X & Y values and all settings in the first lines accordingly. The code in this one field that everything is relative to is how you position all of your content into one spot. Add an optional letter-sized template by exporting Word or InDesign template documents to PDF-- this makes the coordinate positioning in the code much easier.

kumkum29,
Did you check the box that says "bypass PHP eval"? The newest versions of Views PDF include this check box as a safety feature.

Hello,

Firstly thank you for your answers.

I tried to use the rc1 version, but I get a blank page when creating the pdf.
Now, I use the new version 7.x-1.3.
I have assembled the fields on a single field (address field) and rewrite output of this field. It's ok.
But if I copy the code from post #40 in the field "before PHP code output", I get a blank page when I created the pdf. In logs i have this error:

PHP Fatal error:  Using $this when not in object context in /srv/data/web/vhosts/www.mysite.com/htdocs/modules/php/php.module(80) : eval()'d code on line 2

If I checked "Use the PHP eval function instead php_eval" option I get a new error : "File not found / in http://www.mysite.com/users/pdf." (users/pdf is my path in pdf page). In logs I get a new error :
PHP Parse error:  syntax error, unexpected '<' in /srv/data/web/vhosts/www.mysite.com/htdocs/sites/all/modules/views_pdf/views_pdf_template.php(499) : eval()'d code on line 1

These explanations can help you to find a solution?
Thanks for your help ;)

PS I'm on php 5.4

I think you're on the right track.

PHP Parse error: syntax error, unexpected '<' in

I'm guessing you're using the <?php tags from #40? You must leave out those PHP tags.

Hello Vegansupreme,

I have delete <?php tag in field. Now I haven't error.
But all the fields are positioned at the top left of the pdf. (image).

Do you have an idea to position the fields?
I missed a step?

Thanks.

Are you positioning relative to page?

Hello,

In the settings of my field I have "position relative to page".
When I generates a pdf with php code (#40), the field is positioned at the top left of the page. If I do not put the php code, the field is positioned with margins included in "PDF Page: PDF Page Options".

Thanks.

I need more information to troubleshoot. Can you export the view, or copy paste your settings? There are a lot of things that could go wrong, and they're not always obvious. It's possible there's a problem with 7.x-1.3. I believe I've tested it and the positioning worked, but it's not what I use in production. The RC1 version definitely works for positioning—there's no checkbox to bypass php_eval.

Hi team,

My fields are "contact id" and "calendar date". my submission are as follows:
sid1 = contact1 , nov 1
sid2 = contact1, nov 3
sid3 = contact2, nov 1

what i would like to have is the following:
contact id Nov1 Nov 2 Nov 3
contactid1 x x
contactid2 x

to do this i would need to change the $y to +1 only when $content is not equal to the previous $content.
how do i do that?
thank you for reading

Cousimo,
Yes, I think this is possible. I can't test it today, but maybe something like this:

$this->record++;
if ($this->mydate !== $content) {
  $x++;
}
$this->mydate = $content;
$content='x';

Of course this is only part of what you would need, and I don't know if it'll work, but hopefully it'll point you in the right direction :-)

Vegansupreme,

IT WORKED GREAT, but new challenge :-0

this is the code i used and every time the contact id changes it goes onto a new line.

$this->record++;
if ($this->mydate !== $content) {
  $x=$x;
}
else { $y=$y-1 ;}
$this->mydate = $content;
$content='x';

CHALLENGE: How do i now get it to page break after 5 contact id changes. we cant do 'records' because each contact id can have multiple records hence multiple contact id records of the same id.

is there a variable that doesn't get cleared out, if so. we can add that to the mydate !== $contet statement where $changecount = $changecount +1; then i can have a statment if changecount =5 break.

I was playing around a little, i noticed that you can have any variable set up by using $this->, thank you vegan.

this is what i have so far:

$this->record++;
if ($this->mydate !== $content) {
  $this->rcount = $this->rcount +1;
}
else { $this->rcount = $this->rcount ;}
$this->mydate = $content;
$content='x' . $this->rcount;

it does add up the amount of changes from contact to contact, but now i have several records with the same rcount. if i do a page break after rcont=3 .. if i have serveral records with that same number it will break for all of them. is there a way to break on the last record that have rcount =3?
thanks for all your help

Cousimo,
One way to trigger a page break would be to adjust the margins, especially the bottom margin, so that when you get to 5 rows, it reaches the bottom margin and it will automatically add a new page.

Otherwise, if you want to do it in code, you would probably make a contact change counter on the contact id field.

Maybe something like this

if ($content !== $this->previouscontent) {
   $this->contactcounter++;
}
if ($this->contactcounter == 5) {  //you might need to adjust this to '> 4 or == 4'
   $this->contactcounter=0;
   $this->AddPage();
}
$this->previouscontent = $content;

thanks for all your help

it works partially,

If i have the following:
contact id 1
contact id 1
contact id 1
contact id 2
contact id 2 -> this is where it breaks
contact id 3

and if I asked it to break after contact id 2 it breaks on the second record of contact id 2

solved

I had the code reversed
($content !== $this->previouscontent)

i had $this->previouscontent !== $content
works now
thank you

Awesome job vegansupreme and cousimo!

Guys if you're hacking the module, please submit some patch. I'll review it and see if I can push it to the current used version.

I haven't touched the module.. its all php code within the view

oh! cool cousimo, I didn't get where you actually use this code. Good to know :) hehe

Issue summary:View changes

Hello Vegansupreme,

after several days / tests on my view I have still the problem: all the fields are positioned at the top left of pdf.
For test, I have created a basic view with only a field (title). I insert the code (#40) in PHP Code Before Output/rendered setttings of my field. My field have a relative position to page (left / top).
I have exported the code of my view:

$view = new view();
$view->name = 'test';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'test';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['submit_button'] = 'Appliquer';
$handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Réinitialiser';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['expose']['items_per_page_options_all_label'] = '- Tout -';
$handler->display->display_options['pager']['options']['tags']['first'] = '« premier';
$handler->display->display_options['pager']['options']['tags']['previous'] = '‹ précédent';
$handler->display->display_options['pager']['options']['tags']['next'] = 'suivant ›';
$handler->display->display_options['pager']['options']['tags']['last'] = 'dernier »';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Champ: Contenu: Titre */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Contenu: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Contenu: Publié */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Display: PDF Page */
$handler = $view->new_display('pdf', 'PDF Page', 'pdf_1');
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['style_plugin'] = 'pdf_unformatted';
$handler->display->display_options['row_plugin'] = 'pdf_fields';
$handler->display->display_options['row_options']['formats'] = array(
  'title' => array(
    'position' => array(
      'object' => 'page',
      'corner' => 'top_left',
      'x' => '',
      'y' => '',
      'width' => '',
      'height' => '',
    ),
    'text' => array(
      'font_size' => '',
      'font_family' => 'default',
      'font_style' => array(
        'b' => 0,
        'i' => 0,
        'u' => 0,
        'd' => 0,
        'o' => 0,
      ),
      'align' => NULL,
      'hyphenate' => NULL,
      'color' => '',
    ),
    'render' => array(
      'is_html' => 1,
      'minimal_space' => '1',
      'eval_before' => '$this->record++;
$initr=$this->record;
//set top margin
$topmargin=1.3;
// Change this number to the number of items per page
$r=($initr % 6);
if ($r==0) {
// Also change this to items per page
$r=6;
}
    //column 1
    if (($r % 2) == 1) {
    $x=.27;
    $y=((floor($r/2)+1)*$h)-($h-$topmargin);
}
    //column 2
    if (($r % 2) == 0) {
    $x=4.27;
    $y=((floor($r/2)+1)*$h)-((2*$h)-$topmargin);
}
if ($r == 1 && $initr != 1) {
$this->checkPageBreak($this->PageBreakTrigger + 1);
}',
      'bypass_eval_before' => 1,
      'eval_after' => '',
      'bypass_eval_after' => 0,
    ),
  ),
);
$handler->display->display_options['row_options']['leading_template'] = '0';
$handler->display->display_options['row_options']['template'] = '0';
$handler->display->display_options['row_options']['succeed_template'] = '0';
$handler->display->display_options['path'] = 'test';
$translatables['test'] = array(
  t('Master'),
  t('more'),
  t('Appliquer'),
  t('Réinitialiser'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- Tout -'),
  t('Offset'),
  t('« premier'),
  t('‹ précédent'),
  t('suivant ›'),
  t('dernier »'),
  t('PDF Page'),
);

Thanks for your help.

Okay, your PHP code is technically fine. In the code I posted, I used inches for the measurement under PDF Page Settings. You used millimeters—these are default, and they can still work, you just have to consider your $x values, in mm are very small. If you change $x=4.27; to $x=108; you should start to see two columns. Or change measurements to inches, whichever you prefer. However, this doesn't explain why they aren't moving down (Y axis). The answer is the $h variable. I may have left this part out of the earlier explanations, but you need some value in Height position settings for the field—Or alternatively, you could specify in code $h=.5; (inches) or $h=13; (mm)

These values are just examples, please adjust to fit you needs.

Hello Vegansupreme,

Thanks, Thanks,Thanks, Thanks,Thanks, Thanks, Thanks, Thanks, thanks....
I modified the code with the mm values ​​and defined positions and margins. It's OK.
I have inserted a new $h value to define a space between 2 lines.

I have a last question. I want to transform a field (uppercase). In some posts I see that I must insert in the field "PHP Code Before Output" option: $content = strtoupper($content);
But I have grouped the fields together. How do I proceed to transform one of the fields in uppercase?

Thanks.

Welcome :-)
That's tricky. You might need to break up that single field into more than one field. You can find out more about positioning multiple fields further up in this issue. The biggest thing is to only use $this->record++; in the first field.

Another option might be a variation of #3 in #671400: Is it possible to output the taxonomy term field in lower case?
I have no idea if this would work for Views PDF, but it's only a couple short lines of code.

kumkum29,

This can be accomplished with the Custom Formatters module and the following custom formatter code:

$output = '';
foreach ($variables['#items'] as $item) {
  $output .= strtoupper($item['value']);
}
return $output;

After creating the custom formatter, just select the custom formatter on the field you want to capitalize in Views, like so:

Only local images are allowed.

Hello Ownage,

thanks for your reply.
I have tested your solution with custom formatters module but I gets a link "Edit formatter" with my field (in my output pdf).
In views, I have tested to rewrite my field with several options without success.

How to hide this link "Edit formatter" ?

Thanks.

kumkum29,

Simply disable the "Contextual Links Integration" in the Custom Formatters settings:
@ /admin/structure/formatters/settings

Hello,

I have a new problem using "views pdf" and the code in #40 (see image).

The sixth row is placed on the bottom page.

I use this code in PHP Code Before output:

$this->record++;
$initr=$this->record;
//set top margin
$topmargin=15;
//set height space between 2 rows
$h=34;
// Change this number to the number of items per page
$r=($initr % 6);
if ($r==0) {
// Also change this to items per page
$r=16;
}
    //column 1
    if (($r % 2) == 1) {
    $x=12;
    $y=((floor($r/2)+1)*$h)-($h-$topmargin);
}
    //column 2
    if (($r % 2) == 0) {
    $x=113;
    $y=((floor($r/2)+1)*$h)-((2*$h)-$topmargin);
}
if ($r == 1 && $initr != 1) {
$this->checkPageBreak($this->PageBreakTrigger + 1);
}

Have you an idea to resolve this problem ?

Thanks.

// Change this number to the number of items per page
$r=($initr % 6);

In your case should be:
$r=($initr % 16);

Sorry for that code being confusing. I should have put items per page in only one place. At the time it was just a messy, quick fix. That I wasn't sure would work at all. I'm trying to wrap my mind around the code of this module so I can make a patch.

Hello vegansupreme,

Thank you very much for your help. In fact I had forgotten this option... :(
It is ok now. ;)

Thank you again.

Changing the tag issue because is a bad stuff do tags with # (I learn that this weekend)