Recommend this page to a friend! |
Convert HTML to PDF PHP Library | > | All threads | > | Print an iframe | > | (Un) Subscribe thread alerts |
|
1 - 10 | 11 - 11 |
Lisa Baird - 2017-08-01 20:47:15
What code do I use to print data in an iFrame? Also, how do I define what should be a header and what should be a footer. I want the header and footer to be on each page when there is multiple pages. How do I do this?
Dave Smith - 2017-08-02 06:47:28 - In reply to message 1 from Lisa Baird
You would write a script that instantiates the class, sets the parameters, and then displays the pdf. You use that file for the src attribute of the iframe. You can use the example file included as a guide.
The reference.txt file lists the parameters available. It sounds like you want the header_text and footer_text params. You can also use replacement tags for current page number, total pages, etc... which can be found at the end of the file. Dave
Lisa Baird - 2017-08-02 14:26:49 - In reply to message 2 from Dave Smith
Thanks for your reply, but I seem to have a mental block on how this works, maybe I've missed some detail; or maybe I'm making it harder than it is.
I didn't find an example that was useful. Would this psuedocode be accurate? 1. Header, in the iframe to be printed: <?php $my_header= '<div class="firstdiv">some stuff</div><div calss="second div">some other stuff</div>'; ?> <div class="no_print"><?php echo $my_header; ?></div> //So my header is displayed on the page, but not printed twice 2. Footer, in the iframe to be printed: $my_footer='<table class="outerFooter"><tr><td>some stuff</td><td>some more stuff</td></tr></table>'; <div class="no_print"><?php echo $my_footer; ?></div> 3. Set it up & call it, in the page that contains the iframe: include('../html2pdf.class.php'); $h2pdf = new html2pdf(); $h2pdf->setParam('document_url','https://www.mydomain.com/iframePage.php','css_url', 'path.print-css','document_name', 'My Printed Document', 'header_text', $my_header, 'footer_text', $my_footer); $h2pdf->convertHTML(); $h2pdf->displayCapture(); Thanks!
Dave Smith - 2017-08-02 19:37:09 - In reply to message 3 from Lisa Baird
1. Your inline frame included on your webpage:
<iframe src="https://www.mydomain.com/iframePage.php"></iframe> 2. Your html to be converted in a file named iframepage.html: <html> <head> <link rel="stylesheet" type="text/css" href="iframpage.css"> </head> <body> <div class="firstdiv">some stuff</div><div calss="second div">some other stuff</div><!-- header only printed once --> <div>Some content here</div> <table class="outerFooter"><tr><td>some stuff</td><td>some more stuff</td></tr></table><!-- footer only printed once --> </body> </html> 3. Your source in the iframePage.php file: <?php include('../html2pdf.class.php'); $h2pdf = new html2pdf(); $my_header = 'Include me at the top of each page'; $my_footer = 'Include me at the bottom of each page'; $h2pdf->setParam('document_url','https://www.mydomain.com/iframepage.html'); $h2pdf->setParam('document_name','My Printed Document'); $h2pdf->setParam('header_text',$my_header); $h2pdf->setParam('footer_text',$my_footer); $h2pdf->convertHTML(); $h2pdf->displayCapture(); ?> Basically your inline frame includes the source code that sends instructions to the API to convert your html file into a pdf document and display it. Note that each parameter is set individually. In this example we are converting static html, if you need it to be dynamic then you would have a php file that returns the properly formatted markup, of course you would need to name it something different to avoid the name collision. I kept your original case for the filename, however I would recommend that you only use lowercase when naming files or directories. Dave
Lisa Baird - 2017-08-02 21:09:58 - In reply to message 4 from Dave Smith
Thanks for your response, I was definitely setting the parameters wrong; it makes sense now.
I have the html being generated and am defining the repeating header. I have to work on the css, but it prints well, except that the header doesn't repeat on each page. We are printing a very long table, will this handle pagination and, is pagination automatic? Here's the two parameters (for your reference, in case I'm doing it all wrong): $h2pdf->setParam('document_url', 'proforma_doc.html'); $h2pdf->setParam('header_url', 'proforma_header.html'); proforma_doc.html is a complete html page. proforma_header is just a 2 column table that I would like to repeat at the top of each page. Thanks!
Dave Smith - 2017-08-03 10:32:29 - In reply to message 5 from Lisa Baird
What is confusing me is that you indicate the header is not showing up on each page and then ask if there is pagination. Pagination is automatic based on your paper size (8.5x11 aka letter is the default), margins and the space required for the header and footer.
Is the header showing up at all and are you not seeing pages? I am pretty sure you need to provide the full url in your params, if it is working with just the file name then that is a new one for me. If you are having problems seeing your header, take a look at the header_html param, where you can just define the table in a variable inside the script and pass that. This method will also keep the API from having to visit your site twice. Dave
Lisa Baird - 2017-08-03 14:26:15 - In reply to message 6 from Dave Smith
Hi Dave:
I am using the full URL for paths, I just couldn't give it to you. The question regarding pagination: Mostly I was wondering if html2pdf is able to break a long, multi-page table of data in the middle and add a header to top of the next page. If it can't then that is my problem, and I need to format my data differently; otherwise, continue reading. The header is showing up at the top of the first page only, not at the top of each page. The contents of the html at the header_url is the html of the header table only. (no doctype, body tags, etc) <div><table><th>stuff</th><td><tr>stuff</tr></td></table></div> Thank you for your responses and your time. Lisa
Dave Smith - 2017-08-03 18:51:14 - In reply to message 7 from Lisa Baird
I would think it would properly add the header on each page break, but since it is not...
I found a comment that indicated using the <thead> element did display it on each page. So try getting rid of the header_url html and adding it to the table inside a <thead> tag. If you are not seeing it, you may need to set the margin_top attribute (which defaults to 10) to a larger value so that there is space available. It was also recommended that you add the following css for better page breaking... td, tr { page-break-inside: avoid; } Dave
Lisa Baird - 2017-08-04 21:53:31 - In reply to message 8 from Dave Smith
First, can you tell me where you look to find comments and suggestions? I am having troubles finding sources of good information for my purposes.
Getting the header to repeat is hit or miss. I've defined my thead section with embedded tables, one table and it works fine, more than one and it doesn't repeat. Without html2pdf, my header prints at the top of the first page, with html2pdf, my thead prints at the top of each page, but the table lays out over top of it. You wouldn't happen to know of a work-around? Alternatively, do you know of any good way to print (multiple pages some with over two thousand lines of code) with a header and footer at the top of each page, without having to re-write the program? Thanks!
Dave Smith - 2017-08-05 02:20:59 - In reply to message 9 from Lisa Baird
The comment and suggestions I am getting are from core elements built into the API. Since I worked on the API, I have insider knowledge on how it works, however I am bound by a non disclosure agreement to keep the proprietary secrets, secret.
It sounds like your tables may not be properly formatted. Here is the basic table structure... <table> <thead> <tr> <th>Header Row 1 Column 1</th> <th>Header Row 1 Column 2</th> </tr> </thead> <tfoot> <tr> <td colspan="2">Table footer</td> </tr> </tfoot> <tbody> <tr> <td>Row 1 Column 1</td> <td>Row 1 Column 2</td> </tr> <tr> <td>Row 2 Column 1</td> <td>Row 2 Column 2</td> </tr> </tbody> </table> I would try to avoid embedding tables unless you had a subset of tabular data, however that embed would be in the body inside a row and column. I did notice in an earlier post that you had your rows and columns inverted. I assumed that it was just a typo, however a simple mistake like that would certainly cause formatting issues. It is also possible that the embed is not in a column, which would cause it to fall out of the table structure. I am not sure what program you would have to re-write, however if the problem is a formatting issue then the best work-around is to fix the problem. The good news is that it sounds like we are on the right track with the thead showing up on each page, we just need to figure out why the body is laying over it. If it is not a table formatting issue, then try increasing the margin_top param passed to the API. Dave |
1 - 10 | 11 - 11 |
info at phpclasses dot org
.