So I'm sure other people are curious about this because I can't be the only one who was trying to do it. But I figured it out, from tweaking some sample code I found online. Maybe someone could add this as a method into the code because it really should be something that is in pdfSharp by default:
Code:
var context = ControllerContext.HttpContext;
string tempPath = "" + context.Request.Url;
string path = tempPath.Replace("" + context.Request.Path, "");
const int BYTESTOREAD = 10000;
WebRequest myRequest = WebRequest.Create(path + "/Content/Images/pdf/logoTop.png");
WebResponse myResponse = myRequest.GetResponse();
Stream ReceiveStream = myResponse.GetResponseStream();
BinaryReader br = new BinaryReader(ReceiveStream);
MemoryStream memstream = new MemoryStream();
byte[] bytebuffer = new byte[BYTESTOREAD];
int BytesRead = br.Read(bytebuffer, 0, BYTESTOREAD);
while (BytesRead > 0)
{
memstream.Write(bytebuffer, 0, BytesRead);
BytesRead = br.Read(bytebuffer, 0, BYTESTOREAD);
}
BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.StreamSource = memstream;
logo.EndInit();
using (XImage imageLogoTop = XImage.FromBitmapSource(logo))
{
imageScaledWidth = imageLogoTop.PixelWidth / 4;
imageScaledHeight = imageLogoTop.PixelHeight / 4;
gfx.DrawImage(imageLogoTop, 465, 20, imageScaledWidth, imageScaledHeight);
}
It actually ended up being a lot more complicated than I expected, but it works.