#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    1
    Rep Power
    0

    C# jpeg file printing


    Pretty new to c#. I have set up print menu. When user prints, the form is saved as a jpeg on the hard drive. How do I print the jpeg from within the application (preferrably without any user interaction)?

    Thanks.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    6
    Rep Power
    0
    An easy way:

    protected void FunctionYouWantToPrint()
    {
    PrintDocument printDoc = new PrintDocument();
    printDoc.DocumentName = "My Print Document";
    printDoc.PrintPage += new PrintPageEventHandler(OnPrintPage);
    // Send print message
    Console.WriteLine("Sending Print Message...");
    try{printDoc.Print();}
    catch(Exception){Console.WriteLine("Error: No Printer Installed");}
    }
    //
    // Event Handler
    //
    void OnPrintPage(object sender, PrintPageEventArgs ppea)
    {
    Console.WriteLine("Printing...");
    Graphics g = ppea.Graphics;
    g.DrawImage(youImage,0,0);
    }


    BTW: How did you save the form as a jpeg, native dll functions?, thats the only way I can do it, the standard Image.Save only saves as a png no matter if you select any other format, IE jpeg or wmf etc...

IMN logo majestic logo threadwatch logo seochat tools logo