I am trying to print my active form to PDF. I have successfully printed it but I can't change it to fit/stretched the whole page of the PDF document.
Below is the code that I've used.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// additional namespaces
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Drawing.Printing;
using Microsoft.Win32;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Button printButton = new Button();
private PrintDocument printDocuments1 = new PrintDocument();
public Form1()
{
InitializeComponent();
printButton.Click += new EventHandler(button12_Click);
printDocuments1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
}
Bitmap memoryImages;
private void CaptureScreens()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
memoryImages = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImages);
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
}
private void printDocument1_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImages, 0, 0);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button12_Click(object sender, EventArgs e)
{
CaptureScreens();
printDocuments1.Print();
}
}
}
Can anyone help me on how to do the resize of image to fit the whole PDF document? Thank you very much for the help.