Re: How to set a "no-header" tag in html for use in page_script()

瀏覽次數:763 次
跳到第一則未讀訊息

BrianS

未讀,
2013年1月17日 上午9:46:182013/1/17
收件者:dom...@googlegroups.com
Detecting the current page contents may be possible, but I'd have to research exactly what you can do at this level. An easier method would be if you could inject some inline script in your generated document. After the main content and before the attachments you could add something like $GLOBALS['attachments'] = true; and then add a check on the status of this variable to your conditional.

<script type="text/php">
if (isset($pdf) ) {
  $pdf->page_script('
    if ( $PAGE_COUNT > 10 && $PAGE_NUM == 1) {
      //front page footer
    }elseif ($GLOBALS['attachments']) {
      //attachments actions
    }else{
      //other pages' header and footer
    }
  ');
}
</script>

Of course, don't forget to initialize the variable to false at the top of the document.


On Thursday, January 17, 2013 5:09:42 AM UTC-5, David Forsberg wrote:
Hi,

I am using dompdf to generate reports which sometimes has a front page, and sometimes has some attachments. The main content has a header and a footer, but the front page and the attachments (the last 3 to 5 pages of the pdf) should not contain header and footer. I'm placing the header and footer with a  inline php page_script(), like this:

<script type="text/php"> 
  if (isset($pdf) ) { 
$pdf->page_script('
if ( $PAGE_COUNT > 10 && $PAGE_NUM == 1) {
//front page footer
}else{
//other pages' header and footer
}
');
  }
</script>

The whole report is built by a database engine which outputs it all as a temporary html.txt-file which is then read into DOMPDF.

Now, to recognize the front page I just have to check if the page number is = 1. If any attachments are added (which are comprised of 1000px-height jpg images, each on their own page)  Does anyone have an idea for how to identify these "attachment"-pages and get DOMPDF to not render a header and footer on those pages? Or is there any way I could check within the page_script()-script whether the current page contains only an image (or perhaps an image with a specific class or identifier)?

Thanks for any help,
David

BrianS

未讀,
2013年3月10日 晚上11:15:562013/3/10
收件者:dom...@googlegroups.com
Looking back at this there is one problem. If you declare $GLOBALS['attachments'] using normal inline script it will always be set to whatever the last value when the page_script() is run. This is because inline script is executed as the document is parsed, while page_script() is stored during document parsing and subsequently run on every page of the document after the entire document has been parsed. So instead of true you should indicate what page the attachments start on. Then this modified code logic should work.

<script type="text/php">
if (isset($pdf) ) {
  $pdf->page_script('
    if ( $PAGE_COUNT > 10 && $PAGE_NUM == 1) {
      //front page footer
    } elseif ($PAGE_NUM == $GLOBALS['attachments']) {

      //attachments actions
    } else {
      //other pages' header and footer
    }
  ');
}
</script>


I hope that works better for you.

FYI, the nightly download is currently out of date. It still pulls from our old SVN repository, which is behind by a bit. To try out the latest code head over to our github project pages and click on the "zip" button near the top of the page. It's a bit inconvenient because you have to download php-font-lib separately.

dompdf
https://github.com/dompdf/dompdf

php-font-lib
https://github.com/PhenX/php-font-lib

On Sunday, March 10, 2013 6:22:14 PM UTC-4, Sean Kelly wrote:
Hi Brian, please forgive me for jumping in on an older ticket but I wonder if you have a moment to please clarify your explanation above?

When I declare $GLOBALS['attachments'] "true" near the bottom of my page-to-be-printed, it is applied to all of my pdf pages instead of just the last ones with attachments. 

I know that my conditional code inside page_script() is working by setting the attachments to false and headers/footers are inserted into all of my pdf pages. 

I grabbed the nightly build from http://eclecticgeek.com/dompdf/ just a short while ago and unfortunately it didn't help.

In my page, I have three blocks of <script type="text/php"> code for Dompdf to parse.
1) Page numbers on all pages. I also set $GLOBALS['attachments'] to false in this block at the top of my page.
2) page_script() code with conditional statement as in your example.
3) A small block just before I add my file attachments that sets the $GLOBALS['attachments'] variable to true.

Any suggestions you might have would be greatly appreciated.

Regards,
Sean
回覆所有人
回覆作者
轉寄
0 則新訊息