C# PDF标题无法在Itextsharp中显示
您好,我写了一些pdf解析html到它使用itextsharp和它的工作很好,但我想在每个pdf页面上添加页码。为此,我添加了带有虚拟文本的标题(稍后我将用页数替换它),并写入了dome内容,但内容没有显示C# PDF标题无法在Itextsharp中显示,c#,pdf,itextsharp,C#,Pdf,Itextsharp,您好,我写了一些pdf解析html到它使用itextsharp和它的工作很好,但我想在每个pdf页面上添加页码。为此,我添加了带有虚拟文本的标题(稍后我将用页数替换它),并写入了dome内容,但内容没有显示 try { Document oNewDocument = new Document(PageSize.A4, 20f, 20f, 30f, 10f); PdfWriter.GetInstance(oNewDocument, new FileStream(pdfpath
try
{
Document oNewDocument = new Document(PageSize.A4, 20f, 20f, 30f, 10f);
PdfWriter.GetInstance(oNewDocument, new FileStream(pdfpath + "/" + sSaleInvoicePdf, FileMode.Create));
string content = "Some HTML Content";
List<IElement> parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), styles);
oNewDocument.AddHeader("text","text");
foreach (var htmlElement in parsedHtmlElements)
{
oNewDocument.Add(htmlElement as IElement);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
oNewDocument.Close();
}
试试看
{
Document oNewDocument=新文档(PageSize.A4、20f、20f、30f、10f);
GetInstance(oNewDocument,新文件流(pdfpath+“/”+sSaleInvoicePdf,FileMode.Create));
string content=“一些HTML内容”;
List parsedhtmlements=HTMLWorker.ParseToList(新的StringReader(内容)、样式);
oNewDocument.AddHeader(“文本”、“文本”);
foreach(parsedhtmlements中的var htmlElement)
{
添加(htmlElement作为IEElement);
}
}
捕获(例外情况除外)
{
响应。写入(例如消息);
}
最后
{
oNewDocument.Close();
}
我在哪里工作。此代码生成所有html内容,但不生成标题文本
HeaderFooter hdr = new HeaderFooter(stringvalue, false);
hdr.Border = Rectangle.NO_BORDER;
hdr.Alignment = Element.ALIGN_LEFT;
doc.Header = hdr;
尝试此操作不确定您的版本是否支持此操作。请尝试一下
尝试此操作不确定您的版本是否支持此操作。请尝试使用版本5+您必须使用页面事件来执行此操作: 在版本5之前,它的工作原理如下:
Document oNewDocument = new Document(PageSize.A4, 20f, 20f, 30f, 10f);
PdfWriter.GetInstance(oNewDocument, new FileStream(pdfpath + "/" + sSaleInvoicePdf, FileMode.Create));
//Create some text to add to the header
Chunk text= new Chunk("my text");
Phrase phHeader = new Phrase();
phHeader.Add(text);
//Assign the Phrase to PDF Header
HeaderFooter header = new HeaderFooter(phHeader, false);
//Add the header to the document
oNewDocument.Header = header;
版本5+您必须通过页面事件执行此操作: 在版本5之前,它的工作原理如下:
Document oNewDocument = new Document(PageSize.A4, 20f, 20f, 30f, 10f);
PdfWriter.GetInstance(oNewDocument, new FileStream(pdfpath + "/" + sSaleInvoicePdf, FileMode.Create));
//Create some text to add to the header
Chunk text= new Chunk("my text");
Phrase phHeader = new Phrase();
phHeader.Add(text);
//Assign the Phrase to PDF Header
HeaderFooter header = new HeaderFooter(phHeader, false);
//Add the header to the document
oNewDocument.Header = header;
我认为这将帮助你:我认为这将帮助你: