Hello,
I’m having this same problem, but in an odd situation. I use the same code to print a PDF via a FileStream using the Aspose.Pdf.Kit.PdfViewer via an ASP.NET 2.0 C# application and a C# 2.0 Window Service. The process works great via the ASP.NET application, but the Window Service gives me the “Pages are corrupt or too many pages” error. Will this not work for Windows Services? I’m using Aspose.Pdf.Kit v 3.3
Here is my code:
///
/// Prints a pdf document with an already specified printer
///
public static void PrintPdf(Stream fileStream, string printerName)
{
GrabLicense();
PdfViewer viewer = new PdfViewer();
viewer.OpenPdfFile(fileStream);
PrinterSettings ps = new PrinterSettings();
ps.PrinterName = printerName;
viewer.AutoRotate = true;
viewer.PrintDocumentWithSettings(ps);
viewer.ClosePdfFile();
}
using (DataSet dsPdf = PrintingServiceDAO.getImage(printedDocId.ToString()))
{
if (dsPdf.Tables[0].Rows.Count > 0)
{
//Grabs DocumentImage from Database
byte[] pdfByteArray = (byte[])dsPdf.Tables[0].Rows[0][“DOCUMENT_IMAGE”];
if (myByteArray.Length > 0)
{
//Put in MemoryStream
using (MemoryStream msPdf = new MemoryStream(myByteArray))
{
PrintDoc(msPdf, Path.GetExtension(documentName), printerName);
}
}
}
}
private static void PrintDoc(Stream fileStream, string extension, string printerName)
{
try
{
//If PDF - then Re-print, go to general drawer
if (extension.ToLower() == “.pdf”)
{
PrintQueue.PrintPdf(fileStream, PrintQueue.PrinterTypes.PHYSICIAN_STATEMENTS_REPRINT,
Util.ConfigPath + Util.ConfigFileName);
}
else if (extension.ToLower() == “.doc”)
{
if (string.IsNullOrEmpty(printerName))
{
PrintQueue.PrintDoc(fileStream, PrintQueue.PrinterTypes.PHYSICIAN_STATEMENTS,
Util.ConfigPath + Util.ConfigFileName);
}
else
{
//Printer Specified
PrintQueue.PrintDoc(fileStream, printerName);
}
}
}
catch (Exception ex)
{
Util.log.WriteEntry(string.Format(“Error Printing Statement - PrintDoc() Message:{0}”, ex.Message), EventLogEntryType.Information, 554);
}
}