Hem Acharya
Hem Acharya

Reputation: 258

How to send all images of a folder to printer

I need to send all the images in a folder to printer at once. This is possible from windows explorer where we select all the image files, right click and select print to send all the selected images to print dialog from where we can select printer settings and proceed to print. How do I do this from within c# windows form Application?

Edit: I came up with this but it prints only the last page. How should I modify this?

private void printAllCardSheetBtn_Click(object sender, EventArgs e) {

        PrintDocument pdoc = new PrintDocument();
        pdoc.DocumentName = "cardsheets";
        PrintDialog pd = new PrintDialog();
        if(pd.ShowDialog() == DialogResult.OK)
        {

            PrinterSettings ps = pd.PrinterSettings;
            pdoc.PrinterSettings = ps;


            pdoc.PrintPage += pdoc_PrintPage;
            pdoc.Print();
        }



    }

    void pdoc_PrintPage(object sender, PrintPageEventArgs e)
    {
         Graphics g = e.Graphics;
         string[] sheetpaths = Directory.GetFiles(_sheetDirectory);
         Point point = new Point(0, 0);
         foreach (string s in sheetpaths)
         {
             g.DrawImage(new Bitmap(s), point);

         }



    }

Upvotes: 1

Views: 1860

Answers (1)

tweellt
tweellt

Reputation: 2171

You can use PrintDocument.

Just get all images from folder, load them to a Bitmap and through a For Loop use PrintDocument to print one by one.

BTW, use PrintPage event and with PrintPageEventArgs you can draw the image in the document to print with Graphics.

Cheers

EDIT: Check this example -> Example

Upvotes: 0

Related Questions