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

Free Support Forum - aspose.com

DocumentBuilder InsertHtml (nested table) Save as pdf , some TD will disapper

Hi Sirs,
DocumentBuilder InsertHtml (nested table) Save as pdf , some TD will disapper
My code is below,

var htmlTable2 = @"<style>
div[data-speed-id=seal-box] {
	margin-top: 20px;
	margin-left: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	height: 20px;
}

td[data-speed-sealouid] {
	width: 60px;
}

table[data-speed-id='seal-table'] {
	border: 1px solid red !important;
	color: red !important;
	border-collapse: initial;
}

table[data-speed-id=seal-table] td {
	padding: 0px !important;
	margin: 0px !important;
	border: 0px;
	border-collapse: collapse;
	border-spacing: 0px !important;
	vertical-align: middle !important;
}
</style>
<div style='color: blue;'>下面是原本職章結構直接輸出,</div>
<table>
<colgroup>
	<col style='width:35%;'>
	<col style='width:65%;'>
</colgroup>
<tbody>
<tr>
	<td>
		<div style='margin-top: 10px;' data-speed-id='seal-box'>
			<table>
				<tbody>
				<tr>
					<td>
						<table data-speed-id='seal-table'>
							<tbody>
							<tr>
								<td style='font-size: 10px;' data-speed-sealouid='10110'>文化資源司</td>
								<td style='font-size: 16px;' rowspan='2'>亂馬客</td>
							</tr>
							<tr>
								<td style='font-size: 10px;'>科員</td>
							</tr>
							</tbody>
						</table>
					</td>
				</tr>
				<tr>
					<td style='text-align: center; font-size: 12px;'>106/10/18 10:36</td>
				</tr>
				</tbody>
			</table>
		</div>
	</td>
	<td>
		案係亂馬客測試文化局將於本(105)年10月29日召開「106亂馬客測試社區營造平台工作小組第九十次會議」,本部為列席單位,擬視業務狀況再行派員,當否?請核示。文陳閱後存查。
	</td>
</tr>
</tbody>
</table>";
builder.InsertHtml(htmlTable2, true);
//doc.CompatibilityOptions.GrowAutofit = false;
doc.UpdateTableLayout();
doc.Save("test.doc", SaveFormat.Doc);
doc.Save("TEST.pdf", SaveFormat.Pdf);

disapper.png (117.2 KB)
Thanks for your help

@rainmaker_ho,

Thanks for your inquiry. Please do not call Document.UpdateTableLayout method to get the desired output.

We have logged this problem in our issue tracking system as WORDSNET-16089. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@tahir.manzoor ,
Thanks for your help.

@tahir.manzoor,
The pdf file’s table will overlap between td, if i change code to below,

builder.InsertHtml(htmlTable2, true);
doc.CompatibilityOptions.GrowAutofit = false;
//doc.UpdateTableLayout();
doc.Save("test.doc", SaveFormat.Doc);
doc.Save("TEST.pdf", SaveFormat.Pdf); 

The compare result please ref attach file, thanks
formatError.png (132.3 KB)

@rainmaker_ho,

Thanks for your inquiry. You may increase the left padding of table’s cell to workaround this issue.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(htmlTable2, true);
doc.CompatibilityOptions.GrowAutofit = false;

foreach (Cell cell in doc.GetChildNodes(NodeType.Cell, true))
{
    cell.CellFormat.LeftPadding = 5;
}
doc.Save(MyDir + "17.10.pdf");
1 Like

@tahir.manzoor,
It’s worked!
Thanks for your help.