Free Support Forum - aspose.com

Print PDF document using Aspose.PDF for .NET - File is not printing on center

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)

@ikramshams,

Can you please share generated result with us along with comparison screenshot so that we may further investigate to help you out.

I am attaching two Files. One is directly By Program and one is after replacing the text using asppse.pdf i am opening the file Adobe Acrobat(It is printing fine).

PrintByProgram.pdf (259.5 KB)
PrintByDirectPrinter.pdf (259.7 KB)

@ikramshams,

Thanks for contacting support.

I have observed your issue and like to inform that I have created ticket with ID PDFNET-47668 in our issue tracking system to investigate and resolve this issue as soon as possible. We will share good news with you soon.