Created
November 6, 2010 12:58
-
-
Save aont/665397 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using PdfSharp.Pdf; | |
using PdfSharp.Drawing; | |
using PdfSharp; | |
using System.Reflection; | |
using System.IO; | |
using System.Windows.Forms; | |
namespace Images2PDF | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string SavePath = new FileInfo(Application.ExecutablePath).DirectoryName + "\\Images.pdf"; | |
using (PdfDocument Document = new PdfDocument()) | |
{ | |
foreach (string ImagePath in args) | |
{ | |
Console.WriteLine(ImagePath); | |
PdfPage page = Document.AddPage(); | |
page.Size = PageSize.A4; | |
using (XImage image = XImage.FromFile(ImagePath)) | |
{ | |
//page.Width = image.PointWidth; | |
//page.Height = image.PointHeight; | |
using (XGraphics gfx = XGraphics.FromPdfPage(page)) | |
{ | |
double Height = image.PointHeight * page.Width / image.PointWidth; | |
if (Height < page.Height) | |
gfx.DrawImage(image, 0, (page.Height - Height) / 2, page.Width, Height); | |
else | |
{ | |
double Width = image.PointWidth * page.Height / image.PointHeight; | |
gfx.DrawImage(image, (page.Width - Width) / 2, 0, Width, page.Height); | |
} | |
} | |
} | |
} | |
Document.Save(SavePath); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment