html - Save web page as pdf with vba -


i having trouble saving web page pdf format. have pdf creator. printing on paper works, pdfcreator default printer doesn't save pdf. here have until :

dim wshnetwork object  set wshnetwork = createobject("wscript.network")  wshnetwork.setdefaultprinter "pdfcreator"   ie.execwb 6, 2 'olecmdid_print, olecmdexecopt_dontpromptuser   call pdfprint("c:\" & "filename" & ".pdf") 

and :

sub pdfprint(strpdfpath string)      'prints web page pdf file using adobe professional.     'api functions used specify necessary windows while     'a wmi function used check printer's status.      'by christos samaras     'http://www.myengineeringworld.net      dim ret                 long     dim childret            long     dim childret2           long     dim childret3           long     dim comboret            long     dim editret             long     dim childsavebutton     long     dim pdfret              long     dim pdfname             string     dim starttime           date      'find main print window.     starttime = now()     until now() > starttime + timevalue("00:00:05")         ret = 0         doevents         ret = findwindow(vbnullstring, "save pdf file as")         if ret <> 0 exit     loop      if ret <> 0         setforegroundwindow (ret)         'find first child window.         starttime = now()         until now() > starttime + timevalue("00:00:05")             childret = 0             doevents             childret = findwindowex(ret, byval 0&, "duiviewwndclassname", vbnullstring)             if childret <> 0 exit         loop          if childret <> 0             'find second child window.             starttime = now()             until now() > starttime + timevalue("00:00:05")                 childret2 = 0                 doevents                 childret2 = findwindowex(childret, byval 0&, "directuihwnd", vbnullstring)                 if childret2 <> 0 exit             loop              if childret2 <> 0                 'find third child window.                 starttime = now()                 until now() > starttime + timevalue("00:00:05")                     childret3 = 0                     doevents                     childret3 = findwindowex(childret2, byval 0&, "floatnotifysink", vbnullstring)                     if childret3 <> 0 exit                 loop                  if childret3 <> 0                     'find combobox edited.                     starttime = now()                     until now() > starttime + timevalue("00:00:05")                         comboret = 0                         doevents                         comboret = findwindowex(childret3, byval 0&, "combobox", vbnullstring)                         if comboret <> 0 exit                     loop                      if comboret <> 0                         'finally, find "edit property" of combobox.                         starttime = now()                         until now() > starttime + timevalue("00:00:05")                             editret = 0                             doevents                             editret = findwindowex(comboret, byval 0&, "edit", vbnullstring)                             if editret <> 0 exit                         loop                          'add pdf path file name combobox of print window.                         if editret <> 0                             sendmessage editret, wm_settext, 0&, byval " " & strpdfpath                             keybd_event vk_delete, 0, 0, 0 'press delete                             keybd_event vk_delete, 0, keyeventf_keyup, 0 ' release delete                              'get pdf file name full path.                             on error resume next                             pdfname = strpdfpath                             on error goto 0                              'save/print web page pressing save button of print window.                             sleep 1000                             childsavebutton = findwindowex(ret, byval 0&, "button", "&save")                             sendmessage childsavebutton, bm_click, 0, 0                              'sometimes printing delays, in large colorful web pages.                             'here code checks printer status , if idle means                             'printing has finished.                             until checkprinterstatus("adobe pdf") = "idle"                                 doevents                                 if checkprinterstatus("adobe pdf") = "error" exit                             loop                              'since adobe professional opens after finishing printing, find                             'the open pdf document , close (using post message).                             starttime = now()                             until starttime > starttime + timevalue("00:00:05")                                 pdfret = 0                                 doevents                                 pdfret = findwindow(vbnullstring, pdfname & " - adobe acrobat")                                 if pdfret <> 0 exit                             loop                             if pdfret <> 0                                 postmessage pdfret, wm_close, 0&, 0&                             end if                         end if                     end if                 end if             end if         end if    end if end sub 


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -