When I include a view PDF inside another view PDF, it shows the contents of that view twice.
Steps to duplicate:

  1. create and save a View PDF Page displaying 10 node titles
  2. create another view PDF page
  3. change items per page to 1
  4. add field: View: include view, and select the previous view
  5. save view
  6. when viewing the final PDF, the titles from the included view appear twice. (1-10, then 1-10)

I haven't been able to figure out what's happening, but commit 547dc6f seems to work fine, while commit b747ea7 has this problem.


yenidem’s picture

I have same problem, I use this useful module when I creating invoices with Commerce module. The line items have to be included from another views. There are 2 views, one of them creates pdf only line items and main view have another fields (letterhead, date etc..) and have "Insert View" field. The insert view field showing duplicated.

adri4n’s picture

Same problem here with latest dev from Nov 18.
Did you find any way to solve it?

killua99’s picture

If someone can digg more in this issue.

Currently I'm full focus on the v 2. But if this issue present some patch, I can test it and see if this solve the problem.

If you use normal display, like block o page when you add a field: View: include view it duplicate as well the content?

adri4n’s picture

I reproduced the same content in a page view including another page, there the included view only appears once.
I'll try to debug the next days, trying to find the root cause. Just thought, maybe someone has found a workaround

killua99’s picture

Ok thanks

vegansupreme’s picture

I wish I could help, but this looks over my head. The problem may have started with this issue
#1313404: Grouping field doesn't work in the PDF
the phrase "dramatic refactoring" was thrown around a bit.

@adri4n, as for a workaround, I'm just using an earlier version that doesn't have this problem. If you checkout 547dc6f, it doesn't have this problem.

inno81’s picture

Issue summary:View changes

I have the same issue, but cannot revert to earlier version because other problems appears (positioning of included view).

killua99’s picture

Status:Active» Needs work

So I have to take a look the diff in between these patchs

Tranko’s picture

Same problem here with latest dev from Nov 18.

TBarina’s picture

Same problem here. I'm using version = "7.x-1.4+0-dev"

Is there any patch in progress?

vegansupreme’s picture

I've tried to figure this out but haven't been able to so far.
Hopefully I can hack on it again this week. Any suggestions welcome!

TBarina’s picture

Hi, I agree with #6. The problem is surely relating to grouping and I think it is due to the way Views manages things.
I don't know the php code of Views (it's too big to deal with for me). And I've only been playing with Views_PDF for a couple of days so far, hence I'm not an expert of this module as well.

What I'd like to do is to help maintainers of Views_PDF to patch this issue. I think Views_PDF is a great module and should be considered necessary to fill the gap between Drupal as a simple CMS and Drupal as a real application framework.

What we are trying to fix is that when we include a PDF table view inside a PDF unformatted view display we get a duplicated output of the PDF table, like this:

1) The duplicated output of the included PDF table (of which we would like to get rid)
2) Fields coming from the PDF page unformatted
(that should form the header part of the final desired output)
3) The included PDF table
(that should form the details part of the final desired output)

In modules/views/plugins/views_plugin_style.inc we find the function render() at line 314 which is:

function render() {

// Group the rows according to the grouping instructions, if specified.
$sets = $this->render_grouping(

return $this->render_grouping_sets($sets);

- render_grouping [line 430], in turn, calls render_fields, which causes the duplication of the PDF table [see 1) above].

- render_grouping_sets($sets) renders both the fields form the PDF unformatted [see 2) above] and, once again, the fields from the included PDF table [see 3) above].

Since we cannot change Views, it seems like we have to find a way to prevent that subsequent functions calls, starting from render_grouping, render the undesired output.

I've come up with a solution for which I attach a patching file here.

Probably not a definitive solution but maybe a step forward.

Let me know

TBarina’s picture

Status:Needs work» Needs review
vegansupreme’s picture

With the patch in #12, I'm getting errors when I try to create a PDF table, also the table won't render. Could be something on my end. I think we're on the right track!

TBarina’s picture

new3.66 KB

I noticed it today as well. Unfortunally patches in #12 works only partially: I've discovered that there are further nested function calls that generate undesired output.
In fact the patch created for managing "grouping" creates multiple recurring and nested function calls that invoke row rendering and thus improperly generate unwanted output to the final pdf.

As far as PDF table not rendering when used alone it's my fault: I didn't test thas use case focusing mainly on the PDF page including a PDF table.

Patch included here should fix that as well. It replaces patch in #12 and must be applied to a clean 7.x-1.x-dev version of Views PDF.

I've left the entire Views PDF module logic untouched: I've just tried to introduce a way to switch on and off the actual rendering to the final PDF in order to suppress output when not appropriate.

Hope this may solve this issue a little better but it needs review by maintainers.


vegansupreme’s picture

#15 seems to be working after some simple testing. It works for included table PDF, but not for included unformatted PDF. I think you've got the right code TBarina, we just need to copy it to the right place for unformatted. If you're willing to do that, it'd be great, if not I can do it, but it will take a while.

PhilY’s picture

@Vegansupreme: I hope you will find time to adapt the code for the unformatted PDF ;-)

vegansupreme’s picture

I hope so too! It's trickier than I thought :-\

vegansupreme’s picture

I think I've got something that works! I've only done limited testing. I haven't yet dared to see if grouping sets still work!
#1313404: Grouping field doesn't work in the PDF

vegansupreme’s picture

Status:Needs review» Needs work

This patch seems to change the behavior of grouping fields, that is, it doesn't render as many of them as it should.

stevieb’s picture

the patch in #19 removes duplicates on a fresh install


vegansupreme’s picture

Here's a new patch that only fixes unformatted, but does not cause regression of grouping fields.

vegansupreme’s picture

Status:Needs work» Needs review
new2.6 KB

Okay I think I've got a patch that fixes duplication of both tables and unformatted, when either is included in an unformatted PDF. It also doesn't break the existing grouping functionality, as far as I can tell.

vegansupreme’s picture

new2.6 KB

Ah! I patched it backwards! Rerolled patch attached!

vegansupreme’s picture

Status:Needs review» Needs work

Ugh! Previous patch does not allow me to include more than one view! Including one view works fine, but any subsequent included views don't show up!

alibama’s picture

just tested #24 with one attached view - it didn't seem to work... going to test the other patch you recently released

alibama’s picture

ok - tested again - now it keeps getting worse... first time i tested it there were 4 pages, then 6, then 8.... it's just adding more and more crud...

vegansupreme’s picture

@alibama, this issue is only for include view, not append view. There exists another issue and patch for append view. #2130343: Views Append displays external pdf files multiple times and erratically
The patch in that issue is not prefect, but it seems to prevent duplication.

killua99’s picture

Assigned:Unassigned» vegansupreme
+++ b/views_pdf_plugin_style_unformatted.inc
@@ -52,11 +55,17 @@ class views_pdf_plugin_style_unformatted extends views_plugin_style {
+        if (isset($this->view->pdf->render_flag)) {
+          } else {
+          $this->view->pdf->render_flag = array();
+          if ($this->uses_row_plugin()) {
+              foreach ($set['rows'] as $index => $row) {
+                $this->view->row_index = $index;
+                if (!isset($this->view->pdf->render_flag[$index])) {
+                  $set['rows'][$index] = $this->row_plugin->render($row);
+                  $this->view->pdf->render_flag[$index] = FALSE;
+              }
+            }

Change this.

vegansupreme’s picture

Using empty instead of isset?
I'm having to rethink the whole approach of this patch. The problem was, the included view was repeating 3 times. So this patch was only allowing the view to be rendered once. The problem is, when using eval_before on the included field, that PHP doesn't seem to be executed until the 3rd time. I still haven't figured out exactly why the view was rendering 3 times to begin with—other than it seemed to have something to do with grouping fields. So my patches were just fixing the symptom, not addressing the root problem.

killua99’s picture

No well ...


+ if (isset($this->view->pdf->render_flag)) {
+ } else {

That if for nothing? and wrapping inside the else?

vlad897’s picture

I am not 100% sure, but I believe included view content repeats only when included view Format is set to PDF unformatted, or PDF TABLE, I think module renders the same content twice because of it. When view has a format mentioned earlier when it is displayed it is pdf format, so if you include it (already pdf formatted) in other view with pdf format it is rendered twice.
I recreated and included "Commerce Pdf Invoice Line Items" view without using pdf format and it looks fine, no double content.

Toki’s picture

Hi vlad897,
I am still struggling with this display issue (and thus still using Views PDF 7.x1.0 instead of 1.4) so your answer is really interesting for me.
Could you specify how you manage to include the "Commerce PDF Invoice Line Items" view without any PDF format since only two options are available (PDF unformatted or PDF Table)?

vlad897’s picture

new66.31 KB

Hi, I included Untitled.png screenshot, basically just create a new block view with fields display, add contextual filter and select 3rd url param as order id, add required relations and fields. Then u can include this view instead default pdf included line items view in "Commerce Invoice" view. This is how it is working fine to me without any issue.

Toki’s picture

Thanks for the details.
Actually, you could build a block without all theses relationships by using Show : Commerce Line item when creating the view. Thus, you only need the contextual filter Order ID from the URL, 3rd component, and it works (no more double display). I had to configure "Hide contextual links" on Yes to avoid the Edit view tab above the line items table. Then, it's only a matter of CSS to get something nice!
Anyway, thank you for your idea.

FatherShawn’s picture

new26.24 KB

I have this issue as well. The parent view is of the 960x720 image and the included view is another pdf display.

the first occurrence on the page is extraneous. The second is as positioned by field settings.

Reading the comments above I'll try formatting in html and not as another view pdf

kevster’s picture

Ive tried patches from #22 and #24 for the unformatted PDF and Im now only getting the 2nd view showing in the PDF - seems to be discarding the 1st view I include (im pullign in 2 views using include view). Without the patch I get both views but the 1st view has the 2nd view superimposed (so duplicating the 2nd view).