I am trying to place image in PDF using XSLT. I have images that are already displayed but in that case I have the bytecode initially and I simply generate the base64 string. However in the below case I am reading image from the resource file and then trying to change it to base64 but in this case it gives me the following error:
Path exception: this.imageFilePath (first 100 chars):base64:iVBORw0KGgoAAAANSUhEUgAAAFoAAABNCAYAAAAme3MhAAAABGdBTUEAALGPC/xhBQAAHrFJREFUeF7V3AuwrWVdx/Etq
The template used is as follows:
string brandLogoXslt = @"<Paragraph Style=""P"">Some text here:</Paragraph>";
brandLogoXslt += @"<Image><xsl:attribute name=""Filename"">" + MigraDocFilenameFromByteArray(ExtractResource(Business.Properties.Resources.logo)) + "</xsl:attribute></Image>";
genericPlaceholderNodes[i].ParentNode.InnerXml = genericPlaceholderNodes[i].ParentNode.InnerXml.Replace(genericPlaceholderNodes[i].OuterXml, brandLogoXslt);
Code used for changing the image:
private static string MigraDocFilenameFromByteArray(byte[] image)
{
return "base64:" + Convert.ToBase64String(image);
}
public static byte[] ExtractResource(System.Drawing.Image image)
{
MemoryStream ms = new MemoryStream();
image.Save(ms, ImageFormat.Png);
if (ms == null)
return null;
byte[] imageByteArray = ms.ToArray();
return imageByteArray;
}
I already check the base64 string and it is generating the correct image checked online.
Stack trace:
bei MigraDoc.Rendering.ImageRenderer.CalculateImageDimensions()
bei MigraDoc.Rendering.ImageRenderer.Format(Area area, FormatInfo previousFormatInfo)
bei MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel)
bei MigraDoc.Rendering.FormattedCell.Format(XGraphics gfx)
bei MigraDoc.Rendering.TableRenderer.FormatCells()
bei MigraDoc.Rendering.TableRenderer.InitFormat(Area area, FormatInfo previousFormatInfo)
bei MigraDoc.Rendering.TableRenderer.Format(Area area, FormatInfo previousFormatInfo)
bei MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel)
bei MigraDoc.Rendering.FormattedDocument.Format(XGraphics gfx)
bei MigraDoc.Rendering.DocumentRenderer.PrepareDocument()
bei MigraDoc.Rendering.PdfDocumentRenderer.PrepareDocumentRenderer(Boolean prepareCompletely)
bei MigraDoc.Rendering.PdfDocumentRenderer.PrepareRenderPages()
bei MigraDoc.Rendering.PdfDocumentRenderer.RenderDocument()
bei School.DE.WebApplications.SCHDI.Business.NewPDFGenerator.TemplateToPdfTransformerBase.Transform2Pdf(Object data, XslTransform transform, Stream outStrm) in d:\Projects\Business\NewPDFGenerator\TemplateToPdfTransformerBase.cs:Zeile 70.