is there any PHP code (preferred, but doesn’t have to be) out there that can convert an html page to a PDF? Like ones you can google do? but it needs to be directly on site. any help?
Well, first, you would have to rip off the page into text. This is easy to do.
But, then, you have to format it which can be tricky.
Next, you would have to send the formatted text to a PDF printer or another text-to-PDF utility.
This would not be hard to do.
Adobe has a utility that will allow you to create PDF from text. Here is a link to an explaination of this:
http://www.sitepoint.com/generate-pdfs-php/
If you need to learn how to get the text, you can use Javascript’s Document options (DOM) or create a webpage scraper to load it into a variable…
Hope that helps…
is there any out there that just copy the page and make it a pdf? no positioning or editing size or anything?
Well, I can not locate anything that would solve your idea online.
I did have a thought that might help. If you were talking about HTML code, it would be a pain to sort out formatting it. If you are talking about a PDF of the “RENDERED” output of a browser, that might be easier. You could set up a PDF printer. (There are tons of those around.) And, then print the page to the PDF printer.
This might work. I will test it tonight and see if a PDF printer will print the “RENDERED” output.
Sounds interesting if it does…
Searls03,
I found one way that seems to work. I got curious, so dropped my work and experimented for you. You can install a free PDF printer. I tried CutePDF and it worked well for my tests. It will take a webpage and turn it into a PDF. You just have to PRINT the screen. It rendered it nicely. I did find that on my IE, I had to go into InternetOptions and AdvancedOoptions and set it to print the backgrounds. Otherwise the background colors and graphics were missing. This actually could be a handy option because it is a little easier to read if you are going for that type of output.
Now that it works that way, I am not sure how to handle it from a webpage. I suppose you can just use PHP or Javascript to open the page and print it to the correct printer. Not sure if that is possible with website code. Or just write a VB.NET program to load the page and print it to the PDF printer.
Anyway, not sure why you wanted this option, but, perhaps this info will help… Good luck…