Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Printing an image in the middle of a page

Printing an image in the middle of a page

Scheduled Pinned Locked Moved C#
graphicshelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devzav
    wrote on last edited by
    #1

    Hi all! I can't make an image is printed in the middle of a page. I use this code:

    printDocument = new PrintDocument();
    printDocument.OriginAtMargins = true;

    printDocument.DefaultPageSettings.Margins = new margins((int)printDocument.DefaultPageSettings.HardMarginX,
    (int)printDocument.DefaultPageSettings.HardMarginX, (int)printDocument.DefaultPageSettings.HardMarginY,
    (int)printDocument.DefaultPageSettings.HardMarginY);

    x = xCenter;
    y = yCenter;

    x -= MeasureConverter.FromUnitToUnit(UnitOfMeasurement.Inches, UnitOfMeasurement.Millimeters,
    printDocument.DefaultPageSettings.HardMarginX / 100);
    y -= MeasureConverter.FromUnitToUnit(UnitOfMeasurement.Inches, UnitOfMeasurement.Millimeters,
    printDocument.DefaultPageSettings.HardMarginY / 100);
    ...

    X and Y are given in millimeters, and in my printDocument_PrintPage method I have:

    Graphics g = e.Graphics;
    g.PageUnit = GraphicsUnit.Millimeter;
    g.DrawImage(printableObj.GetMetafileImage(), x, y);
    g.Dispose();
    e.HasMorePages = false;

    Unfortunately my image is printed not exactly in the center... Can you help me, pls? Thnks in advantage.

    P 1 Reply Last reply
    0
    • D devzav

      Hi all! I can't make an image is printed in the middle of a page. I use this code:

      printDocument = new PrintDocument();
      printDocument.OriginAtMargins = true;

      printDocument.DefaultPageSettings.Margins = new margins((int)printDocument.DefaultPageSettings.HardMarginX,
      (int)printDocument.DefaultPageSettings.HardMarginX, (int)printDocument.DefaultPageSettings.HardMarginY,
      (int)printDocument.DefaultPageSettings.HardMarginY);

      x = xCenter;
      y = yCenter;

      x -= MeasureConverter.FromUnitToUnit(UnitOfMeasurement.Inches, UnitOfMeasurement.Millimeters,
      printDocument.DefaultPageSettings.HardMarginX / 100);
      y -= MeasureConverter.FromUnitToUnit(UnitOfMeasurement.Inches, UnitOfMeasurement.Millimeters,
      printDocument.DefaultPageSettings.HardMarginY / 100);
      ...

      X and Y are given in millimeters, and in my printDocument_PrintPage method I have:

      Graphics g = e.Graphics;
      g.PageUnit = GraphicsUnit.Millimeter;
      g.DrawImage(printableObj.GetMetafileImage(), x, y);
      g.Dispose();
      e.HasMorePages = false;

      Unfortunately my image is printed not exactly in the center... Can you help me, pls? Thnks in advantage.

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      Do you have this working yet?

      "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

      D 1 Reply Last reply
      0
      • P Paul Conrad

        Do you have this working yet?

        "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

        D Offline
        D Offline
        devzav
        wrote on last edited by
        #3

        I still have this problem...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups