Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Feb 25, 2019 5:36 pm

Hi,

I am encountering some problems when I try to print a document that it stored in memory as a byte array.
My function is the following:
Code: Select all
private static void Print(byte[] bytes)
        {
            using (var stream = new MemoryStream(bytes))
            {
                using (var document = new Spire.Doc.Document(stream))
                {
                    document.PrintDocument.PrinterSettings.PrinterName = "MyPrinter";
                    document.PrintDocument.Print();
                }
            }
        }


However, occasionally the function fails, even when printing always the same document (just to make sure the problem does not depend on the document itself).
What I suspect, is that the printing process is actually carried out during the OnBeginPrint event, where it tries to access resources that may have been disposed by the using statement.
Is my feeling correct? How would you suggest to address the problem?

Thanks,
Francesco

f.mazzurco
 
Posts: 12
Joined: Thu Aug 30, 2018 7:57 am

Tue Feb 26, 2019 3:20 am

Dear Francesco,

Thank you for contacting us.
In your code, the print function is included in the using statements, the resources have not been disposed when executing printing, I think your issue is not related to that the print can't access the resources. And I did an initial simulation with the latest Spire.Doc Pack(hot fix) Version:7.2.4, but didn't encounter any issue when printing. If you were using an old version, I would suggest that you give the latest one a try. If it doesn't help, we need more information as follows to do further investigation.
1) Please tell us the detailed error information that happened on your side.
2) Please provide your input Word document for printing. You could send it to us via email (support@e-iceblue.com).

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Thu Feb 28, 2019 8:23 am

Hi,

Greetings from E-iceblue.
How is your issue going? Could you please give us some feedback at your convenience?
Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Thu Mar 07, 2019 9:52 am

Hi,

Sorry for not giving any feedback. Finally, I investigated the problem and found out that, even though the objectdisposedexception was raised during the printing process, the error did not come from Spire library, but was due to a bug in my code.
My apologies for "blaming" your library when it was just doing fine.

Thanks for the support,
Francesco

f.mazzurco
 
Posts: 12
Joined: Thu Aug 30, 2018 7:57 am

Thu Mar 07, 2019 10:11 am

Hello,

Thanks for your feedback.
If you need other helps, please do not hesitate to contact us. Wish you all the best!

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc