Aspose. word printing rtf file causes issue

Hello,

Our .Net software uses Aspose Word to print .rtf file, but with some certain
printers, such as:

Brother MFC-8950DW/Sanon
Imageclass D1320/ HP printer with HP Universal
Printing PCL 5 (61.150.2.15717) driver,

we could not to print .rtf file to a
.prn file, and system give us some error messages:

Error
occurred while printing document to file “C:\Program
Files\Tamtron\Distribution Server 3\PowerPath_new\Work
Files2\O230708_1_3675837.prn”

Detail:

System.ComponentModel.Win32Exception (0x80004005): A StartDocPrinter call was not issued 
at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e) 
at System.Drawing.Printing.PrintController.Print(PrintDocument document) 
at System.Drawing.Printing.PrintDocument.Print() 
at Aspose.Words.Document.Print(PrinterSettings printerSettings, String documentName) 
at Tamtron.DS3.Service.AsposeWords.PrintDocument(Document document, String printFile, String printerName, Int16 copies, String pageRange, Int32 tray, Boolean useWord95Printing) 

we have tried to print the same file
from our software to other printers, it worked, also tried to print file from
MS word and our other software, the file could be printed as well. I suspected whether Aspose.word is incompatible with
certain printers’ driver?

We use Aspose.Words.dll,
v2.0.50727

Here are related codes:

private void PrintDocument(Document document, string printFile, string printerName, short copies, string pageRange, int tray, bool useWord95Printing)
{   … …
    if (ExtremeTracing)
        TraceExtreme(string.Format("Print document args: doc name=\"{0}\", print file=\"{1}\", "
            + "printer=\"{2}\", copies={3}, page range={4}, tray={5}, use Word 95 printing={6}",
            document.OriginalFileName, printFile, printerName, copies, pageRange, tray, useWord95Printing));
    …
…
 

    // Select the printer through the old WordBasic method because the VBA way changes the default
    // printer for the system
    //typeof(object).InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null,
    // document.Application.WordBasic, new object[] { printerName, 1 },
    //  null, null, new string[] { "Printer", "DoNotSetAsSysDefault" });
    // setup the paper tray to print to
    int useTray = tray;
    if (useTray == 0)
    {
        PrinterSettings settings = new PrinterSettings();
        settings.PrinterName = printerName;
        useTray = settings.DefaultPageSettings.PaperSource.RawKind;
    }
 
    foreach (Section section in document.Sections)
    {
        section.PageSetup.FirstPageTray = useTray;
        section.PageSetup.OtherPagesTray = useTray;
    }

    if (ExtremeTracing)
        TraceExtreme(String.Format("Setting document paper tray to {0}", useTray));

    // the document should have the watermarks and repagination at this point.
    PrinterSettings printerSettings = new PrinterSettings();
    printerSettings.PrinterName = printerName;
    printerSettings.Collate = true;
    printerSettings.Copies = copies;
    try
    {
        SetPrintRange(printerSettings, pageRange);
    }
    catch
    {
        // not a critical failure if it were to happen. Just note it and move on.
        if (VerboseTracing)
        TraceVerbose(string.Format("Invalid print range \"{0}\". Printing all pages.", pageRange));
        printerSettings.PrintRange = PrintRange.AllPages;
    }

    if (!string.IsNullOrEmpty(printFile))
    {
        printerSettings.PrintToFile = true;
        printerSettings.PrintFileName = printFile;
    }

    // finally, we are ready to print the document
    if (VerboseTracing)
    {
        if (printerSettings.PrintToFile)
        TraceVerbose(string.Format("Printing document to file \"{0}\"", printFile));
        else
        TraceVerbose("Printing document directly to printer");
    }

… …

    // pass a document name for when we are printing to PDF, otherwise the output file
    // will be called something generic like "document.pdf" which will be overwritten
    // each time.
    string docName = Path.GetFileNameWithoutExtension(document.OriginalFileName);
    document.Print(printerSettings, docName);
    … …
    }
    catch (Exception ex)
    {
    if (string.IsNullOrEmpty(printFile))
        logSet.Trace.WriteEntry(string.Format("Error occurred while printing document to printer \"{0}\"", printerName),
            TraceLogEntryType.Error, "AsposeWords", "PrintOut", ex.ToString());
    else
        logSet.Trace.WriteEntry(string.Format("Error occurred while printing document to file \"{0}\"", printFile),
            TraceLogEntryType.Error, "AsposeWords", "PrintOut", ex.ToString());

    throw new AsposeWordsException("Error occurred while printing Microsoft Word document to file", ex);
    }
}

Document document is an instance of
Aspose.Words.Document class, which referred to .rtf file; String printFile is the .prn file name with full
path; PrinterSettings is in System.Drawing.dll,
v4.0.30319

Hi,


Thanks for your inquiry. To ensure a timely and accurate response, it would be great if you please create a standalone runnable simple console application that helps us reproduce your problem on our end and attach it here for testing. As soon as you get this simple application ready, we’ll start investigation into your issue and provide you more information. Also, please attach the RTF document you’re getting this problem with here for testing. Does this problem occur with one particular RTF file or any RTF you print causes this exception? What OS (version) are you using?

Best regards,

Thank you Awais,

The rft is created by uncompressing an image stream which is stored in database.

I will email you the simple application and two sample .rtf file.

The OS is MS server 2003.

The weird part of the issue is that for some printers the print function work perfectly, but for some certain printers, it raises the “The printer output file is empty” error.

Hi,


I have received a .rtf file but there was no console application attached with your email. As soon as we receive it, we will start our investigation into your issue and provide you more information.

Best regards,

Thank you Awais,

I have resent the application through email again, it seems that only one attachment could be added for an email.


Hi,

Thanks for sending your console application. We have found that you’re using a very old version of Aspose.Words i.e. 11.8.0. We suggest you please upgrade to the latest version (14.2.0) from the following link and see how it goes on your end. Hope, this helps.
https://downloads.aspose.com/words/net

Best regards,

I used aspose word v14.2, but got the same result:


I will email you the new test application which used Aspose word v14.2.
Please check the new test application and advise.

Thanks

Hi,

I tested your new project on “2857360tmp.rtf” document and it was printed perfectly fine on various soft printers on my end. Could you please check if the same issue also occurs when printing from Microsoft Word application? Please also try this overloaded print method to try discover if a simple call to Document.Print method causes the same problem.

Best regards,

I will test MS word application.

I double check the folder of prn file printed to, in the folder, there is the prn file with the same name typed during the test, but the prn file size is 0kb.

Also please double check the error message:

System.ComponentModel.Win32Exception (0x80004005): A StartDocPrinter call was not issued 
at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e) 
at System.Drawing.Printing.PrintController.Print(PrintDocument document) 
at System.Drawing.Printing.PrintDocument.Print() 
at Aspose.Words.Document.Print(PrinterSettings printerSettings, String documentName) 

Are those error familiar to you?

Thanks

Hi,


For the sake of any correction(s) in Aspose.Words API, I have logged an issue in our issue tracking system. The ID of this issue is WORDSNET-9922. Our development team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Thank you.

How will i get the updates? In this post or get email?

Hi,


Thanks for your inquiry. Our development team has started doing analysis of this issue. We will keep you posted (via this thread) of any updates.

Best regards,

Hi,

Please share if the problem happens only with .rtf document or with .doc and .docx as well? Does this problem also occur when using a blank document?

Secondly, it seems this is a bug in .NET printer area. Please find attached “SimplePrintDocument” class. To determine if this issue is because of Aspose.Words or with .NET framework itself, please try doing the following steps:

  1. Add “SimplePrintDocument.cs” class in your application.
  2. Instead of code “document.Print(printerSettings, docName)”, please use the following code:
SimplePrintDocument simplePrintDocument = new SimplePrintDocument("text");
simplePrintDocument.PrinterSettings = printerSettings;
simplePrintDocument.Print();

Please let us know if the above code still throws the same exception.

Best regards,

The issue does not only happen on .rtf file, I just created a new blank .doc file and test with the application, raise the same error as well.

I will create the test application with the “SimplePrintDocument” class to test, and will update you with the test result.

Thanks

Tested the above codes, the application raised the same error.

Thanks

Tested the “SimplePrintDocument” class on client site, it raised the same error.

Do you have any suggestion on next step issue investigation?

Thanks

Hi,

Thanks for the details. We will check this further and get back to you soon. Also, a quick search in Google reveals some links similar to your problem. Please check if they help:
https://social.technet.microsoft.com/Forums/windows/en-US/1dcc2606-b21d-4141-998c-2f371dd62fba/error-startdocprinter-call-was-not-issued

Best regards,

Hi,

I have checked the links, but it seems not the case of this issue, let me provide some more information:

The issued printers do not have password protected, and files(no matter .rtf or doc or others formats) can be printed out correctly through the printers when we print the files from MS word, or our another software which is developed in Delphi.

In addition, if we connected to some other printers, printing from our .NET application did not raise the error as well.

Comparing the setting of the issued printers and correct ones, the only different is the printer model. The issued printers are “all-in-one” units, and we have tried multiple drivers downloads form internet/manufacturer, with no luck printing through the .NET application.

Thanks

Hi,


Thanks for the additional information. SimplePrintDocument is not a part of Aspose.Words API and since the exception still occurs when using SimplePrintDocument, we believe this is some problem with .NET framework itself. Our development team has completed the analysis of this issue and has come to a conclusion that this issue you’re observing with a particular printer is actually not a bug in Aspose.Words. So, we will most likely close this issue as ‘Not a Bug’. We apologize for any inconvenience.

Best regards,