1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "PDF file|*.pdf", ValidateNames = true })
{
if (sfd.ShowDialog() == DialogResult.OK)
{
iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4.Rotate());
try
{
int width = panelTombi.Size.Width;
int height = panelTombi.Size.Height;
doc.Open();
MemoryImage = new Bitmap(width, height);
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
panelTombi.DrawToBitmap(MemoryImage, new System.Drawing.Rectangle(0, 0, width, height));
iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance((System.Drawing.Image)MemoryImage, System.Drawing.Imaging.ImageFormat.Jpeg);
image1.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
image1.ScaleAbsolute(100f, 100f);
doc.SetMargins(2f, 4f, 3f, 2f);
doc.Add(image1);
doc.NewPage();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
doc.Close();
}
}
} |
Partager