how to display an image from second page in dom pdf? - php

I am new to dom pdf. I am loading footer image in all the pdf pages using DOM pdf.and banner image only in first page of pdf.
From second page i want to display another image in header part.
How can i achieve this?

The header and footer you use is DOM PDF are on every page the same. If you want to have different images on each page you can use your own css to archieve this.
If you only want page 1 to be different, you need to take a look [here].(dompdf: How to add header on every page except first?). That question is already treated.

Related

Hide header tags in WKHTMLPDF TOC

I'm trying to generate a PDF Catalog including a table of contens with wkhtmltopdf.
To achieve this I create a toc dump, and read it's content through PHP. So long - no problem...
Now I have some headers, that have to be display inside the TOC, but not in the rendered PDF. So I set the mentioned headers to "display: none". If I do so, they don't appear in the TOC.
I need a possibility to render some headers into the TOC without displaying them in the PDF document.
This can be achieved using --xsl-style-sheet option and using a customized XSL. You can add any content to it.

How to render HTML and graphics on top of existing PDF using wkhtmltopdf

I have these inputs:
an HTML page
an Existing PDF, and some more HTML/stuff I want to draw on top of that PDF (text, html, circles)
an HTML Page
I want to render a 3-page PDF, and have them all be displayed on in a single PDF.
In other words, my question is How do I use an existing PDF as a template for more input
Can this be done from PHP and how?
Unfortunately, with wkhtmltopdf, you can't modify/edit an existing PDF.
With a custom XSL using this code, you could easily do it.
http://www.cloudformatter.com/CSS2Pdf.APIDoc.Usage
The backend rendering engine is XSL FO based which supports injecting a PDF as a background image.
So easy, I did you a sample. Go to this page:
http://www.cloudformatter.com/CSS2Pdf.CustomTipsTricks.BackgroundImages
Click the Open-> PDF button.
The "Top Secret" PDF is injected as a background, the HTML overlayed on top. You can use this solution to combine your HTML, PDF and HTML+PDF in any way you wish.
In fact, with HTML, this Javascript and a little customization you could have a document that was:
start document
format HTML div
format HTML div with this PDF background
format another HTML div
inject this entire PDF
format another HTML div with a different PDF background
inject a different entire PDF
...
end document

TCPDF cuts text when the page end / footer is reached?

I am using TCPDF to create PDFs with PHP. Everything works very nice, except when text would be placed where the footer resides. In my example, the text is shown only half, the rest is behind the footer. Is there an option which defines to put it on the next page?
Besides that, my PDFs differ from print to print, some have 1 page, some 2 or more. Is it possible to say that a specific text should only be placed on the page when it fits completely? if not, it should go to the next page.
I already have this in my code, but it doesnt help, the text is still cut.
$pdf->SetAutoPageBreak(true, 25);
I am creating the PDF by creating a huge HTML string and print that to the PDF using writeHTML. This is how it looks, the bold text on top should go to the next page, its hidden behind the footer.
Thanks!

dompdf making the header and the footer "solid"

Hi i'm saving some html stuff with .pdf extension using dompdf.
The problem is that i made an header and a footer(using the dompdf script) and it looks fine as long as content does not fill the whole page.
The thing is that the header and the footer generated act like an absolute positioned div and the page content goes under them instead of jumping to the next page once the footer is reached.
Now, i know they are added after the html and it's normal that the text goes under but is there anyway(maybe with some kind of html/css solution) to make a solid div that, once "reached" by the div above makes it jump to the next free space available on the page?
Any work around?
Thanks in advance
I solved the problem giving the body tag a margin top equal to the header height and a margin bottom equal to the footer height this automatically applies to every page.

Display user created invalid HTML content without messing up the page

I have a website that allows a user to save text content and then display it as is.
The user can use HTML tags to create his data the way he wants - design, fonts, divs, tables and so on...
To display the data been saved I direct the user to a page with a header/footer of my own and he's data in the middle. The problem happens when the user has some invalid HTML tags or un-closed ones, then it interfere with my own header/footer HTML and the whole page gets messed up.
Is there a way to encapsulate the user's data so it would not harm the page?
You can try to load it in iframe. Haven't tested it, but I think it should work.
you can use iframe with fixed width and height.
The Iframe suggestion are good but was not enough. Because i wanted it to show like it was a part of the page and I didn't know what is the length and size of the user data, the solution i've used is like that:
Created a page that shows the user data alone. Opened it in an iframe which was located between my main page header and footer.
Now for the trick - for when the user has a lot of data, to avoid scroll bars in the middle of the page i have used this script on the iframe onload event:
function setHeight()
{
//get page height
var the_height=
document.getElementById('userFrame').contentWindow.document.body.scrollHeight;
//set iframe height
document.getElementById('userFrame').height=the_height;
}
This way, when the page loads, the iframe height will change according to it's size, pushing the footer to the bottom.
After that just needed to set the iframe border to "none" and the page looks normal.

Categories