Is there any special config for printing of browsers?

40 Views Asked by At

I'm using EasyHook to do dll injection to inject gdi32.dll to other processes then i can use it's EndPage function to add a rectangle to printing document.

This is my code to inject dll:

[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
private delegate int EndPageDelegate(IntPtr hdc);

// Hook the EndPage function
LocalHook _endPageHook = LocalHook.Create(
LocalHook.GetProcAddress(Gdi32Dll, "EndPage"),
new EndPageDelegate(EndPageHook),this);

And this is my EndPageHook function to draw rectangle to fit a4 page size on printing document:

[DllImport(Gdi32Dll, CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int EndPage(IntPtr hdc);

private int EndPageHook(IntPtr hdc)
{
   System.Drawing.Graphics e = System.Drawing.Graphics.FromHdc(hdc);
   e.PageUnit = GraphicsUnit.Millimeter;
   int a4Width = 210;
   int a4Height = 297;

   Pen pen = new Pen(Color.Blue, 2);
   Rectangle rectangle = new Rectangle(0, 0, a4Width, a4Height);
   e.DrawRectangle(pen, rectangle);
   // Call the original EndPage function
   return EndPage(hdc);
}

Problem: When i do printing by desktop application like docx, powerpoint, excel, etc... the rectangle is correct size but when i do printing by browsers like edge, chrome, the square looks like be zoomed in a lot. Is there any special config on browsers printing?

Rectangle printed by docx Rectangle printed by chrome

Hope everyone can help me to figure out what's the main problem

0

There are 0 best solutions below