How to print an office application?

Sett 26 ganger
Hopp til første uleste melding

Keyhan Hadjari

ulest,
8. juli 2021, 14:52:4208.07.2021
til Java Native Access
I want to be able to print a word/excel/powerpoint document programmitically.

I had a conversation earlier with MAthias Bläsig where he gave me a tip to look at printout method in Document class in his project which looks liked this:

@ComMethod(name = "PrintOut", dispId = 0x1be)
void PrintOut(Object Background,
Object Append,
Object Range,
Object OutputFileName,
Object From,
Object To,
Object Item,
Object Copies,
Object Pages,
Object PageType,
Object PrintToFile,
Object Collate,
Object ActivePrinterMacGX,
Object ManualDuplexPrint,
Object PrintZoomColumn,
Object PrintZoomRow,
Object PrintZoomPaperWidth,
Object PrintZoomPaperHeight);

I have looked at his project and copied the method Printout to ComIDocument.

But when I call it I get error message: 

Exception in thread "main" com.sun.jna.platform.win32.COM.COMInvokeException: Undantag inträffade.(HRESULT: 80020009)
Source:      Microsoft Word
Description: Talet måste vara mellan -32765 och 32767.
at com.sun.jna.platform.win32.COM.COMUtils.checkRC(COMUtils.java:187)
at com.sun.jna.platform.win32.COM.util.ProxyObject.oleMethod(ProxyObject.java:736)
at com.sun.jna.platform.win32.COM.util.ProxyObject.invokeMethod(ProxyObject.java:450)
at com.sun.jna.platform.win32.COM.util.ProxyObject.invoke(ProxyObject.java:256)
at com.sun.proxy.$Proxy13.PrintOut(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.sun.jna.platform.win32.COM.util.Factory$ProxyObject2$1.call(Factory.java:98)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:205)
at com.sun.jna.platform.win32.COM.util.ComThread.execute(ComThread.java:157)
at com.sun.jna.platform.win32.COM.util.Factory.runInComThread(Factory.java:172)
at com.sun.jna.platform.win32.COM.util.Factory.access$100(Factory.java:56)
at com.sun.jna.platform.win32.COM.util.Factory$ProxyObject2.invoke(Factory.java:95)
at com.sun.proxy.$Proxy13.PrintOut(Unknown Source)
at com.sun.jna.platform.win32.COM.util.office.Wordautomation_KB_313193_Mod.main(Wordautomation_KB_313193_Mod.java:216)

I have set everything to null except OutputFileName.

Has anyone else solved this or have a suggestion where to look?


Matthias Bläsing

ulest,
9. juli 2021, 11:42:4509.07.2021
til jna-...@googlegroups.com
Hi Keyhan,

if I remember correctly, optional parameters for COM should be send as type VT_ERROR and s_code DISP_E_PARAMNOTFOUND. To make that easier in the past the helper constant:

com.sun.jna.platform.win32.Variant.VARIANT.VARIANT_MISSING

was introduced.

Please see if it helps if you replace all parameters with VARIANT_MISSING.

HTH

Matthias
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/f621180b-84e2-4701-8668-4aaedc2dc1a5n%40googlegroups.com.

Keyhan Hadjari

ulest,
10. juli 2021, 17:34:1410.07.2021
til Java Native Access
Thank Mathias, very correctly it worked and I got my print like you said. Thanks for your help.
Svar alle
Svar til forfatter
Videresend
0 nye meldinger