Plots in PDF being divided between two pages

This might sound funny but i am new to python :smiley:
What I’m trying to do is to download a pdf form that has 2 datagrids and a plot
The problem is that at some point the plot is divided between two pages as seen in the image

I just need to know how to make the plot element of the pdf to be on a page on its own or if there is an other solution you could suggest i would really appreciate it.

Code Sample:

@anvil.server.callable
  def create_pdf(dg_1, dg_2, plot):
  pdf = anvil.pdf.render_form('Form1', dg_1, dg_2, plot)
  return pdf()

IN FORM: all is working perfectly . the download button and the init for the pdf  /form thing are on point no problem there

Is something not clear or needs more clarification ? Or is the task not related to code ? Can some one please help :worried:

Everyone helping on here is doing so voluntarily in their own time. If nobody is answering, it’s because they don’t know the answer or don’t have time to look into it.

If you need help urgently, I suggest you consider paying for a support plan.

Hi @khouryman,
welcome tho the Forum!

I recently had some similar issues:

Check out the app in the solution post, you should be able to us that for your problem.
Essentially create a custom component which includes a page break.

Greetings, Mark

I’ve created a custom Html component to do this in the past.
You can change the html to something like this:

<hr class="page-break"/>
<style>
  .page-break {
    border: 0.5px solid grey;
  }
  @media print {
    .page-break {
      height: 0;
      border: none;
      page-break-after: always;
      margin: 0 
    }
  }
</style>

Add this to the form you want to print just above your plot.
It will show a horizontal line in the design view.
But it shouldn’t be there when you print.

Anvil Docs | Custom Components

3 Likes

Oh, I think I know a library of ‘Extra’ components that might make its way into!

2 Likes

It worked . Thank you :smiley:

This is EXCELLENT - I’m about to put this in 8 different places. Thanks!

Hmm. I added this to my component and it didn’t work as expected. I’m not seeing those page breaks where I’m dropping that custom component. Any idea what I’m missing here?

Thanks!

https://anvil.works/build#clone:DK7MA3WHZ2X2KDDH=PGLQUMF3FAF5CKGYPYXVNV44

printing html is always tricky - here’s a solution that seems to work better

<div class="break-container" style="overflow: hidden;">
  <div style="page-break-after:always;"/>
  <div style="margin-top: -55px;"/>
</div>

<style>
  .break-container {
    border: 1px solid grey;
  }
  @media print {
    .break-container {
      border: none;
    }
  }
</style>

You may need to adjust the margin-top property. -55px worked for me.
If you’re debugging removing the border: none will help to see what’s going on when you print.

1 Like