Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Add controls in pdf or print as it looks

Add controls in pdf or print as it looks

Scheduled Pinned Locked Moved C#
graphicshelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DPaul1994
    wrote on last edited by
    #1

    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 =
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups