hi, i have a panel with controls and richtextbox's within it. When the user clicks the save button, i take panel1 and DrawToBitmap, then add the image to a pdf created using abcPDF7.

My problem is that i have recently change textbox's with richTextBox's to enable the user more functionality, but they are not being rendered into the image.

If i add a normal textbox it works fine, with the exact code, but not with richtextbox.

am i missing something? why would it not render?

Thanks.

Doc myDoc = new Doc();
            myDoc.TopDown = true;
            String myTempPath = Path.GetTempPath();
            const string myFile = "myFile.pdf";
            myDoc.Read(myTempPath + myFile);

            myDoc.MediaBox.String = "A4";
            myDoc.Rect.String = myDoc.MediaBox.String; // <- Important
            myDoc.Page = myDoc.AddPage();

            myDoc.Rendering.AntiAliasImages = true;
            myDoc.Rendering.DotsPerInch = 300;
            myDoc.Rendering.AntiAliasPolygons = true;
            myDoc.Rendering.AntiAliasScene = true;
            myDoc.Rendering.AntiAliasText = true;
            myDoc.Rendering.BitsPerChannel = 8;

            int theID = myDoc.AddObject("<< >>");
            myDoc.SetInfo(-1, "/Info:Ref", theID.ToString());

            myDoc.SetInfo(theID, "/Title:Text", richTextBox1.Text + " Product Brochure");
            myDoc.SetInfo(theID, "/Author:Text", "Chehade Real Estate Group");
            myDoc.SetInfo(theID, "/Subject:Text", "Inhouse Documentation");
            myDoc.SetInfo(theID, "/Creator:Text", "iDocs v1");
            DateTime theDate = DateTime.Now;
            myDoc.SetInfo(theID, "/CreationDate:Text", theDate);
            myDoc.SetInfo(theID, "/Trapped:Name", "False");

            Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);
            bmp.SetResolution(300, 300);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                //Set quality to High
                g.CompositingMode = CompositingMode.SourceCopy;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                panel1.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, 2480, 3508));
            }
            myDoc.AddImage(bmp);
            
            // myDoc.AddImageBitmap(bmp, false);

            try
            {
                using (SaveFileDialog dlgSave = new SaveFileDialog())
                {
                    dlgSave.Title = "Save PDF File";
                    dlgSave.Filter = "PDF File (*.pdf)|*.pdf|All Files (*.*)|*.*";
                    if (dlgSave.ShowDialog(this) == DialogResult.OK)
                    {
                        myDoc.Save(dlgSave.FileName);
                        Process.Start(dlgSave.FileName);
                    }
                }
            }
            finally
            {
                bmp.Dispose();
                myDoc.Clear();
            }

MSDN Documentation wrote:
DrawToBitmap does not draw a child TextBox if the Visible property of the TextBox is set to false.
Controls inside containers are rendered in reverse order.
DrawToBitmap is not fully functional for the RichTextBox; only the border of a bitmap is drawn.

So that is why RTB are not being rendered, but does anyone know another method of capturing the panel?

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.