How to print two images on two different pages at once?

Asked

Viewed 137 times

0

Hello!

I can print a panel (pnlPrint) using the following code. But, I am not able to print a datagridview that already belongs to the same form together, on the second page so that the two leave in the same print. I could make two different buttons to print the two separate panels, but I need the two panels to come out in the same print because the user can choose the PDF printer and thus generate a two-page file.

   void Imprimir()
    {
        PrintDocument pd = new PrintDocument();
        pd.DocumentName = "Relatório SisIndice";
        pd.PrintPage += new PrintPageEventHandler(doc_PrintPage);
        pd.DefaultPageSettings.Landscape = true;
        PrintDialog printDialog1 = new PrintDialog();
        printDialog1.Document = pd;
        DialogResult result = printDialog1.ShowDialog();
        if (result == DialogResult.OK)
        {
            pd.Print();
        }
    }

    private void doc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        Bitmap bmp = new Bitmap(pnlPrint.Width, pnlPrint.Height, pnlPrint.CreateGraphics());
        pnlPrint.DrawToBitmap(bmp, new Rectangle(0, 0, pnlPrint.Width, pnlPrint.Height));
        RectangleF bounds = e.PageSettings.PrintableArea;
        float factor = ((float)bmp.Height / (float)bmp.Width);
        e.Graphics.DrawImage(bmp, bounds.Left, bounds.Top, 1118, 855);


    Bitmap bmp1 = new Bitmap(dgvDetGraf.Width, dgvDetGraf.Height, dgvDetGraf.CreateGraphics());
        dgvDetGraf.DrawToBitmap(bmp1, new Rectangle(0, 0, dgvDetGraf.Width, dgvDetGraf.Height));
        RectangleF bounds1 = e.PageSettings.PrintableArea;

        e.Graphics.DrawImage(bmp1, bounds1.Left, bounds1.Top, 1118, 855);

        e.HasMorePages = false;

    }
  • One appears superimposed on the other. ?

1 answer

0

  • It would be interesting then you reproduce the answer here, instead of just leaving link. It becomes easier to see the solution and makes your answer here independent of the answer from it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.