Free Support Forum - aspose.com

Shift left

int width = (int)(210 * 25.4 * 72);
int height = (int)(297 * 25.4 * 72);

pgs.PaperSize = new System.Drawing.Printing.PaperSize(“A4”, width, height);
//pgs.PaperSize = new System.Drawing.Printing.PaperSize(“A4”, 827, 1169);

// Set PageMargins (if required)
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
if (printDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ps = printDialog.PrinterSettings;
ps.Copies = m;
//ps.PrinterName = ps.PrinterName;

    // Document printing code goes here
    // Print document using printer and page settings
    viewer.PrintDocumentWithSettings(pgs, ps);

}

Question:

  • As shown in the attached PDF file, the printing is shifted to the left. How can I fix it?
    shiftleft.jpg (86.2 KB)

@hbhur102

Thank you for contacting support.

Would you please share the source PDF file with us so that we may try to reproduce and investigate it in our environment to help you out.

This is my document…test.pdf (386.5 KB)

@hbhur102

We have modified you code snippet to make it work in a console application in our environment. You need to resize the contents with AutoResize property. Please try using below code snippet in your environment and then share your kind feedback with us.

    System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
    System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
    PdfViewer viewer = new PdfViewer();
    viewer.BindPdf(dataDir + "test.pdf");
    int width = (int)(210 * 25.4 * 72);
    int height = (int)(297 * 25.4 * 72);

    pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", width, height);
    //pgs.PaperSize = new System.Drawing.Printing.PaperSize(“A4”, 827, 1169);

    // Set PageMargins (if required)
    pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
    ps.Copies = 1;
    ps.PrinterName = "Microsoft Print to PDF";
    viewer.AutoResize = true;
    viewer.PrintDocumentWithSettings(ps);

We hope his will be helpful. Please fill free to contact us if you need any further assistance.