PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 8:56 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Jan 01, 2021 2:14 pm 
Offline

Joined: Sun Aug 26, 2012 2:34 pm
Posts: 15
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;
}


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 04, 2021 9:19 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
RTFM: BASE64 works for PDF, but not yet for RTF. Just use normal images from files.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 04, 2021 11:52 am 
Offline

Joined: Sun Aug 26, 2012 2:34 pm
Posts: 15
The RTF is generated on a web server thru a web service and downloaded to the client. When the images are added to the RTF, the image is missing when downloaded. I was hoping to embed the image in the RTF like the PDF.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 04, 2021 5:10 pm 
Offline

Joined: Sun Aug 26, 2012 2:34 pm
Posts: 15
I separated the logic between the PDF & RTF generation and the image is now appearing in the downloaded RTF document.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 05, 2021 12:09 pm 
Offline

Joined: Sun Aug 26, 2012 2:34 pm
Posts: 15
Although I'm now able to embed the logo image in the PDF, I've lost the ability to position the image on the header, either left, right or center. How can I add positioning to the image i'm embedding?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 133 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group