private void SaveButton_Click(object sender, EventArgs e) { PdfDocument doc = new PdfDocument(); PdfImage pdfImage = PdfImage.FromImage(documentWrapper.Image); PdfUnitConvertor uinit = new PdfUnitConvertor(); SizeF pageSize = uinit.ConvertFromPixels(documentWrapper.Image.Size, PdfGraphicsUnit.Point); PdfPageBase page = doc.Pages.Add(pageSize, new PdfMargins(0f)); page.Canvas.DrawImage(pdfImage, new PointF(0, 0)); doc.SaveToFile(path.Insert(path.LastIndexOf(".pdf"), "_converted")); isSaved = true; }
private PdfDocument BitmapToPdf(Bitmap bitmap) { PdfDocument doc = new PdfDocument(); PdfImage pdfimage = PdfImage.FromImage(bitmap); PdfUnitConvertor uinit = new PdfUnitConvertor(); SizeF pageSize = uinit.ConvertFromPixels(bitmap.Size, PdfGraphicsUnit.Point); PdfPageBase page = doc.Pages.Add(pageSize, new PdfMargins(0f)); page.Canvas.DrawImage(pdfimage, new PointF(0, 0)); return(doc); }
private void SaveAsButton_Click(object sender, EventArgs e) { PdfDocument doc = new PdfDocument(); PdfImage pdfImage = PdfImage.FromImage(documentWrapper.Image); PdfUnitConvertor uinit = new PdfUnitConvertor(); SizeF pageSize = uinit.ConvertFromPixels(documentWrapper.Image.Size, PdfGraphicsUnit.Point); PdfPageBase page = doc.Pages.Add(pageSize, new PdfMargins(0f)); page.Canvas.DrawImage(pdfImage, new PointF(0, 0)); using var sfd = new SaveFileDialog(); sfd.InitialDirectory = Environment.SpecialFolder.Desktop.ToString(); sfd.RestoreDirectory = true; sfd.CheckPathExists = true; sfd.AddExtension = true; sfd.DefaultExt = "pdf"; sfd.Filter = "PDF|*.pdf"; var result = sfd.ShowDialog(); if (result == DialogResult.OK) { doc.SaveToFile(sfd.FileName); } isSaved = true; }