I am using ItextSharp Library to generate pdf files on a button click on my SharePoint Site. I want to use a logo on the pdf whose image resides on the Images Folder of Sharepoint. I am unable to do that.
Can someone help me with it.
Below is the code that I am using which is getting the instance from window32 which I dont want.
protected void button1_OnClick(object sender, EventArgs e)
{
Font Arial = FontFactory.GetFont("Arial", 12, BaseColor.GREEN);
Font Verdana = FontFactory.GetFont("Verdana", 16, Font.BOLDITALIC, new BaseColor(125, 88, 15));
string imagepath = SPContext.Current.Web + "/_layouts/Images/Image1.png";
using (var ms = new MemoryStream())
{
using (var document = new Document(PageSize.A4,50,50,15,15))
{
PdfWriter.GetInstance(document, ms);
document.Open();
Paragraph img = new Paragraph();
Image jpg = Image.GetInstance(imagepath); --- Getting an error here stating "Could not find a part of the path 'c:\windows\system32\inetsrv\CustomSystem\_layouts\Images\Image1.png'"
img.Add(jpg );
}
}
}
Please help!
I’m not too familiar with SharePoint development but you’re problem is with this line:
This string must be an absolute path path such as
c:\www\sites\image.png, not a relative one which it is right now. I can tell its relative because when you ask ASP.Net to get something for you but you don’t specify a path it looks in%WINDOWS%.I don’t know how you’re using
SPContext.Current.Webbut according to the docs calling.ToString()on it returns the title of the website which is what would happen if you concatenated it with a string like you are. My guess is that you don’t need that but could be wrong.If the
layoutsfolder is a subfolder of the folder that the file you are working on is in then you should be able to useServer.MapPathto get the absolute path: