Welcome, Register for free! or Login below:
EduGeek.net RSS Feeds Register FAQ Members Social Groups User Map Calendar Search Today's Posts Mark Forums Read

Go Back   EduGeek.net Forums > Coding and Web Development > Web Development
Reply
 
LinkBack Thread Tools Search Thread Language
Sponsored Links
Old 15-07-2008, 05:10 PM   #1
 
danIT's Avatar
 
Join Date: Apr 2006
Location: UK
Posts: 484
Thanks: 8
Thanked 6 Times in 5 Posts
Rep Power: 7 danIT is on a distinguished road
Default Convert HTML / CSS to PDF/PS

Im looking for some kind of server based software which will automate the process of converting a HTML/CSS based web page to a PDF file.

The problem i am finding is that many of the scripts - Perl, php etc do not support CSS very well E.g. Floats, inline style and tables

Obviously I could improve/degrade my HTML and CSS but this is not an option.

Does anyone have any idea how i might go about this?

It needs to be an automated process which will allow a bulk job of documents created in HTML/CSS to be converted to PDF on the fly.

...
  Reply With Quote
Old 15-07-2008, 08:12 PM   #2
 
srochford's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 1,100
uk
Thanks: 1
Thanked 113 Times in 98 Posts
Rep Power: 29 srochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to all
Default

Not sure what you want to do this on but if you can use Internet Explorer on Windows then you coudl install PDFCreator as a printer driver and then use a script like the one below (make sure the PDFCreator is set as default printer first)

Basically, it sets a few variables so that the PDF Creator will print without prompting for filenames etc and then it loads each file named in the list at c:\temp\urls.txt (just a plain text file, 1 URL per line). Once the page is loaded it gets printed.

You don't have any control over things like fitting to page etc (although I suspect you could - this is left as an exercise for the reader :-)) but it basically works.

Code:
const OLECMDID_PRINT = 6
const OLECMDEXECOPT_DONTPROMPTUSER = 2
const PRINT_WAITFORCOMPLETION =2
Const HKEY_CURRENT_USER = &H80000001

Initialise
set oShell=createobject("wscript.shell")
set OFSO=createobject("scripting.filesystemobject")
set oFile=ofso.opentextfile("c:\temp\urls.txt")
do while not ofile.atendofstream
  sURL=ofile.readline
  PrintPage sURL
loop
oFile.close

sub PrintPage(sURL)
  Set oIE= CreateObject("InternetExplorer.Application")
  Do While (oIE.Busy)
      Wscript.Sleep 250
  Loop
  oIE.visible=true
  oIE.ToolBar = false
  oIE.StatusBar = false
  oIE.Resizable = false
  oIE.Navigate (sURL)
  Do While (oIE.Busy)
      Wscript.Sleep 250
  Loop
  wscript.sleep 1000 'just so you can see the page
  sFilename=replace(sURL,"/","-")
  sFileName=replace(sURL,":","-")
  oShell.regwrite "HKCU\Software\PDFCreator\Program\AutoSaveFileName",sFileName
  Oie.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, PRINT_WAITFORCOMPLETION,0
  oIe.quit
end sub

Sub Initialise
  Set oReg = GetObject("winmgmts://./root/default:StdRegProv")
  sPath = "Software\PDFCreator\Program"
  lRC=oReg.SetDwordValue(HKEY_CURRENT_USER,sPath,"ShowAnimation",0)
  lRC=oReg.SetDwordValue(HKEY_CURRENT_USER,sPath,"UseAutoSave",1)
  lRC=oReg.SetDwordValue(HKEY_CURRENT_USER,sPath,"UseAutoSaveDirectory",1)
  lRC=oReg.SetStringValue(HKEY_CURRENT_USER,sPath,"AutoSaveDirectory","c:\temp")
  lRC=oReg.SetDwordValue(HKEY_CURRENT_USER,sPath,"AutoSaveStartStandardProgram",0)
end sub
  Reply With Quote
Old 16-07-2008, 02:16 PM   #3
 
danIT's Avatar
 
Join Date: Apr 2006
Location: UK
Posts: 484
Thanks: 8
Thanked 6 Times in 5 Posts
Rep Power: 7 danIT is on a distinguished road
Default

The problem i have is that the pages to be printed are dynamic.

The system is basically a way of recording staff CPD, with a number of sheets attached.

The system produces a HTML/CSS template report based on this data.

I would like 'reviewers' to view the reports on screen but at a certain point in time teacher are not allowed to access the system and make changes, I lock the system at this point. But at the same time I need to output all the reports to PDF on the fly...

So no files names or URLs just data output to a html page...

Help please lol
  Reply With Quote
Old 16-07-2008, 02:36 PM   #4
 
dhicks's Avatar
 
Join Date: Aug 2005
Location: Alton, Hampshire
Posts: 1,385
Thanks: 119
Thanked 92 Times in 87 Posts
Rep Power: 28 dhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to all
Default

Quote:
Originally Posted by danIT View Post
So no files names or URLs just data output to a html page...
Have you tried XSLT:FO, a transforms language for transforming XML into PDF? Have a look at Apache Xalan, see if that is appropriate to what you are trying to do. I assume you've already had a look at the PDF writing library for whatever language you're developing in? The above idea really doesn't sound bad at all - use a browser engine to render your page, then print that rendered page out to a temporary PDF document - you can easily delete that PDF documents again as soon as you've sent it to the user.

--
David Hicks
  Reply With Quote
Old 17-07-2008, 12:48 PM   #5
 
srochford's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 1,100
uk
Thanks: 1
Thanked 113 Times in 98 Posts
Rep Power: 29 srochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to all
Default

Quote:
Originally Posted by danIT View Post
The problem i have is that the pages to be printed are dynamic.

So no files names or URLs just data output to a html page...
Not sure I understand?? How do you look at the pages now? Do they just come up on a screen as part of an application (ie not rendered in a normal browser window)??
  Reply With Quote
Old 21-07-2008, 11:32 AM   #6
 
danIT's Avatar
 
Join Date: Apr 2006
Location: UK
Posts: 484
Thanks: 8
Thanked 6 Times in 5 Posts
Rep Power: 7 danIT is on a distinguished road
Default

Yes they are rendered in a browser window, but dynamically...

E.g the address for every page generated is http://localhost/report.cgi

but the contents of each page is different depending on what users report is selected.
  Reply With Quote
Old 21-07-2008, 01:43 PM   #7
 
dhicks's Avatar
 
Join Date: Aug 2005
Location: Alton, Hampshire
Posts: 1,385
Thanks: 119
Thanked 92 Times in 87 Posts
Rep Power: 28 dhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to all
Default

Quote:
Originally Posted by danIT View Post
E.g the address for every page generated is http://localhost/report.cgi
You get that your CGI script can simply read a PDF document from disk and write it out as its output? You just have to get your CGI script to set the MIME type correctly (er, application/PDF?), then read in the PDF document from a file on the server and write it out as output. You can generate the PDF document however you like - as you seem to be wanting to generate the PDF document from the rendered HTML view of whatever data it its you're showing, I'd reckon the easiest solution is to have a web browser server-side that you automate in some way (AutoIt?) to automatically "print" to an installed PDF document printer (i.e. PDFCreator).

--
David Hicks
  Reply With Quote
Old 21-07-2008, 10:04 PM   #8
 
srochford's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 1,100
uk
Thanks: 1
Thanked 113 Times in 98 Posts
Rep Power: 29 srochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to all
Default

Quote:
Originally Posted by danIT View Post
Yes they are rendered in a browser window, but dynamically...

E.g the address for every page generated is http://localhost/report.cgi

but the contents of each page is different depending on what users report is selected.
Still not sure that I understand. I suspect you've actually got to sort 2 things:

1 - render a report for each possible input
2 - convert that to PDF

Assuming that you can't just do something like:

http://localhost/report.cgi?code=1
http://localhost/report.cgi?code=2
http://localhost/report.cgi?code=3

etc then I think you're stuck.
  Reply With Quote
Old 30-07-2008, 04:30 PM   #9
 
danIT's Avatar
 
Join Date: Apr 2006
Location: UK
Posts: 484
Thanks: 8
Thanked 6 Times in 5 Posts
Rep Power: 7 danIT is on a distinguished road
Default Help

Can anyone tell me how to go about using the below code? Combile etc....

or atleast what language this is?

Code:
sub PrintPage(sURL)
  Set oIE= CreateObject("InternetExplorer.Application")
  Do While (oIE.Busy)
      Wscript.Sleep 250
  Loop
  oIE.visible=true
  oIE.ToolBar = false
  oIE.StatusBar = false
  oIE.Resizable = false
  oIE.Navigate (sURL)
  Do While (oIE.Busy)
      Wscript.Sleep 250
  Loop
  wscript.sleep 1000 'just so you can see the page
  sFilename=replace(sURL,"/","-")
  sFileName=replace(sURL,":","-")
  oShell.regwrite "HKCU\Software\PDFCreator\Program\AutoSaveFileName",sFileName
  Oie.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, PRINT_WAITFORCOMPLETION,0
  oIe.quit
end sub

Sub Initialise
  Set oReg = GetObject("winmgmts://./root/default:StdRegProv")
  sPath = "Software\PDFCreator\Program"
  lRC=oReg.SetDwordValue(HKEY_CURRENT_USER,sPath,"ShowAnimation",0)
  lRC=oReg.SetDwordValue(HKEY_CURRENT_USER,sPath,"UseAutoSave",1)
  lRC=oReg.SetDwordValue(HKEY_CURRENT_USER,sPath,"UseAutoSaveDirectory",1)
  lRC=oReg.SetStringValue(HKEY_CURRENT_USER,sPath,"AutoSaveDirectory","c:\temp")
  lRC=oReg.SetDwordValue(HKEY_CURRENT_USER,sPath,"AutoSaveStartStandardProgram",0)
end sub
  Reply With Quote
Old 30-07-2008, 05:20 PM   #10
 
dhicks's Avatar
 
Join Date: Aug 2005
Location: Alton, Hampshire
Posts: 1,385
Thanks: 119
Thanked 92 Times in 87 Posts
Rep Power: 28 dhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to all
Default

Quote:
Originally Posted by danIT View Post
Can anyone tell me how to go about using the below code? Compile etc... or at least what language this is?
Where did the code come from? I'm guessing it's VBScript, intended to be run server-side (i.e. save it with a .vbs extension, run it and see what happens). It looks like it prints a web page for you by starting up an instance of Internet Explorer, waiting until it loads and navigates to a web page, then printing that page to the Open Source version of PDF Creator.

--
David Hicks
  Reply With Quote
Old 31-07-2008, 12:12 AM   #11
 
kesomir's Avatar
 
Join Date: Mar 2008
Location: London
Posts: 173
uk uk city of london
Thanks: 8
Thanked 12 Times in 11 Posts
Rep Power: 4 kesomir will become famous soon enough
Default

I feel your pain.

html2ps and html2pdf - Convert HTML to PostScript or PDF. Supports over 500 HTML and CSS tags and properties.
dompdf - The PHP 5 HTML to PDF Converter
FPDF
PHP: PDF - Manual

Listed a few in case they weren't all on your list.
  Reply With Quote
The Following User Says Thank You to kesomir For This Useful Post:
danIT (31-07-2008)
Old 31-07-2008, 12:08 PM   #12
 
srochford's Avatar
 
Join Date: Aug 2005
Location: London
Posts: 1,100
uk
Thanks: 1
Thanked 113 Times in 98 Posts
Rep Power: 29 srochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to allsrochford is a name known to all
Default

Quote:
Originally Posted by dhicks View Post
Where did the code come from? I'm guessing it's VBScript, intended to be run server-side (i.e. save it with a .vbs extension, run it and see what happens). It looks like it prints a web page for you by starting up an instance of Internet Explorer, waiting until it loads and navigates to a web page, then printing that page to the Open Source version of PDF Creator.

--
David Hicks
Came from me :-)

It's vbscript - it'll run on any machine as long as you've got internet explorer and a PDF driver installed (actually, it'll print to the default printer but the original request was for PDF)

as you say, save it as <filename>.vbs Create a text file c:\temp\urls.txt containing addresses of pages you want printing then open a command prompt and type <filename> to get the web pages loaded in turn and then printed.
  Reply With Quote
Old 31-07-2008, 12:49 PM   #13
 
dhicks's Avatar
 
Join Date: Aug 2005
Location: Alton, Hampshire
Posts: 1,385
Thanks: 119
Thanked 92 Times in 87 Posts
Rep Power: 28 dhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to alldhicks is a name known to all
Default

Quote:
Originally Posted by srochford View Post
Came from me :-)
Eh? <Checks previous posts...> Oh yea! How come the original poster is still having a problem, surely that script does just what he wants?

--
David Hicks
  Reply With Quote
Old 31-07-2008, 12:59 PM   #14
 
Geoff's Avatar
 
Join Date: Jun 2005
Location: Fylde, Lancs, UK.
Posts: 9,842
uk uk lancashire
Thanks: 41
Thanked 217 Times in 198 Posts
Blog Entries: 1
Rep Power: 64 Geoff has much to be proud ofGeoff has much to be proud ofGeoff has much to be proud ofGeoff has much to be proud ofGeoff has much to be proud ofGeoff has much to be proud ofGeoff has much to be proud ofGeoff has much to be proud ofGeoff has much to be proud of
Send a message via ICQ to Geoff Send a message via AIM to Geoff Send a message via MSN to Geoff Send a message via Yahoo to Geoff Send a message via Skype™ to Geoff
Default

HTML 2 (F)PDF Project ?
  Reply With Quote
Reply

Register now for FREE and post messages!


Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
Birthday:      
Image Verification
  I agree to forum rules 

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wiki Site which teaches html, css and php My220x Coding 1 04-07-2008 10:17 PM
html/ javascript help strawberry Coding 2 02-07-2008 11:22 AM
HTML Help Shrimpersfan Windows 6 25-04-2008 01:56 PM
HTML Help with Outlook robbied69 Coding 4 29-02-2008 05:37 PM
HTML Editor alan-d Web Development 7 17-04-2007 07:56 AM



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search Thread
Search Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 03:29 PM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Copyright EduGeek.net