I'm using the PDFsharp
library to do some simple manipulation of PDF files.
I have the following code to copy an image from a folder into an existing PDF
document - it works as expected:
public void AddImagePDF()
{
this.DrawPage(this.PDFdoc.Pages[0]);
this.DrawPage(this.PDFdoc.Pages[1]);
this.DrawPage(this.PDFdoc.Pages[2]);
}
private void DrawPage(PdfPage page)
{
XGraphics gfx = XGraphics.FromPdfPage(page);
DrawPng(gfx);
}
private void DrawPng(XGraphics gfx)
{
XImage imageMu = XImage.FromFile(@"C:\Images\AnImage.png");
double width = imageMu.PixelWidth * 7.0 / imageMu.HorizontalResolution;
double height = imageMu.PixelHeight * 7.0 / imageMu.HorizontalResolution;
gfx.DrawImage(imageMu,500,30,width,height);
this.PDFdoc.Save(this.DestinationFullPath);
}
To make the solution more portable I've moved the image file AnImage.png
into the projects resources - here:
Properties.Resources.AnImage
But what changes do I need to make to the code in order to use the resources file rather than the file saved in the C-Drive?