We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

HTML to RTF - Saving images

I have HTML with images that I want to convert to RTF. When I save the stream in RTF format, I get everything but the images.


Here is my code:
Dim HTML As Byte() = System.Text.Encoding.GetEncoding(“iso-8859-1”).GetBytes(oEditor.Html)
Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream(HTML)

Dim doc As New Document(memoryStream)

Dim options As New RtfSaveOptions()
Dim dstStream As New MemoryStream()
doc.Save(dstStream, options)
doc.Save(“c:\temp\rtf\saved-from-ae.rtf”, options)


This message was posted using Page2Forum from html to rtf image - Aspose Search Results - Aspose.com

Hi Tim,

Thanks for your inquiry.

Could you please attach your HTML document here and we will glaly provide you some further feedback.

Thanks,

Hi,

Here is the HTML code (kind-of ugly) which contains a referencing a file on disk:

Evaluation Only. Created with Aspose.Words. Copyright 2003-2010 Aspose Pty Ltd.

Testing that the Applications are Prepared for HTTPS Communication

Replace “yourdomain.com” with the domain name that the SSL certificate was issued for.

o TEST: GlassFish
https://yourdomain.com:8181/wsclient/servlet/DMS <https://localhost:8181/wsclient/servlet/DMS> - The page should load without error and the certificate should not cause a warning.

o TEST: GlassFish
https://yourdomain.com:8181/wsclient/servlet/VueServlet <https://localhost:8181/wsclient/servlet/VueServlet> - The page should load without error and the certificate should not cause a warning.

o TEST: Adept Web Services
https://yourdomain.com/Adept/BluePrintWebService/BPWS.asmx?op=getDmsConfig <https://localhost/Adept/BluePrintWebService/BPWS.asmx?op=getDmsConfig> - The page should load without error and the certificate should not cause a warning.

o TEST: Adept Web Services
https://yourdomain.com/Adept/Service_Adept.asmx?op=HelloWorld <https://localhost/Adept/Service_Adept.asmx?op=HelloWorld>

§ Login with AE and View a file.

TEST: AutoVue. This test will not load a file, but will test whether the viewer has been configured properly.

Hi

Thanks for your request. I suppose the problem occurs because Apsose.Words cannot find the image in the specified location. Moreover, path to image is relative. Have you tried to specify full path to image? This should fix the problem.

Best regards,

Let me give more background on what I'm testing.

I have a small RTF document stored in a database (it's raw text is stored in a varchar column in a table).

Using your component, I'm converting the RTF to HTML, so I can display it in an HTML editor control:

Dim sMemo As String = docrec.GetTextMemoValue()

Dim RTF As Byte() = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(docrec.GetTextMemoValue())

Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream(RTF)

Dim doc As New Document(memoryStream)

' Create and pass the object which implements the handler methods.

Dim options As New HtmlSaveOptions(SaveFormat.Html)

options.ExportTextInputFormFieldAsText = True

options.ImagesFolder = "C:\inetpub\wwwroot\Adept8.3\tmp\ADM"

options.ImagesFolderAlias = "/Adept8.3/tmp/ADM/"

Dim dstStream As New MemoryStream()

doc.Save(dstStream, options)

Dim pos = dstStream.Position

dstStream.Position = 0

Dim reader As New StreamReader(dstStream)

Dim str = reader.ReadToEnd()

oEditor.Html = str

oEditor.ID = "MemoField"

The user can edit the text in the HTML editor and when they click "Save" I need to convert the HTML back to RTF:

Dim HTML As Byte() = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(oEditor.Html)

Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream(HTML)

Dim doc As New Document(memoryStream)

Dim options As New RtfSaveOptions()

Dim dstStream As New MemoryStream()

doc.Save(dstStream, options)

doc.Save("c:\temp\rtf\saved-from-ae.rtf", options)

The problem is that the images are saved to disk by your component:

options.ImagesFolder = "C:\inetpub\wwwroot\Adept8.3\tmp\ADM"

options.ImagesFolderAlias = "/Adept8.3/tmp/ADM/"

If I change the path of the imageFolderAlias to:

options.ImagesFolderAlias = "http://localhost/Adept8.3/tmp/ADM/"

I'm could get burned down the road, because I cannot guarantee that the image path is http://localhost/. It could be a fully-qualified domain name or it could be https.

Is there a way to specify the directory where images are located?

Hi Tim,

Thanks for your inquiry.

I think you need to set the BaseUri in the LoadOptions when loading the HTML document. Please see the API page here for details.

Thanks,

Working with the Aspose.Words component to convert HTML to RTF. Local images are not converting properly. The image is located physically in c:\inetpub\wwwroot. The resulting RTF shows a broken image. Please advise.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

string sHtml = "";

string sText = string.Empty;

string sBaseUrl = null;

System.Web.HttpRequest oRequester = HttpContext.Current.Request;

#region Convert HTML to RTF with Aspose.Words

byte[] HTML = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(sHtml);

System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(HTML);

LoadOptions loadOptions = new LoadOptions(Aspose.Words.LoadFormat.Html, "", "http://localhost/");

Document doc = new Document(memoryStream, loadOptions);

RtfSaveOptions options = new RtfSaveOptions();

MemoryStream dstStream = new MemoryStream();

doc.Save(dstStream, options);

dstStream.Position = 0;

StreamReader reader = new StreamReader(dstStream);

sText = reader.ReadToEnd();

/*

* {\rtf1\ansi\ansicpg1252\uc0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deff0\adeff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}}{\colortbl;}{\stylesheet{\s0\snext0\styrsid8412110\sqformat\spriority0\ltrpar\li0\lin0\ri0\rin0\ql\faauto\rtlch\afs24\ltrch\fs24 Normal;}{\*\cs10\additive\ssemihidden\spriority0 Default Paragraph Font;}}{\*\generator Aspose.Words for .NET 9.6.0.0;}{\info\version0\edmins0\nofpages0\nofwords0\nofchars0\nofcharsws0}\deflang1033\deflangfe2052\adeflang1025\jexpand\showxmlerrors1\validatexml1\viewscale100\fet0\widowctrl\nospaceforul\nolnhtadjtbl\alntblind\lyttblrtgr\nogrowautofit\dntblnsbdb\noxlattoyen\wrppunct\nobrkwrptbl\expshrtn\snaptogridincell\asianbrkrule\htmautsp\noultrlspc\useltbaln\splytwnine\ftnlytwnine\lytcalctblwd\allowfieldendsel\newtblstyruls\lnbrkrule\formshade\nojkernpunct\dghspace180\dgvspace180\dghorigin1800\dgvorigin1440\dghshow1\dgvshow1\dgmargin\pgbrdrhead\pgbrdrfoot\sectd\ltrsect\sectdefaultcl\pard\plain\itap0\s0\ltrpar\li0\lin0\ri0\rin0\ql\faauto\rtlch\afs24\ltrch\fs24{\rtlch\afs24\ltrch\fs24{\*\shppict{\pict{\*\picprop\shplid1025{\sp{\sn fLayoutInCell}{\sv 1}}{\sp{\sn posrelh}{\sv 2}}{\sp{\sn posrelv}{\sv 2}}{\sp{\sn shapeType}{\sv 75}}}\pngblip\picw847\pich847\picwgoal480\pichgoal480\picscalex100\picscaley100\piccropl0\piccropr0\piccropt0\piccropb0\bliptag1766401221{\*\blipuid 694924c50c2e81711f287ad60b8ef0e5}89504e470d0a1a0a0000000d494844520000002000000020080300000044a48ac600000300504c5445000000ffffff808080c0c0c0ff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d84498c0000000097048597300000ec300000ec301c76fa8640000004249444154789c63602400188699022614804d01923666868153c0c202c1b84d606101c9e3b3022c4f810984dd40c817b456c08c04b0296040015814e000a30a20000034d404691ed77d330000000049454e44ae426082}}{\nonshppict{\pict\pngblip\picw847\pich847\picwgoal480\pichgoal480\picscalex100\picscaley100\piccropl0\piccropr0\piccropt0\piccropb0\bliptag1766401221{\*\blipuid 694924c50c2e81711f287ad60b8ef0e5}89504e470d0a1a0a0000000d494844520000002000000020080300000044a48ac600000300504c5445000000ffffff808080c0c0c0ff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d84498c0000000097048597300000ec300000ec301c76fa8640000004249444154789c63602400188699022614804d01923666868153c0c202c1b84d606101c9e3b3022c4f810984dd40c817b456c08c04b0296040015814e000a30a20000034d404691ed77d330000000049454e44ae426082}}}{\rtlch\afs24\ltrch\fs24\par}{\*\latentstyles\lsdstimax267\lsdlockeddef0\lsdsemihiddendef1\lsdunhideuseddef1\lsdqformatdef0\lsdprioritydef99{\lsdlockedexcept}}}

* /

#endregion

Hello

Thanks for your inquiry. Could you please attach your input HTML and output RTF here for testing? I’ll check the problem on my side and provide you more information.

Best regards,

Both are already posted. The html is in a string (very simple) and the resulting RTF is in a comment at the end.

Hello

Thank you for additional information. I cannot reproduce the problem on my side using the latest version of Aspose.Words (10.6.0). Here are my steps:

1. I have created virtual directory on my machine.

2. Then I have added images to this directory

3. And then I have converted HTML to RTF.

Moreover I have tried using the following code, and it works fine too:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

string baseUri = "";

builder.InsertHtml(baseUri + "<img alt='' src='../images/test.jpg/>"</span>);<o:p></o:p></span></p></font></p> <p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin;mso-ansi-language:RU;mso-fareast-language: EN-US;mso-no-proof:yes"><o:p> </o:p></span></p> <p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"; mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language: RU;mso-fareast-language:EN-US;mso-no-proof:yes">doc.Save(<span style="color:#A31515">"C:\\Temp\\out.</span></span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin;color:#A31515;mso-fareast-language:EN-US; mso-no-proof:yes">rtf</span><span style="font-size:10.0pt;font-family:"Courier New"; mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;color:#A31515; mso-ansi-language:RU;mso-fareast-language:EN-US;mso-no-proof:yes">"</span><span style="font-size:10.0pt;font-family:"Courier New";mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin;mso-ansi-language:RU;mso-fareast-language: EN-US;mso-no-proof:yes">);</span><span lang="EN-US" style="font-size:10.0pt; font-family:"Courier New";mso-fareast-font-family:Calibri;mso-fareast-theme-font: minor-latin;mso-fareast-language:EN-US;mso-no-proof:yes"><o:p></o:p></span></p> <p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New"; mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-fareast-language: EN-US;mso-no-proof:yes"><o:p> </o:p></span></p> <p class="MsoNormal"><span lang="EN-US">Best regards, </span></p>

I found that your sample code DOES work (though it has a typo), but I am using a Web Application that has explicit permissions, which is quite different than a virtual directory.

I'm confident that this is a permissions issue, as images from other domains and virtual directories do work, but images in my web application do not.

Can you please help resolve this?

Quite simply, the virtual directory is converted to a web app, with the ASP.Net v4.0 Classic App Pool, and a set user using Windows authentication.

Hi

Thank you for additional information. I think, you can use the approach suggested here to work the problem around:

Hope this helps.

Best regards,

Thank you for the suggestion; however, it doesn't seem to work: the regular expression doesn't find any of the image tags in my HTML.

I'm not great at regex and I tried a couple of variations:

]+src[\\s='\"]+([^\"'>\\s]+)/is

""

So, with the issue at hand, are you saying that there is a known problem with websites that use authentication?

If I get your sample working, won't I have to manage each of the image types, e.g. gif, png, jpg, bmp, etc.? Why doesn't the component handle this automatically?

Ok, forget my last post - I figured out how to make it work using some of your suggestions.

Let's consider this resolved.

Hi

It is perfect that you managed to resolve the problem. Please let us know if you need more assistance, we will be glad to help you.

Best regards,