Trying to use version MigraDoc 1.50.5147.0 to embed a gif logo into a RTF document. Used the readily available examples and it's working for PDF but not when I render a RTF.
static string MigraDocFilenameFromByteArray(byte[] image) { return "base64:" + Convert.ToBase64String(image); }
void LoadLogo() { byte[] imageArray = Library.Helpers.FileUtils.ReadFile(LogoFilename); string strEmbeddedImage = MigraDocFilenameFromByteArray(imageArray); CurrentDocument.LastSection.Headers.FirstPage.AddImage(strEmbeddedImage); }
public static byte[] ReadFile(string sPath) { //Initialize byte array with a null value initially. byte[] data = null;
//Use FileInfo object to get file size. FileInfo fInfo = new FileInfo(sPath); long numBytes = fInfo.Length;
//Open FileStream to read file FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
//Use BinaryReader to read file stream into byte array. BinaryReader br = new BinaryReader(fStream, Encoding.Default);
//When you use BinaryReader, you need to supply number of bytes to read from file. //In this case we want to read entire file. So supplying total number of bytes. data = br.ReadBytes((int)numBytes);
//Close BinaryReader br.Close();
//Close FileStream fStream.Close();
return data; }
|