Add controls in pdf or print as it looks
C#
1
Posts
1
Posters
0
Views
1
Watching
-
Hi guys. I have created a form where I included a tabcontrol. In this object I have an tabpage where I inserted multiple data as labels, textboxes, checkboxes and its format is as a contract. Well, I want to print this tabpage or to create a pdf file only with that tabpage. I managed to create a print and a print view with some functions that I found on other sources, but it doesn't create new pages when I print the form. I have created an OXPS file and the result is not the best. I mean, it creates only one page which includes all tabpage content, but the content is large so it would be needed more pages (A4 format). This is the source code:
public Form1()
{
InitializeComponent();
}
Bitmap MemoryImage;
Control panel = null;private void button1\_Click(object sender, EventArgs e) { try { Print(tabPage2); } catch (Exception exp) { MessageBox.Show("Error: \\n" + exp.Message); } } private void printDocument1\_PrintPage(object sender, PrintPageEventArgs e) { Rectangle pageArea = e.PageBounds; Rectangle m = e.MarginBounds; if ((double)MemoryImage.Width / (double)MemoryImage.Height > (double)m.Width / (double)m.Height) // image is wider { m.Height = (int)((double)MemoryImage.Height / (double)MemoryImage.Width \* (double)m.Width); } else { m.Width = (int)((double)MemoryImage.Width / (double)MemoryImage.Height \* (double)m.Height); } e.Graphics.DrawImage(MemoryImage, m); } public void Print(Control pnl) { DateTime saveNow = DateTime.Now; string datePatt = @"yyyy-M-d\_hh-mm-ss tt"; panel = pnl; GetPrintArea(pnl); printDialog1.AllowSomePages = true; printDocument1.PrintPage += new PrintPageEventHandler(Print\_Details); printDialog1.Document = printDocument1; printDialog1.Document.DocumentName = "Document Name"; //printDialog.ShowDialog(); if (printDialog1.ShowDialog() == DialogResult.OK) { printDocument1.Print(); } } public void PrintPreview(Control pnl) { DateTime saveNow = DateTime.Now; string datePatt =