Author Topic: Manipulating AdobeReader using Visual LISP Possible?  (Read 23070 times)

0 Members and 2 Guests are viewing this topic.

LE3

  • Guest
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #75 on: August 26, 2010, 09:51:18 PM »
Using C# ?

I referenced the activex file:
i.e: C:\Program Files\Common Files\Adobe\Acrobat\ActiveX\AcroPDF.dll

And this one allows you to print, to have the pdf control and use it on a form, take out the toolbar, etc...



Thanks!
I know and even if that is not possible, I still gave it a try... and that's why I am in the programming field -  :-)

Went the C# route and that looks better (promising) - btw - once there is a working sample will try to post it at the .net side.


Tell me about it :) I didn't want to believe it either! But, after importing the type library and banging my head against the wall for a couple of hours I just had to assume that even though it looked like all the necessary methods had been exposed, there was still something behind the scenes stopping me from creating the connection.

A bit of further reading suggests that you can use DDE to communicate with Reader.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #76 on: August 27, 2010, 08:06:56 AM »
@Lee: Just wondering; is there a reason you are trying to do this from code?  If you select the files you want to print in explorer then select "print" from the right click menu then everything prints without a problem (at least on my system).

Hi Daniel,

Yes, I realise this can be done, but it doesn't give much control over the printing - for example all the files are in a weird order and some are perhaps at the wrong orientation. I first thought manipulating Adobe to print file by file might be a relatively easy task (using the relevant ActiveX object methods), but it appears not.

BTW, with Luis' VL code, 'pdf' is not nil on my machine but rather a valid VLA object.

Lee

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #77 on: August 30, 2010, 08:40:08 AM »
Now that im back to work from my vacation i gave this a quick try and it worked for me; One giant hint for you:

The printer name isnt always the same name you see in "Printers and Faxes" section of your control panel.  Here are two methods for you to try and find the proper name for the printer.

Method 1 (this would be the fake hacker or script kiddie way): Open a windows command prompt and type NET VIEW this should show you the print server name (along with others).  Now open a win explore window and try to navigate there. Now you should see several printers, juxtapose a view of the "Printers and Faxes" on your computer to see which is which.

Method 2 (This would be the IT way): go to "Printers and Faxes". Right click on the printer in question and choose "Printer properties". Go to the "Ports" tab and see what the fully qualified path and name is of the printer.

COPY <PLOT NAME> <PATH YOU JUST LOOKED UP> /B
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #78 on: August 30, 2010, 08:46:03 AM »
Now that im back to work from my vacation i gave this a quick try and it worked for me; One giant hint for you:

I'm loving how direct this answer is, having just this morning read through the whole of this gem - an enlightening read, offering many things that I would implement if I had the chance to start this thread again.

When I get back to work after the bank holiday weekend I shall be sure to give your methods a go and get back to you with my results.

Many thanks for your time helping me investigate this Se7en - it is sincerely appreciated.

Lee

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #79 on: August 30, 2010, 11:10:13 AM »
Yes, that is a VERY good read and I'm glad you liked it.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #80 on: August 30, 2010, 11:16:59 AM »
Yes, that is a VERY good read and I'm glad you liked it.

That - and the article about 'hackers'  :-)

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #81 on: August 30, 2010, 11:28:00 AM »
I haven't read that one yet. 

He has got a very nice style about his writings doesn't he?

I cant wait to read his "The Art of Unix Programming" paper. Ive skimmed it and it seemed like it had some very cool stuff in it.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #82 on: August 30, 2010, 12:06:11 PM »
I haven't read that one yet. 

He has got a very nice style about his writings doesn't he?

Definitely - I love his humour, especially in his reference to 'crackers' ( you'll read that in the hackers article ).

I cant wait to read his "The Art of Unix Programming" paper. Ive skimmed it and it seemed like it had some very cool stuff in it.

Yeah, after reading his articles I feel like I need to advance a lot more into other languages and systems - I'm glad he notes LISP as a notable language to learn though.  :-)


JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #83 on: August 30, 2010, 12:24:36 PM »
heh, not AutoLisp. Im pretty sure he's talking about Common Lisp. And Just so you know, you could fit AutoLisp in Common Lisp's bathroom closet.

If you would like a taste of whats to come if you choose to wander into the Common Lisp ring, read this.
http://www.paulgraham.com/onlisp.html
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #84 on: August 30, 2010, 12:26:59 PM »
heh, not AutoLisp. Im pretty sure he's talking about Common Lisp. And Just so you know, you could fit AutoLisp in Common Lisp's bathroom closet.

I thought you might say something like that...

I'll have a read  :-)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #85 on: August 31, 2010, 04:44:12 PM »
Developments:

1) Tried method as describe by Se7en above: printer path is correct.

Result:

Job not added to print queue, no noticeable result. Could this be a permissions thing? Seeing as I'm not administrator on the computer?



2) Advancement in OLE Automation approach.

After a touch of research, I found that the exe print command could be found using something like:

Code: [Select]
(defun GetPrintCmd ( / wsh reg result )

  (setq wsh (vlax-create-object "WScript.Shell"))

  (if (setq reg (vlax-invoke wsh 'RegRead "HKCR\\.pdf\\"))
    (setq result (vlax-invoke wsh 'RegRead (strcat "HKCR\\" reg ".7\\shell\\print\\command\\")))
  )

  (vlax-release-object wsh)

  result
)

(For the relevant version of Adobe)

I tried using the result of the above to manipulate the .exe as before, and the jobs were added to the queue. But, as before, only the first job prints and the others register that seemingly only half the data has been sent - causing a timeout error.

But, during my digging in the registry, I found entries for the AcroExch.App Object, using the ProgID AcroExch.App.1 - this returned a valid object which I could query for properties.

I then found info on the net relating to how to manipulate such objects for printing, and translated it to VL:

Code: [Select]
(defun c:test ( / pdf_file adobe pddoc printdoc n avdoc )

  (setq pdf_file "H:\\My Documents\\Test.pdf")

  (setq adobe (vlax-create-object "AcroExch.app.1"))

  (setq pddoc (vlax-create-object "AcroExch.PDDoc.1"))

  (setq printdoc (vlax-create-object "AcroExch.AvDoc.1"))

  (vlax-invoke printdoc 'open pdf_file "")

  (setq n (vlax-invoke pddoc 'GetNumPages))

  (princ (strcat "\nPages: " (itoa n)))

  (setq avdoc (vlax-invoke adobe 'GetActiveDoc))

  (print (vlax-invoke avdoc 'PrintPages 0 n 1 0 0))

  (vlax-invoke pddoc 'Close)

  (vlax-invoke adobe 'CloseAllDocs)

  (vlax-invoke adobe 'Exit)

  (vlax-release-object pddoc)
 
  (vlax-release-object adobe)
 
  (vlax-release-object printdoc)

  (princ)
)

This opens the document OK, but the PrintPages method seems to return 0, indicating an error during printing   :-(

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #86 on: September 01, 2010, 10:29:22 AM »
> permissions ...

Not sure, but i doubt it.

Thought:
I'm seeing some people saying some of the same things you are though. Would this be a "HP" brand of printer? Apparently there is some firmware problems (no link because im still researching and im not even sure this is the same issue yet).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #87 on: September 01, 2010, 02:22:26 PM »
Would this be a "HP" brand of printer?

Indeedy.  :-(

The printer is a HP Color LaserJet 5550 PS on a network.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #88 on: September 01, 2010, 03:00:44 PM »
Try to plot via the windows command prompt (start->applications->accessories->cmd prompt) and see what happens.


BTW, You will not get any further using the Adobe reader route then you already have and i hope you realize that now; You need to divert that attention elsewhere. If you need/can/whatever give a third party tool like Redmon (now RedmonEE) a try because it has an exe  that is devoted to just sending files to a printer.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Manipulating AdobeReader using Visual LISP Possible?
« Reply #89 on: September 01, 2010, 03:18:07 PM »
Try to plot via the windows command prompt (start->applications->accessories->cmd prompt) and see what happens.

Will do.

BTW, You will not get any further using the Adobe reader route then you already have and i hope you realize that now; You need to divert that attention elsewhere. If you need/can/whatever give a third party tool like Redmon (now RedmonEE) a try because it has an exe  that is devoted to just sending files to a printer.

It does seem that way, yes. I only really pursued it because it was the method that came closest to a print over the other methods, but I seem to have hit a major wall with it.

Third-party software is likely to be a last resort if I'm honest due to IT restrictions...  :|