I am having trouble converting a set of PNG's to one pdf document. Right now I am using PDFSharp and the code works but it is inefficient. I want to use Aspose because I use it for other things and it is way faster but I cannot get it working. Here is the code I am currently using:
public class PdfCreator {
///
/// Creates a PDF document of a presentation’s images.
///
/// The output path.
/// The image paths.
public void CreatePdfOfImages(string outputPath, string[] imagePaths) {
//creates a new pdf document
var pdf = new PdfDocument( );
//sets the title and author for this pdf
pdf.Info.Title = “Presentation”;
pdf.Info.Author = “Me”;
const double dx = 800, dy = 600;
//loops through each img in the presentation
for (int i=0; i<imagePaths.Length; ++i) {
//adds a new page to the pdf document
var page = pdf.AddPage();
//sets the page orientation to landscape
page.Orientation = PdfSharp.PageOrientation.Landscape;
XGraphics gfx = XGraphics.FromPdfPage(page);
using (PdfSharp.Drawing.XImage image = PdfSharp.Drawing.XImage.FromFile(imagePaths[i])) {
double width = image.PixelWidth * 48 / image.HorizontalResolution;
double height = image.PixelHeight * 48 / image.HorizontalResolution;
image.Interpolate = false;
gfx.DrawImage(image, (dx - width) / 2, 36, width, height);
}
}
pdf.Save(outputPath);
}
}