Print positioning operation literacy, print positioning operation literacy

Source: Internet
Author: User

Print positioning operation literacy, print positioning operation literacy

Position Control during printing. I remember that in the past, sometimes my company asked me to use photo shop to make some logos and print them out on a4 paper, or print them out on A4 sticker. My approach was to create a document in photo shop, the size is a4, then the ruler is displayed, and then the Auxiliary Line is compared. In short, the full copy of image A4 will be so big.

The printing in C # is very simple, but what has always plagued me is positioning on paper. In the onprintpage event, the graph object drawstring drawline does not know the standard, although the unit can be obtained in the parameter. This is also related to resolution. The resolution height is small.

Now I need a way to draw a picture on the paper in millimeters, and display the size of the 1 cm mark on the software interface like photo shop, it must be so long to print it on paper. How can I do this? view me.

We will use the virtual printer that comes with the system for testing. First, create a custom size, 10 cm x 10 cm square print area to Open Control Panel devices and printers-Print Server properties. If the xp system is the same, then in the print preferences, set the paper size to the size we just defined.

All know that you can get the print area. PageBounds, but I usually like to use this e. PageSettings. PrintableArea. Let's use the above printer settings to see if there is anything different between them.

The output is 394, but the number of digits after a decimal point is retained more.

 

First, draw a line segment:

1 e.Graphics.DrawLine(Pens.Red, new Point(0, 0), new Point(100, 100));

There are many units about graph, that is, multiple length units. Let's take a look at our

1 GraphicsUnit unit = e.Graphics.PageUnit;

The result is display.

At this point, I finally understand one thing, that is, no matter how many 394 display = 10 cm. The above code e. graphics. drawLine (Pens. red, new Point (0, 0), new Point (100,100); you do not know the number of painting units.

Use the following method to change the unit first.

1 e.Graphics.PageUnit = GraphicsUnit.Millimeter;2 e.Graphics.DrawLine(new Pen(Color.Blue, 0.5f), new Point(0, 0), new Point((int)Math.Sqrt(10000f) - 2, (int)Math.Sqrt(10000f) - 2));


We can see whether it has achieved what we want, but whether the line width has become thicker, because the same amount is the same unit but not the same. Adjust as needed, like this

1 e.Graphics.DrawLine(new Pen(Color.Red, 0.5f), new Point(0, 0), new Point((int)Math.Sqrt(10000f) - 2, (int)Math.Sqrt(10000f) - 2));


Maybe you want to replace the unit Millimeter and then Display, then you can know the ratio between them. However, it is not convenient for e. Graphics. pageunit to always control the Unit during painting. In fact, you can do what you want to do with your current knowledge.

 

The key part comes with a package.

Now we know that the paper is 10 cm x 10 cm. If you do not know it. Let's take a look at the following code to convert the millimeter parameter to a pixel point:

1 // the size of the paper in the unit of 1 inch, 2 float widthMM = papersize. width * 0.254f; 3 float heiMM = papersize. height * 0.254f; 4 5 Point p = new Point (); 6 p. X = (int) (printsize. width/widthMM * mmX); 7 p. Y = (int) (printsize. height/heiMM * Rows); 8 return p;


Why is it multiplied by 0.254? Why is it multiplied by 0.254? Because of this figure:

View the description about paperSize. Width: Get or set the paper Width (in 1 inch ). E. PageSettings. PaperSize indicates the actual size of the paper.
Multiply by 0.254 to get the number of millimeters on the edges of the printed paper, and e. PageSettings. PrintableArea can get the number of splices on the printed edges, which is clear.
Is it OK?

1 e.Graphics.PageUnit = unit;2 e.Graphics.DrawLine(Pens.Green, new Point(0, 0),  3     getScale(e.PageSettings.PaperSize, e.PageSettings.PrintableArea,4    (int)( e.PageSettings.PaperSize.Width * 0.254f)-1,(int)( e.PageSettings.PaperSize.Height * 0.254f)-1));

The display and control on the software interface is very easy. The current knowledge about pixel and millimeter conversion is enough.
This is the result of the last time I did something to show the scale. Drag the label and print it to the paper to map it to the actual size:


The printer cannot be located. What is the problem when the printer runs in disorder?

Do you mean the color drift in the print effect, or is the printer moving too much when it is working? Regardless of the problem, the customer cannot solve it by themselves. We need to seek after-sales support for repair.

I only printed some information on my computer.

1. Copy, paste, set it to a PRN file, and print it;
2. Position the cursor on this page. When printing, select "Current page"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.