PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

RTF Document and Images from memory
http://forum.pdfsharp.com/viewtopic.php?f=2&t=3973
Page 1 of 1

Author:  jrk [ Tue May 28, 2019 4:11 pm ]
Post subject:  RTF Document and Images from memory

Right off the bat...I'm new to this tool, so just getting started. I've read through some examples and getting started sections. The first thing I'd like to get working is loading several images into a migradoc rtf document, where those images are in memory. I've tried using the example I found, but I'm sure I'm making assumptions and or not doing this correctly.

We are using a 3rd party software which visualized dashboard graphs/objects.
This 3rd party software has a pretty extensive api, part of which allows me to export a byte array from the objects of varying types within the dashboard.
I can use FileStream to manually create individual files, each representing an image, or rtf table, of an object within the dashboard.
For exporting image byte arrays, using FileStream is successful in creating either .png or .bmp files.
For exporting rtf table byte arrays, using FileStream is successful in creating .rtf files.

We'd rather not write to disk each file first. So, I'm trying the following:

DEFINE VARIABLE oDocument AS MigraDoc.DocumentObjectModel.Document NO-UNDO.
DEFINE VARIABLE oSection AS MigraDoc.DocumentObjectModel.Section NO-UNDO.
DEFINE VARIABLE lcImage AS LONGCHAR NO-UNDO.
DEFINE VARIABLE oRTFRender AS MigraDoc.RtfRendering.RtfDocumentRenderer NO-UNDO.
DEFINE VARIABLE ObjectBytes AS CLASS "System.Byte[]" NO-UNDO.

oDocument = NEW MigraDoc.DocumentObjectModel.Document().

Coding loops through a collection of image byte arrays. For each image, the following takes place:

lcImage = "base64:" + System.Convert:ToBase64String(ObjectBytes).
oSection = oDocument:AddSection().
oSection:AddImage(lcImage).

After loop above completes for each image...
oRender = NEW MigraDoc.RtfRendering.RtfDocumentRenderer().
oRender:Render(oDocument, "C:\temp\finaldocument.rtf", ?).
System.Diagnostics.Process:Start("C:\temp\finaldocument.rtf":U").


The result is a blank rtf document.

Hopefully something above points to glaring issues that someone can kindly assist me with...

Thanks

Author:  Thomas Hoevel [ Tue May 28, 2019 4:54 pm ]
Post subject:  Re: RTF Document and Images from memory

Hi!

The bad news: BASE64-encoded images are not yet supported by the RTF renderer.
Your code should work for PDF, but AFAIK you still have to create temporary files for RTF - or update the RTF renderer to support BASE64.

I'm sorry for the inconvenience.

Author:  jrk [ Tue May 28, 2019 5:00 pm ]
Post subject:  Re: RTF Document and Images from memory

Thank you Thomas...At this stage I'm just happy to know I can stop banging my head against the way.

Author:  jrk [ Tue May 28, 2019 5:09 pm ]
Post subject:  Re: RTF Document and Images from memory

I replied to quickly, as I'm not sure I follow you response.

My coding using Convert.ToBase64String(byte array) came from your samples.

http://www.pdfsharp.net/wiki/MigraDoc_F ... ?HL=images

My apology if I've misunderstood Thomas.

Author:  jrk [ Tue May 28, 2019 5:10 pm ]
Post subject:  Re: RTF Document and Images from memory

Ok...so I need another cup of coffee. My apologies.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/