We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose PDF not printing correctly

I have several Word documents that I need to print using Aspose WORDS or Aspose PDF. I have tried the following methods.

Method 1. Print from Aspose WORDS. Prints OK. I can set duplex, color, but the paper size and orientation are ignored. It always prints A4 and Portrait, even though all the PrinterSettings values seem to be OK.
Method 2. Convert to PDF and print using Aspose PDF. I can set page size, orientation, duplex,color. If I set AutoResize=true the printed page is re-sized much too small. When AutoResize=false the printing overflows the page. Left margin is large and the right side is missing.

If I print the same converted PDF from MS Word or from Adobe Reader it prints fine, no problems.

I need a solution using either Aspose WORDS or Aspose PDF that
1. Prints the file correctly on the page
2. Allows me to set page size (A4, A3 etc), Orientation, Duplex, color
Any suggestions?
The two files are attached. SampleDoc1W.doc is the original Word Document. SampleDoc1.PDF is the same document converted to PDF by Aspose Words

Hi Peter,

Can you please share your complete code and the versions of Aspose.Words and Aspose.Pdf are you using?

Best Regards,

We are using Aspose Pdf v 9.0.0 and Aspose Word 14.2.0

Here is some sample code tp print the PDF file. It works except for the printed page being re-sized too small when AutoResize=true, and too big when AutoResize=false

public class PrinterDoc
{
private string DocName;
private string PrinterName;
private string ResultMsg;
private int PrintMode; //1=Print 2=Convert 3=Convert+Print
private int PrintColor; //1=B&W, 2=Color
private int PageOrientation; //1=Portrait 2=Landscape
private int PageDuplex; // 1=Simplex 2=Duplex
private string PaperSize;
private string InputTray;
}


public bool PrintPdfFile(PrinterDoc pD)
{
try
{
PdfViewer viewer = new PdfViewer();
Aspose.Pdf.Document document = new Aspose.Pdf.Document(pD.DocName);
viewer.BindPdf(document);
viewer.AutoResize = true; //false; //tried it both ways
viewer.AutoRotate = false; // true; // tried it both ways
viewer.PrintPageDialog = false;

System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
System.Drawing.Printing.PageSettings pa = new System.Drawing.Printing.PageSettings();
ps.PrinterName = pD.PrinterName;
// set PrinterSettings
if (ps.CanDuplex)
{
if (pD.PageDuplex == 1)
ps.Duplex = Duplex.Simplex;
else if (pD.PageDuplex == 2)
ps.Duplex = Duplex.Vertical; //test case
else
ps.Duplex = Duplex.Simplex;
}
if (ps.SupportsColor)
ps.DefaultPageSettings.Color = pD.PrintColor == 2?true:false;
ps.DefaultPageSettings.Landscape = pD.PageOrientation == 2? true:false;
if(!string.IsNullOrEmpty(pD.InputTray))
ps.DefaultPageSettings.PaperSource.SourceName = pD.InputTray;
// set PaperSize
if(!string.IsNullOrEmpty(pD.PaperSize))
{
foreach (System.Drawing.Printing.PaperSize size in ps.PaperSizes)
if (size.Kind.ToString().ToUpper() == pD.PaperSize)
{
pa.PaperSize = size;
break;
}
}
viewer.PrintDocumentWithSettings(pa, ps);
viewer.Close();
return true;
}//try

catch (Exception ex)
{
string strError = ex.Message;
return false;
}
}


grazm:
2. Convert to PDF and print using Aspose PDF. I can set page size, orientation, duplex,color. If I set AutoResize=true the printed page is re-sized much too small. When AutoResize=false the printing overflows the page. Left margin is large and the right side is missing
Hi Peter,

Thanks for sharing the code snippet.

I
have tested the scenario using Aspose.Pdf for .NET 9.3.0 and have managed to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as PDFNEWNET-37098. We will
investigate this issue in details and will keep you updated on the status of a
correction. <o:p></o:p>

We apologize for your inconvenience.