Html aspose pdf 中的标签使用 xml
Html tags in aspose pdf using xml
我正在动态生成一个 xml 文件并使用 aspose pdf 我正在生成一个 pdf 文件。每次我在我的 pdf 文件中得到 html 标签
我生成如下:
stringbuilder strScenarioXML = new stringbuilder();
strScenarioXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Pdf xmlns=\"Aspose.Pdf\"> <Section PageWidth='612' PageHeight='792' PageMarginTop='5' PageMarginBottom='0.1' PageMarginLeft='30' PageMarginRight='30' IsNewPage='true'>");
strScenarioXML.Append("<Table MarginTop='5' MarginBottom='5' MarginLeft='15' MarginRight='15' DefaultCellPaddingTop='2.0' DefaultCellPaddingRight='2.0' DefaultCellPaddingLeft='2.0' DefaultCellPaddingBottom='2.0' ColumnWidths='100%'><Border><All LineWidth='1'></All></Border>");
strScenarioXML.Append("<Row FixedRowHeight='15'><Cell><Border><Bottom LineWidth='1' /></Border><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='10' >Notes Details</Segment><Segment></Segment></Text></Cell></Row>");
strScenarioXML.Append("<Row FixedRowHeight='15'><Cell><Table ColumnWidths='70% 15% 15% 0%' DefaultCellPaddingRight='1.0' DefaultCellPaddingLeft='3.0' DefaultCellPaddingBottom='1.0'>");
strScenarioXML.Append("<Row FixedRowHeight='15'><Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='8'>Note</Segment><Segment></Segment></Text></Cell><Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='8'>Created By</Segment><Segment></Segment></Text></Cell><Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='8'>Created Date</Segment><Segment></Segment></Text></Cell></Row>");
for (int i = 0; i < objNote.Count; i++)
{
strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='false' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[" + objNote[i].Comments + "]]>" + " </Segment> <Segment></Segment></Text></Cell>");
strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[" + objNote[i].Publisher + "]]>" + "</Segment><Segment></Segment></Text></Cell>");
strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[" + objNote[i].CreatedDate.ToString("MM/dd/yy HH:mm") + "]]>" + "</Segment><Segment></Segment></Text></Cell></Row>");
}
strScenarioXML.Append("</Table></Cell></Row></Table>");
strScenarioXML.Append("</Section></Pdf>");
Aspose.Words.License licWord = new Aspose.Words.License();
licWord.SetLicense("Aspose.Words.lic");
Aspose.Pdf.License lic = new Aspose.Pdf.License();
lic.SetLicense("Aspose.Custom.lic");
Aspose.Pdf.Kit.License licKit = new Aspose.Pdf.Kit.License();
licKit.SetLicense("Aspose.Custom.lic");
Aspose.Pdf.Pdf scenarioExportPDF = new Aspose.Pdf.Pdf();
XmlDocument xmlDoc = new XmlDocument();
scenarioExportPDF.PageSetup.Margin.Left = 0;
scenarioExportPDF.PageSetup.Margin.Right = 0;
xmlDoc.LoadXml(strScenarioXML);
scenarioExportPDF.BindXML(xmlDoc, null);
scenarioExportPDF.Save(msExportScenarioStream);
我将在第一列 objNote[i].Comments 中得到
标签,我不想在 pdf 文件中显示
标签,因为我将它放在 [![CDATA ""]] 但是还是没有用。
我不明白我错过了什么..是 aspose 支持它还是我错过的其他东西?请帮助我...
我试过你的代码,但有标签错误,例如没有结束标签。我简化了它并与最新版本一起使用,最终的 PDF 正确显示了 table。
代码
string dst = dataDir + "xml.pdf";
StringBuilder strScenarioXML = new StringBuilder();
strScenarioXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Pdf xmlns=\"Aspose.Pdf\"> <Section PageWidth='612' PageHeight='792' PageMarginTop='5' PageMarginBottom='0.1' PageMarginLeft='30' PageMarginRight='30' IsNewPage='true'>");
strScenarioXML.Append("<Table MarginTop='5' MarginBottom='5' MarginLeft='15' MarginRight='15' DefaultCellPaddingTop='2.0' DefaultCellPaddingRight='2.0' DefaultCellPaddingLeft='2.0' DefaultCellPaddingBottom='2.0' ColumnWidths='100%'><Border><All LineWidth='1'></All></Border>");
strScenarioXML.Append("<Row FixedRowHeight='15'><Cell><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='10' >Notes Details</Segment></Text></Cell></Row>");
for (int i = 0; i < 3; i++)
{
strScenarioXML.Append("<Row><Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='false' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[comments]]>" + " </Segment> <Segment></Segment></Text></Cell>");
strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[publisher]]>" + "</Segment><Segment></Segment></Text></Cell>");
strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[date]]>" + "</Segment><Segment></Segment></Text></Cell></Row>");
}
strScenarioXML.Append("</Table>");
strScenarioXML.Append("</Section></Pdf>");
//Aspose.Words.License licWord = new Aspose.Words.License();
//licWord.SetLicense("Aspose.Words.lic");
//Aspose.Pdf.License lic = new Aspose.Pdf.License();
//lic.SetLicense("Aspose.Custom.lic");
//Aspose.Pdf.License licKit = new Aspose.Pdf.License();
//licKit.SetLicense("Aspose.Custom.lic");
Aspose.Pdf.Generator.Pdf scenarioExportPDF = new Aspose.Pdf.Generator.Pdf();
XmlDocument xmlDoc = new XmlDocument();
//scenarioExportPDF.PageSetup.Margin.Left = 0;
//scenarioExportPDF.PageSetup.Margin.Right = 0;
xmlDoc.LoadXml(strScenarioXML.ToString());
scenarioExportPDF.BindXML(xmlDoc, null);
scenarioExportPDF.Save(dst);
输出如下:
我正在动态生成一个 xml 文件并使用 aspose pdf 我正在生成一个 pdf 文件。每次我在我的 pdf 文件中得到 html 标签 我生成如下:
stringbuilder strScenarioXML = new stringbuilder();
strScenarioXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Pdf xmlns=\"Aspose.Pdf\"> <Section PageWidth='612' PageHeight='792' PageMarginTop='5' PageMarginBottom='0.1' PageMarginLeft='30' PageMarginRight='30' IsNewPage='true'>");
strScenarioXML.Append("<Table MarginTop='5' MarginBottom='5' MarginLeft='15' MarginRight='15' DefaultCellPaddingTop='2.0' DefaultCellPaddingRight='2.0' DefaultCellPaddingLeft='2.0' DefaultCellPaddingBottom='2.0' ColumnWidths='100%'><Border><All LineWidth='1'></All></Border>");
strScenarioXML.Append("<Row FixedRowHeight='15'><Cell><Border><Bottom LineWidth='1' /></Border><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='10' >Notes Details</Segment><Segment></Segment></Text></Cell></Row>");
strScenarioXML.Append("<Row FixedRowHeight='15'><Cell><Table ColumnWidths='70% 15% 15% 0%' DefaultCellPaddingRight='1.0' DefaultCellPaddingLeft='3.0' DefaultCellPaddingBottom='1.0'>");
strScenarioXML.Append("<Row FixedRowHeight='15'><Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='8'>Note</Segment><Segment></Segment></Text></Cell><Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='8'>Created By</Segment><Segment></Segment></Text></Cell><Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='8'>Created Date</Segment><Segment></Segment></Text></Cell></Row>");
for (int i = 0; i < objNote.Count; i++)
{
strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='false' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[" + objNote[i].Comments + "]]>" + " </Segment> <Segment></Segment></Text></Cell>");
strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[" + objNote[i].Publisher + "]]>" + "</Segment><Segment></Segment></Text></Cell>");
strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[" + objNote[i].CreatedDate.ToString("MM/dd/yy HH:mm") + "]]>" + "</Segment><Segment></Segment></Text></Cell></Row>");
}
strScenarioXML.Append("</Table></Cell></Row></Table>");
strScenarioXML.Append("</Section></Pdf>");
Aspose.Words.License licWord = new Aspose.Words.License();
licWord.SetLicense("Aspose.Words.lic");
Aspose.Pdf.License lic = new Aspose.Pdf.License();
lic.SetLicense("Aspose.Custom.lic");
Aspose.Pdf.Kit.License licKit = new Aspose.Pdf.Kit.License();
licKit.SetLicense("Aspose.Custom.lic");
Aspose.Pdf.Pdf scenarioExportPDF = new Aspose.Pdf.Pdf();
XmlDocument xmlDoc = new XmlDocument();
scenarioExportPDF.PageSetup.Margin.Left = 0;
scenarioExportPDF.PageSetup.Margin.Right = 0;
xmlDoc.LoadXml(strScenarioXML);
scenarioExportPDF.BindXML(xmlDoc, null);
scenarioExportPDF.Save(msExportScenarioStream);
我将在第一列 objNote[i].Comments 中得到
标签,我不想在 pdf 文件中显示
标签,因为我将它放在 [![CDATA ""]] 但是还是没有用。
我不明白我错过了什么..是 aspose 支持它还是我错过的其他东西?请帮助我...
我试过你的代码,但有标签错误,例如没有结束标签。我简化了它并与最新版本一起使用,最终的 PDF 正确显示了 table。
代码
string dst = dataDir + "xml.pdf";
StringBuilder strScenarioXML = new StringBuilder();
strScenarioXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Pdf xmlns=\"Aspose.Pdf\"> <Section PageWidth='612' PageHeight='792' PageMarginTop='5' PageMarginBottom='0.1' PageMarginLeft='30' PageMarginRight='30' IsNewPage='true'>");
strScenarioXML.Append("<Table MarginTop='5' MarginBottom='5' MarginLeft='15' MarginRight='15' DefaultCellPaddingTop='2.0' DefaultCellPaddingRight='2.0' DefaultCellPaddingLeft='2.0' DefaultCellPaddingBottom='2.0' ColumnWidths='100%'><Border><All LineWidth='1'></All></Border>");
strScenarioXML.Append("<Row FixedRowHeight='15'><Cell><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='true' FontName='Arial' FontSize='10' >Notes Details</Segment></Text></Cell></Row>");
for (int i = 0; i < 3; i++)
{
strScenarioXML.Append("<Row><Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='false' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[comments]]>" + " </Segment> <Segment></Segment></Text></Cell>");
strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[publisher]]>" + "</Segment><Segment></Segment></Text></Cell>");
strScenarioXML.Append("<Cell VerticalAlignment='Center'><Text Alignment='Left' IsSpaced='false'><Segment IsUnicode='true' IsTrueTypeFontBold='false' FontName='Arial' FontSize='8' ><![CDATA[date]]>" + "</Segment><Segment></Segment></Text></Cell></Row>");
}
strScenarioXML.Append("</Table>");
strScenarioXML.Append("</Section></Pdf>");
//Aspose.Words.License licWord = new Aspose.Words.License();
//licWord.SetLicense("Aspose.Words.lic");
//Aspose.Pdf.License lic = new Aspose.Pdf.License();
//lic.SetLicense("Aspose.Custom.lic");
//Aspose.Pdf.License licKit = new Aspose.Pdf.License();
//licKit.SetLicense("Aspose.Custom.lic");
Aspose.Pdf.Generator.Pdf scenarioExportPDF = new Aspose.Pdf.Generator.Pdf();
XmlDocument xmlDoc = new XmlDocument();
//scenarioExportPDF.PageSetup.Margin.Left = 0;
//scenarioExportPDF.PageSetup.Margin.Right = 0;
xmlDoc.LoadXml(strScenarioXML.ToString());
scenarioExportPDF.BindXML(xmlDoc, null);
scenarioExportPDF.Save(dst);
输出如下: