I am printing pdf A4 Size file by using Aspose.Pdf PdfViewer. I have the problem that Pdf File is not printing on center. It is printing little bit down and little bit right.Please suggest me what i should make changes in my code to print the Pdf File on center. I am attaching that Pdf File.
Below is my code which i am using for printing the Pdf File.
object fileNameSource = FileNameSource;
object fileName = System.IO.Path.GetDirectoryName(System.IO.Path.GetTempPath()) + “\” + DateTime.Now.Ticks.ToString() + “.pdf”;
File.Copy(fileNameSource.ToString(), fileName.ToString(), false);
pdfDocument = new Document(FileNameSource.ToString());
pdfDocument.Save(@fileName.ToString());
Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
viewer.BindPdf(fileName.ToString());
viewer.PrintPageDialog = false;
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
ps.PrinterName = cmbPrinter.Text;
ps.Copies = short.Parse(txtCount.Text.Trim());
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
if (paperType == "A4")
{
if (paperSize == "SIZE1" || paperSize == "SIZE2" || paperSize == "SIZE5" || paperSize == "SIZE6" || paperSize == "SIZE7")
{
pgs.Landscape = true;
}
else
{
pgs.Landscape = false;
}
}
else if (paperType == "Roll")
{
// pgs.Landscape = true;
}
if (paperType == "A4")
{
if (paperSize == "SIZE1")
{
//viewer.AutoResize = true;
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
// pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
}
else if (paperSize == "SIZE3")
{
//pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 5, 0);
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
}
else if (paperSize == "SIZE4")
{
//pgs.Margins = new System.Drawing.Printing.Margins(0, 10, 5, 0);
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
}
else if (paperSize == "SIZE6")
{
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
}
else if (paperSize == "SIZE7")
{
pgs.Margins = new System.Drawing.Printing.Margins(0,0,0,0);
}
else
{
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
}
}
else if (paperType == "Roll")
{
//viewer.AutoResize = true;
//viewer.AutoRotate = true;
//pgs.PaperSize = new System.Drawing.Printing.PaperSize("Roll", 235, 550);
//pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
}
viewer.PrintDocumentWithSettings(pgs, ps);
viewer.Close();
File.Delete(@fileName.ToString());
Size 1 (290 x 150) blank A4.pdf (319.6 KB)