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

Free Support Forum - aspose.com

Unable to get the horizontal row(<hr> tag) in the word document

Hi All,


I am very happy in using aspose.words. But i had a requirement like this:

1. I am having an html content that has say for example two images and an
between them
2. When i am trying to convert this to .doc file i am able to get these images but not the
( horizontal line).

Code snippet:

//for getting the two images paths in that html and added to an array
while (true)
{
int idx1 = htmlContent.IndexOf("<img");
if (idx1 < 0)
break;
int idx2 = htmlContent.IndexOf(">", idx1);
string imstring = htmlContent.Substring(idx1, idx2 - idx1);
htmlContent = htmlContent.Substring(idx2 + 2);
idx2 = imstring.Replace("&", “&”).IndexOf("&EmailTemplate");
int start = imstring.IndexOf("?filename=") + 10;
int len = idx2 - start;
string strEncFilePath = imstring.Substring(start, len);
strEncFilePath = System.Web.HttpUtility.UrlDecode(strEncFilePath);
strEncFilePath = strEncFilePath.Replace("@", “^”);
strEncFilePath = Encryption.SecureDecrypt(strEncFilePath, Encryption.KeyTypes.URL, Encryption.EncodingTypes.Base64);
imnames.Add(strEncFilePath);

}

//go through each shape in the document and assign the actuall source to each image. (here i need
to skip if that is not an image. i will be thankful if u can suggest me to check wether it is image or not)
Aspose.Words.Document doc = new Aspose.Words.Document(strHTMLFilePath);
Aspose.Words.DocumentBuilder db = new DocumentBuilder(doc);
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true, false);
int imageIndex = 1;
foreach (Aspose.Words.Drawing.Shape shape in shapes)
{
if (shape.Name == “”)
{
shape.ImageData.SourceFullName = (string)imnames[imageIndex - 1];
shape.ImageData.SetImage((string)imnames[imageIndex - 1]);
System.Threading.Thread.Sleep(Int32.Parse(strWordSleepTime));
shape.Height = 100;
shape.Width = 100;
}
imageIndex++;
}


doc.Save(strScratchpadDirectoryPath + strWordFileName, SaveFormat.Doc);


With this code i am getting the document but that
is not comming. (it is comming but as a missed image)

I will be very helpfull if someone help me here.

Thanks,
Yashwanth

Hi,


Thanks for your inquiry.

While using the latest version of Aspose.Words i.e. 10.6.0, upon conversion from HTML to DOC, I managed to successfully render
in between two images in DOC. I used the following HTML:

<html><o:p></o:p>

<head>

<title></title>

</head>

<body>

<img src="http://www.mapsofworld.com/images/world-countries-flags/pakistan-flag.gif" />

<hr />

<img src="http://www.mapsofworld.com/images/world-countries-flags/pakistan-flag.gif" />

</body>

</html>


To convert this HTML to DOC I used the following simple code:

Document doc = new Document(@"C:\test\hr.htm");

doc.Save(@"C:\test\hr_out.doc");


Please let us know if you need more information, We are always glad to help you.

Best Regards,