Converting rtf data to png

Just downloaded trial version, and developed a routine to load rtf data from a database, and create a png file from that data. However, the png image isn’t an exact duplicate of the rtf, is it possible the issue is coming from the watermark from the trial software, or is there issues creating the png file? Below is my vb.net code


Try
Dim buffer() As Byte
Dim newStream As System.IO.MemoryStream
WriteToLog(“Value 2 : " + dsCurr.Tables(0).Rows(0)(“Value”))
buffer = System.Text.Encoding.UTF8.GetBytes(dsCurr.Tables(0).Rows(0)(“Value”))
newStream = New System.IO.MemoryStream(buffer)
Dim myDoc As New Aspose.Words.Document(newStream)
Dim options = New Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png)
options.Resolution = 96

For i As Integer = 0 To (myDoc.PageCount - 1)
options.PageIndex = i
myDoc.Save(String.Format(“NewImage2.png”, i), options)
Next

Dim imgCurr As Image

imgCurr = System.Drawing.Image.FromFile(“NewImage2.png”, True)
pb1.Image = imgCurr
pb1.Visible = True
Catch ex As Exception
WriteToLog(”… Exception Message : " + ex.Message)
End Try

Hi Ron,

Thanks for your inquiry. Could you please attach your input Rtf here for testing? We will investigate the issue on our side and provide you more information.

Tahir



Here’s my Rtf file, let me know if there’s anything else you need



Thanks

Ron

Hi Ron,

Thanks for sharing the document. Unfortunately, the shared rtf contains extra line breaks. MS Word does not display the RTF correctly. Please check the attached image for detail.

We have removed the extra line breaks from the RTF and converted it to image and have not found any issue with output. We have attached the input RTF and output image with this post for your kind reference.

Could you please share the RTF which can be opened in MS Word here for further testing? Please also share the problematic sections of output image. We will investigate the issue on our side and provide you more information.

Tahir


Attached you will find 3 files. Original2.png is the image I’m trying to produce (what our vendor’s software produces in a report for us), NewImage2.png is what I can produce (I’m trying to replicate what their software produces in an internal custom reporting app we’re developing) with your software. TempRTF02.rtf is what they have saved in their database, which ultimately they’re using to generate the image? I’m not sure if they’re somehow modifying the rtf data before generating their image, but my assumption is they’re using it mostly as is? The biggest issue is the adding the stand along text above the table and putting it into the column heading of the table, as well as the merging of the two tables into one table? As you can see, the two images are quite different, and won’t yield the desired results.

Thanks for your help on this, hopefully we can resolve this, it’s a critical development project for us, and I’m hoping your software is the solution?

Ron
Hi Ron,

Thanks for sharing the detail. Please note that Aspose.Words mimics the same behavior as MS Word does. If you open your RTF in MS Word, you will get the same output. Please check the attached image and RTF.

The newRTF.rtf is generated by using following steps.

1) Open "TempRTF02.rtf" in MS Word.
2) Copy all contents
3) Open notepad and paste the contents in it.
4) Save the file with name "newRtf.rtf"

Open newRTF.rtf in MS Word to see the exact contents of RTF. Hope this answers your query. Please let us know if you have any more queries.

Tahir


I can understand what you’re saying, but at this point, it would appears mimicing MS Word does not produce the desired results? I’m not an expert on rtf at all, but upon investigating the rtf data, it would appear there are two seperate tables defined, yet only one is being produced via your mechanism? Also, text is being added to the table headers that would appears to be defined outside of the table definition? The text at the end is also not being interpreted as defined?

Ron


Hi Ron,

Thanks your inquiry. The behavior of Aspose.Words you are facing is correct. The issue is not with Aspose.Words. Please modify your RTF according to your requirement and then convert it to Png.

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.