我正在尝试将我的活动表单打印到PDF。我已成功打印了它,但我无法更改它以适合/拉伸PDF文档的整个页面。
以下是我使用的代码。
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();
}
}
}
任何人都可以帮我解决如何调整图像大小以适应整个PDF文档的问题吗?非常感谢您的帮助。