B4J Question [SOLVED] [XLUtils] Error creating a .pdf file

BillMeyer

Well-Known Member
Licensed User
Longtime User
Good Day B4Xers,

I am using the provided example with XLUtils and trying to create a pdf from the generated Word document but I am getting a constant error which I cannot resolve:

Here is the code I am using:

XLUtils Word Example:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    WD.Initialize
    xui.SetDataFolder("Reports")
    Dim n As Long = DateTime.Now
    Dim doc As WordDocument = CreateDocument
    Dim f As String = doc.SaveAs(xui.DefaultFolder, "Report.docx", True)
    Log(DateTime.Now - n)
    Log($"Document saved: ${f}"$)
    'if MS Word is installed:
    Label1.Text = "Creating PDF..."
    'this step can be a bit slow. Comment it during development.
    Wait For (WD.PowerShellConvertToPdf(File.Combine(xui.DefaultFolder, "Report.docx"), File.Combine(xui.DefaultFolder, "Report.pdf"), True)) Complete (Success As Boolean)
    Label1.Text = "Opening word"
    Wait For (WD.OpenWord(f)) Complete (Success As Boolean)
    Label1.Text = "Report created: " & f
    AnotherProgressBar1.Visible = False
End Sub

and the error I am getting:

Code:
, RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
You cannot call a method on a null-valued expression.
At line:1 char:154
+ ... rt.docx');  $document.SaveAs([ref] 'C:\Users\******\AppData\Roami ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
You cannot call a method on a null-valued expression.
At line:1 char:249
+ ... \Roaming\Reports\Report.pdf', [ref] 17);    $document.Close();$objWor ...
+                                                 ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Exception calling "Quit" with "0" argument(s): "Unable to cast COM object of type 
'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This 
operation failed because the QueryInterface call on the COM component for the interface with IID 
'{00020970-0000-0000-C000-000000000046}' failed due to the following error: Error loading type library/DLL. (Exception 
from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))."
At line:1 char:267
+ ... Reports\Report.pdf', [ref] 17);    $document.Close();$objWord.Quit()}
+                                                          ~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidCastException

My Setup:
Dell G3 i7 running windows 11
javac - C:\Program Files\Java\jdk-14.0.1\bin\javac.exe
B4J - Version 9.30

Thanks in Advance for the help
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
Is MS Word installed?
Yes Sir
1642924898257.png
 

Attachments

  • 1642924864760.png
    1642924864760.png
    9.9 KB · Views: 135
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
I think that the problem is that you installed Office 32 bit and are running Java 64 bit. Try to upgrade Office or downgrade to Java 8 32 bit.
Thanks Erel,
I'll give it a shot and report back.
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
Solving this problem was quiet easy once pointed in the right direction by @Erel

When installing Office 365 my support person chose "Default Installation" - this automatically goes to 32bit installation - 32bit Word and 64bit Java are not friends apparently. So to fix this we had to:

1. Backup the .pst files in Outlook
2. Uninstall Office - 64bit won't install if you don't do this
3. Download the 64bit version
4. Install
5. Restore your Outlook

Now B4J speaks to MS Word and can now create a .pdf file and I am a happy chappy !!!
 
Upvote 0
Top