|
11 | 11 | using System.Text.RegularExpressions; |
12 | 12 | using System.Windows.Forms; |
13 | 13 | using PasteIntoFile.Properties; |
| 14 | +using PdfSharp.Drawing; |
| 15 | +using PdfSharp.Pdf; |
14 | 16 |
|
15 | 17 | namespace PasteIntoFile { |
16 | 18 |
|
@@ -66,9 +68,28 @@ public ImageContent(Image image) { |
66 | 68 | Data = image; |
67 | 69 | } |
68 | 70 | public Image Image => Data as Image; |
69 | | - public override string[] Extensions => new[] { "png", "bmp", "emf", "gif", "ico", "jpg", "tif", "wmf" }; |
| 71 | + public override string[] Extensions => new[] { "png", "bmp", "emf", "gif", "ico", "jpg", "pdf", "tif", "wmf" }; |
70 | 72 | public override string Description => string.Format(Resources.str_preview_image, Image.Width, Image.Height); |
71 | 73 | public override void SaveAs(string path, string extension) { |
| 74 | + if (extension == "pdf") { |
| 75 | + // convert image |
| 76 | + var stream = new MemoryStream(); |
| 77 | + Image.Save(stream, ImageFormat.Png); |
| 78 | + stream.Position = 0; |
| 79 | + XImage img = XImage.FromStream(stream); |
| 80 | + // create pdf document |
| 81 | + PdfDocument document = new PdfDocument(); |
| 82 | + document.Info.Creator = Resources.str_main_window_title; |
| 83 | + PdfPage page = document.AddPage(); |
| 84 | + page.Width = XUnit.FromPoint(img.PointWidth); |
| 85 | + page.Height = XUnit.FromPoint(img.PointHeight); |
| 86 | + // insert image and save |
| 87 | + XGraphics gfx = XGraphics.FromPdfPage(page); |
| 88 | + gfx.DrawImage(img, 0, 0); |
| 89 | + document.Save(path); |
| 90 | + return; |
| 91 | + } |
| 92 | + // natively supported formats |
72 | 93 | ImageFormat imageFormat; |
73 | 94 | switch (extension) { |
74 | 95 | case "bmp": imageFormat = ImageFormat.Bmp; break; |
|
0 commit comments