PDFsharp & MigraDoc Foundation

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

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: Tue May 28, 2019 4:11 pm 
Offline

Joined: Tue May 28, 2019 3:53 pm
Posts: 6
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


Top
 Profile  
Reply with quote  
PostPosted: Tue May 28, 2019 4:54 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue May 28, 2019 5:00 pm 
Offline

Joined: Tue May 28, 2019 3:53 pm
Posts: 6
Thank you Thomas...At this stage I'm just happy to know I can stop banging my head against the way.


Top
 Profile  
Reply with quote  
PostPosted: Tue May 28, 2019 5:09 pm 
Offline

Joined: Tue May 28, 2019 3:53 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue May 28, 2019 5:10 pm 
Offline

Joined: Tue May 28, 2019 3:53 pm
Posts: 6
Ok...so I need another cup of coffee. My apologies.


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 163 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group