In .net framework, we were using Aspose to print a docx. That was working fine for us. When we moved to .net core, Aspose did not have the support to print a document. Aspose support team told us a work around where we have to convert each page to a PNG format and then send to a printer. Looks like due to this conversion, our clients are seeing a difference in quality. The quality that was generated by .net framework code was better. Following is the Code you guys provided.
Does Aspose support printing in a newer version?
private void PrintPage(object o, PrintPageEventArgs e)
{
try
{
using (MemoryStream pageImageStream = new MemoryStream())
{
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
//options.PageCount = 1;
//options.PageIndex = mPageIndex;
options.PageSet = new PageSet(mPageIndex);
mDoc.Save(pageImageStream, options);
pageImageStream.Position = 0;
using (Image pageImage = Image.FromStream(pageImageStream))
{
e.Graphics.DrawImage(pageImage, new Point(0, 0));
}
// Increase page index and check if there are more pages.
mPageIndex++;
e.HasMorePages = (mPageIndex < mDoc.PageCount);
}
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
// Stop printing in case of errors.
e.HasMorePages = false;
}
}
public void Print(Aspose.Words.Document doc, string printerName)
{
mDoc = doc;
mPageIndex = 0;
using (PrintDocument pd = new PrintDocument())
{
pd.PrinterSettings.PrinterName = printerName;
pd.PrintPage += PrintPage;
pd.Print();
}
}