XOD Conversion from Excel Failing

487 views
Skip to first unread message

David Compton

unread,
Mar 22, 2017, 11:31:33 AM3/22/17
to PDFTron WebViewer
I have a Windows service that converts document to XOD format.  It uses this simple code to perform the conversion:

                var xodOutputOptions = new pdftron.PDF.Convert.XODOutputOptions();
                try
                {
                    pdftron.PDF.Convert.ToXod(sourceFullPath, targetFullPath, xodOutputOptions);
                        ......................
                    }
                catch (Exception)
                {
                    UseExistingFile(customer, doc.Name, sourceFullPath, targetFullPathExc, type);
                }

Files in Word or PDF format convert fine to XOD format.  However files in Excel (.xlsx) do not.   I have Office 2016 installed on the server, although I have also tried with Office 2010 with the same result.  There is a consistent time lapse of 4 minutes between the call to perform the conversion and when an exception is received.  The log messages followed by the exception message are shown below:

+ 134288    22 Mar 2017 23:34:37,911 [16] INFO User DB Service - Converting document for Cold Water Technologies. Name: Fees and Charges - Water and Wastewater 2017-18 - Editable  Source Path: C:\Web Sites\files.abcdefghi.com.au\a21fcdb9-efb4-4477-afe9-5e1303bbf308\feesandcharges-waterandwastewater2017-18-editable_7b3f1342-ab3e-4a67-8e82-38613665eccc.xlsx  Target Path: C:\Web Sites\filesv2.abcdefghi.com.au\a21fcdb9-efb4-4477-afe9-5e1303bbf308\feesandcharges-waterandwastewater2017-18-editable_7b3f1342-ab3e-4a67-8e82-38613665eccc.xod
+ 134469    22 Mar 2017 23:38:38,786 [16] ERROR User DB Service - Error converting document for Cold Water Technologies. Name: Fees and Charges - Water and Wastewater 2017-18 - Editable  Source Path: C:\Web Sites\files.abcdefghi.com.au\a21fcdb9-efb4-4477-afe9-5e1303bbf308\feesandcharges-waterandwastewater2017-18-editable_7b3f1342-ab3e-4a67-8e82-38613665eccc.xlsx  Target Path: C:\Web Sites\filesv2.abcdefghi.com.au\a21fcdb9-efb4-4477-afe9-5e1303bbf308\feesandcharges-waterandwastewater2017-18-editable_7b3f1342-ab3e-4a67-8e82-38613665eccc.xod

pdftron.Common.PDFNetException: Exception:
     Message: An error occurred while converting the file.
Detailed error:
    Unable to convert file, too many attempts.
Error getting Workbook.ExportAsFixedFormat ID.
Code: PDFTRON_UNKNOWN (-2147023174)
      File: "Excel.cpp":201
    Log:
      Start check system account.
      Session ID is: 0.
      Done checking system account.
      Creating an Excel application instance.
      Excel application instance created.
      Application.AutomationSecurity ID obtained.
      Application.AutomationSecurity value set to 3.
      Application.DisplayAlerts ID obtained.
      Application.Version ID obtained.
      Application version: 16.
      Application.Build ID obtained.
      Application build: 0.
      Application.Workbooks ID obtained.
      Opening workbook "C:\Web Sites\files.abcdefghi.com.au\a21fcdb9-efb4-4477-afe9-5e1303bbf308\feesandcharges-waterandwastewater2017-18-editable_7b3f1342-ab3e-4a67-8e82-38613665eccc.xlsx".
      Workbooks.Open ID obtained.
      Workbook "C:\Web Sites\files.abcdefghi.com.au\a21fcdb9-efb4-4477-afe9-5e1303bbf308\feesandcharges-waterandwastewater2017-18-editable_7b3f1342-ab3e-4a67-8e82-38613665eccc.xlsx" opened.
      Workbook.Saved ID obtained.
      Error setting Workbook.Saved value.

     Conditional expression: false
     Filename   : Convert.cpp
     Function   : trn::PDF::Convert::ToPdf
     Linenumber : 1679

   at pdftron.PDF.Convert.ToXod(String in_filename, String out_filename, XODOutputOptions options)
   at UserDbService.Engine.Engine.ConvertDocument(Customer customer, DateTime utcNow, Document doc)


Are you able to suggest a resolution to this problem.

Kind regards,

David

Ryan - PDFNet Developer

unread,
Mar 22, 2017, 4:06:10 PM3/22/17
to PDFTron WebViewer
What version of PDFNet are you using?

If you download the latest version, the exception message will contain a lot more (useful) information.

Latest official: https://www.pdftron.com/pdfnet/downloads.html
Release channel: http://www.pdftron.com/nightly/?p=stable/
Developer channel: http://www.pdftron.com/nightly/?p=experimental/
Latest official builds, and Release channel, are ready for production usage, however the developer channel builds do not get the same amount of testing and can be in a state of change.

David Compton

unread,
Mar 23, 2017, 11:33:06 AM3/23/17
to PDFTron WebViewer on behalf of Ryan - PDFNet Developer
I am using version 6.7.1.52203.  Isn't that the latest version?

--
You received this message because you are subscribed to the Google Groups "PDFTron WebViewer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfnet-webviewer+unsubscribe@googlegroups.com.
To post to this group, send email to pdfnet-webviewer@googlegroups.com.
Visit this group at https://groups.google.com/group/pdfnet-webviewer.
For more options, visit https://groups.google.com/d/optout.

Ryan - PDFNet Developer

unread,
Mar 23, 2017, 1:08:50 PM3/23/17
to PDFTron WebViewer
Thank, you yes that is the correct version.

Please review this document.

Most likely you missing the correct desktop folder for Excel to run under the service.

David Compton

unread,
Mar 24, 2017, 6:07:33 AM3/24/17
to PDFTron WebViewer on behalf of Ryan - PDFNet Developer
Could this be in any way related to this other forum post related to the Windows service:  https://mail.google.com/mail/u/0/#search/convert+service/159656ab672b63f7


On 24 March 2017 at 12:33, David Compton <david.w...@gmail.com> wrote:
Hi Ryan,

I have reviewed the document.  I am running 32bit Office on a 64 bit machine.  The "C:\Windows\System32\config\systemprofile\Desktop" already existed.  To be safe I also created the "C:\Windows\SysWOW64\config\systemprofile\Desktop" folder.  This made no difference to the problem.  I then temporarily switched my service over to use a system account (I chose administrator to avoid any permission issues).  Still the same error persists.  What else can you suggest?

Thanks,

David

--

David Compton

unread,
Mar 24, 2017, 6:07:33 AM3/24/17
to PDFTron WebViewer on behalf of Ryan - PDFNet Developer
Hi Ryan,

I have reviewed the document.  I am running 32bit Office on a 64 bit machine.  The "C:\Windows\System32\config\systemprofile\Desktop" already existed.  To be safe I also created the "C:\Windows\SysWOW64\config\systemprofile\Desktop" folder.  This made no difference to the problem.  I then temporarily switched my service over to use a system account (I chose administrator to avoid any permission issues).  Still the same error persists.  What else can you suggest?

Thanks,

David

--

Ryan - PDFNet Developer

unread,
Mar 24, 2017, 11:32:01 AM3/24/17
to PDFTron WebViewer
If you have not already you should kill any excel processes running. There may be a hung one causing issues.

Make sure you are using a licensed copy of Office.

Also, make sure that the Print Spooler service is turned on.

Finally, there is this diagnostic tool, it launches IIS, but it has some checks that might be helpful. Just modify it to convert an excel file (I think it just does a Word file).

David Compton

unread,
Mar 27, 2017, 9:40:13 AM3/27/17
to PDFTron WebViewer on behalf of Ryan - PDFNet Developer
Hi Ryan,

We are using a licensed copy of Office and the Print Spooler service is turned on.  Conversion from Word and PDF is working fine.

In order to get it the web app to work on our server I had to give permissions to IUSR and IIS_IUSRS to the Desktop folders - 64 bit and 32 bit and remove the call to PDFNet.Initialize otherwise I got the following error:

PDFNet was already initialized in demo mode. For solution see pdftron.com/kb_demo_init

I also modifed the diagnostic tool to try converting first a PDF, then a Word and finally an Excel file.

However in the end I still got stumped with an error.  The program output is below.  I tried various things suggested at the "kb_eval_error", however none of them worked including installing the PDFNet.dll in the GAC, putting an entry in the web.config and attempting to use the (redundant) caspol utility.  I've been going around in circles with this for a few hours now.  Nothing gets me past this error.  The diagnostic tool is not much use to me in this scenario if it cannot run on the server.  Do you have any other suggestions?

-------- Server Information -------- 
Running IIS: Microsoft-IIS/8.5 
IIS process name: w3wp 
IIS process is running in 32bit mode. 
IIS process is run using credential: 
AppPool ID: DefaultAppPool 
-------- Running PDFNet -------- 
PDFNet is loaded from: file:///C:/inetpub/wwwroot/bin/PDFNet.DLL 
PDFNet is loaded from GAC: False 
Loaded PDFNet version: 6.8045106 
Converting "C:\inetpub\wwwroot\bin\test.pdf" to "C:\inetpub\wwwroot\bin\test.pdf.xod" 
Exception: Exception: 
Message: 
The evaluation version encountered an error in your system configuration. 
Please go to: pdftron.com/kb_eval_error No reg. write rights
Conditional expression: 
Filename : 
Function : 
Linenumber : 0

Stack:
at pdftron.PDF.Convert.ToXod(String in_filename, String out_filename) 
at Net451_VS2013.Default.Page_Load(Object sender, EventArgs e) 

Thanks,

David





--

Ryan - PDFNet Developer

unread,
Mar 27, 2017, 4:56:48 PM3/27/17
to PDFTron WebViewer
PDFNet was already initialized in demo mode. For solution see pdftron.com/kb_demo_init

This error means that you have triggered initialization before hand, either by calling PDFNet.Initialize directly, or by creating a PDFDoc object beforehand, which implicitly triggers Initialization. Please make sure PDFNet.Initialize is called once, near the beginning of the process lifetime.

The evaluation version encountered an error in your system configuration.
Please go to: pdftron.com/kb_eval_error No reg. write rights

This is a purely security/permission issue for the service. I would recommend running the process that is doing conversion under a normal user account, during your evaluation. If you have a license, or once you purchase one, then you can revert to a reduced permission setting.

David Compton

unread,
Mar 27, 2017, 9:16:44 PM3/27/17
to PDFTron WebViewer on behalf of Ryan - PDFNet Developer
Hi Ryan,

Re the "PDFNet was already initialized...." message.  I understand that is what the message is saying - but take a look at my code below (slightly modified version of the original diagnostic project code).  I am not initalizing twice.

protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            using (var writer = new StringWriter()) {
                Console.SetOut(writer);
                Console.SetError(writer);
                try {
                    // Print some useful info about IIS...
                    Console.Out.WriteLine("-------- Server Information --------");
                    Console.Out.WriteLine("Running IIS: {0}", Request.ServerVariables["SERVER_SOFTWARE"]);
                    Console.Out.WriteLine("IIS process name: {0}", Process.GetCurrentProcess().ProcessName);
                    Console.Out.WriteLine("IIS process is running in {0} mode.", Environment.Is64BitProcess ? "64bit" : "32bit");
                    Console.Out.WriteLine("IIS process is run using credential: {0}", Request.ServerVariables["LOGON_USER"]);
                    Console.Out.WriteLine("AppPool ID: {0}", Request.ServerVariables["APP_POOL_ID"]);
                    Console.Out.WriteLine("-------- Running PDFNet --------");
                    var pdfnetAssembly = System.Reflection.Assembly.GetAssembly(typeof(pdftron.PDFNet));
                    Console.Out.WriteLine("PDFNet is loaded from: {0}", pdfnetAssembly.CodeBase);
                    Console.Out.WriteLine("PDFNet is loaded from GAC: {0}", pdfnetAssembly.GlobalAssemblyCache);
                    Console.Out.WriteLine("Loaded PDFNet version: {0}", pdftron.PDFNet.GetVersion());

                    //Console.Out.WriteLine("Initializing PDFNet.");
                    //pdftron.PDFNet.Initialize("");

                    var loadPath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
                    if (loadPath.StartsWith("file:///")) {
                        loadPath = loadPath.Substring("file:///".Length);
                    }
                    loadPath = Path.GetDirectoryName(loadPath);

                    var loadFile = Path.Combine(loadPath, "test.pdf");
                    var outFile = Path.Combine(loadPath, "test.pdf.xod");
                    try
                    {
                        if (File.Exists(outFile))
                        {
                            File.Delete(outFile);
                        }
                    }
                    catch { }
                    Console.Out.WriteLine("Converting \"{0}\" to \"{1}\"", loadFile, outFile);
                    pdftron.PDF.Convert.ToXod(loadFile, outFile);
                    Console.Out.WriteLine("Done converting docx!");

                    loadFile = Path.Combine(loadPath, "test.docx");
                     outFile = Path.Combine(loadPath, "test.docx.xod");
                    try
                    {
                        if (File.Exists(outFile))
                        {
                            File.Delete(outFile);
                        }
                    }
                    catch { }
                    Console.Out.WriteLine("Converting \"{0}\" to \"{1}\"", loadFile, outFile);
                    pdftron.PDF.Convert.ToXod(loadFile, outFile);
                    Console.Out.WriteLine("Done converting docx!");


                    loadFile = Path.Combine(loadPath, "test.xlsx");
                    outFile = Path.Combine(loadPath, "test.xlsx.xod");
                    try {
                        if (File.Exists(outFile)) {
                            File.Delete(outFile);
                        }
                    }
                    catch { }
                    Console.Out.WriteLine("Converting \"{0}\" to \"{1}\"", loadFile, outFile);
                    pdftron.PDF.Convert.ToXod(loadFile, outFile);
                    Console.Out.WriteLine("Done converting xlsx!");
                    pdftron.PDFNet.Terminate();
                }
                catch (Exception ex) {
                    writer.WriteLine("Exception: {0}\nStack:\n{1}", ex.Message, ex.StackTrace);
                }
                writer.Flush();
                Response.Write(writer.ToString().Replace("\n", "<br/>"));
            }
            Response.Flush();
            Response.End();
        }
    }

Ryan - PDFNet Developer

unread,
Mar 28, 2017, 2:46:15 PM3/28/17
to PDFTron WebViewer
Yes, from that code you sent, you should be running in demo mode (watermarking on the generated XOD files).

The "PDFNet was already initialized in demo mode." exception should only occur if you later on call PDFNet.Initialize("with_your_license_key"); after already entering demo mode by accident.

Though it is commented out, I see that you pass in an empty string to pdftron.PDFNet.Initialize(""). Instead, to run in demo mode, don't pass in any parameter to that function. See any of our sample projects for an example.

So you don't pass in a license key string somewhere else in your code?
What line of code actually throws that exception?

David Compton

unread,
Apr 3, 2017, 11:23:03 AM4/3/17
to PDFTron WebViewer on behalf of Ryan - PDFNet Developer
I decided to go back to my Windows Service and try changing the account that it was running under.   I ended up resolving it by running it under a highly priviliged domain account (using Local System, Network Service or Local Service did not work).

There seems to be 3 factors at play here:

1.  The account that the Windows Service runs under
2.  Permissions on C:\Windows\System32\config\systemprofile\Desktop and C:\Windows\SysWOW64\config\systemprofile\Desktop
3.  Setting DCOM permissions by running "mmc comexp.msc /32" (refer http://www.bloing.net/2011/01/how-to-make-iis7-play-nice-with-office-interop/)

I needed to make sure that the domain account was used and had appropriate privileges in each of these 3 areas.

Hopefully this saves someone else the hours of time that it cost me.

Kind regards,

David




Reply all
Reply to author
Forward
0 new messages