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