Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source file is correct, actual print is moved to the right and bottom using system.drawing printing

I've inherited an application created by people who are no longer working for my employer and I'm looking into a printing issue where the output (slightly) falls off the page.

It should be:

enter image description here

But it comes out like this:

enter image description here

I've added the black borders for legibility on this page.

So as you can see, the print is shifted slightly to the right and to the bottom, so that it surpasses the allowed boundaries.

My question

I'm going through the code, looking for options that may cause this, but I'm drawing a blank right now.

Option A (ideal solution):

Any ideas on what may be causing this shift to the right-bottom?

Option B

Any idea how I can shrink the scaling of what's being printed, so that the content no longer falls off the page?

Let me know if you need code to help clear out what's going on (I can't narrow things down enough up front to post any).

like image 228
Spikee Avatar asked Sep 18 '18 07:09

Spikee


1 Answers

Since you didn't published your code, It's a bit harder to answer your question but here are 2 solutions to your problem:

on your System.Drawing.Printing.PrintDocument class, override the default OnPrintPage and change the page margins:

protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
{
    base.OnPrintPage(e);
    // Create a new instance of Margins with 1-inch margins.
    e.PageSettings.Margins = new System.Drawing.Printing.Margins(100, 100, 100,100);
}

you can read more about the Margins property in here

you can also play with the settings in the follow way:

        protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
        {
            // Run base code
            base.OnPrintPage(e);

            //Declare local variables needed

            int printHeight;
            int printWidth;
            int leftMargin;
            int rightMargin;
            Int32 lines;
            Int32 chars;

            //Set print area size and margins
            {
                printHeight = base.DefaultPageSettings.PaperSize.Height - base.DefaultPageSettings.Margins.Top - base.DefaultPageSettings.Margins.Bottom;
                printWidth = base.DefaultPageSettings.PaperSize.Width - base.DefaultPageSettings.Margins.Left - base.DefaultPageSettings.Margins.Right;
                leftMargin = base.DefaultPageSettings.Margins.Left;  //X
                rightMargin = base.DefaultPageSettings.Margins.Top;  //Y
            }
        }

you should read that following guide to learn and change it to fit your own needs

like image 123
Or Yaacov Avatar answered Sep 20 '22 07:09

Or Yaacov