Free Support Forum - aspose.com

SpaceAfterAuto doesn't seem to work with html documents

I have been running some tests on converting some current code to use Aspose. What we are doing is converting an html file to pdf. Because the formatting on the file is pretty bad, Aspose.PDF will not work for this. So I tried creating a word document from the html through Aspose.Words and then converting that to PDF. This is working almost perfectly, except the SpaceAfterAuto does not seem to work. I have set it to false, but the word file that is created always has it set back to true.

Here is the code I am using.

Dim oWord As Aspose.Words.Document = New Aspose.Words.Document(sHTML, Aspose.Words.LoadFormat.Html, "")
oWord.Sections(0).PageSetup.LeftMargin = 28
oWord.Sections(0).PageSetup.RightMargin = 28
oWord.Sections(0).PageSetup.TopMargin = 28
oWord.Sections(0).PageSetup.BottomMargin = 28
oWord.Sections(0).PageSetup.PageWidth = 72 * 11
oWord.Sections(0).PageSetup.PageHeight = 72 * 8.5
oWord.Sections(0).Body.Paragraphs(0).ParagraphFormat.PageBreakBefore = False
oWord.Sections(0).Body.Paragraphs(0).ParagraphFormat.SpaceAfterAuto = False
oWord.Sections(0).Body.Paragraphs(0).ParagraphFormat.SpaceBeforeAuto = False
oWord.Sections(0).Body.Paragraphs(0).ParagraphFormat.SpaceBefore = 0
oWord.Sections(0).Body.Paragraphs(0).ParagraphFormat.SpaceAfter = 0
oWord.Sections(0).Body.Paragraphs(0).ParagraphFormat.Style.Font.Size = 9
oWord.Save(sDOC, Aspose.Words.SaveFormat.Doc)
System.Diagnostics.Process.Start(sDOC)

I can make an example if you need one, but the exact file I am using I cannot send.

Thanks

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Yes, please attach your sample HTML here for testing. I will check it and provide you more information.

Also, as I can see you change SpaceAfterAuto to false only for the first paragraph in your document. Maybe, in your case, you should set this option to false for each paragraph in your document. For example, see the following code:

// Open HTML

Document doc = new Document(@"in.html");

// Get all paragraphs in the document.

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

// Loop through all paragraphs.

foreach (Paragraph paragraph in paragraphs)

{

paragraph.ParagraphFormat.SpaceAfterAuto = false;

paragraph.ParagraphFormat.SpaceAfter = 0;

}

// Save output document

doc.Save(@"out.doc");

doc.SaveToPdf(@"out.pdf");

Hope this helps.

Best regards,

The example that I have is only one paragraph and this is a proof of concept, so I was just getting it to work with that paragraph. I have made an example that shows the issue based off the original html. I have zipped it up and attached it.

Thanks again.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Actually, when you load your document into Aspose.Words Document object model, there more than one paragraphs. You can open document using DocumentExplorer (Aspose.Words demo application). You should reset SpaceAfterAuto for each paragraph in your document as I suggested earlier.

Best regards,