本文介绍了如何在c#中覆盖pdfBox的PDFTextStripper类的writeString方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在c#中覆盖pdfBox的PDFTextStripper类的writeString方法?
我想提取pdf文件内容的字体大小和样式使用pdfBox。当我搜索时,我发现我应该覆盖PDFTextStripper类的writeString方法。
我是c#的新手,我无法实现覆盖。
我使用的代码如下:
How can I override the writeString method of PDFTextStripper class of pdfBox in c#?
I want to extract the font size and style of the contents of a pdf file using pdfBox. When I searched, I found that I should override the writeString method of the PDFTextStripper class.
I am a newbie in c# and I am not able to implement the overriding.
The code that I used is as follows:
PDFTextStripper stripper = new PDFTextStripper(){
protected override void writeString(String text, List<TextPosition> textPositions)
{
String prevBaseFont = "";
StringBuilder builder = new StringBuilder();
foreach (TextPosition position in textPositions)
{
String baseFont = position.getFont().getBaseFont();
if (baseFont != null && baseFont != (prevBaseFont))
{
builder.Append('[').Append(baseFont).Append(']');
prevBaseFont = baseFont;
}
builder.Append(position.getCharacter());
}
writeString(builder.ToString());
}
};
请帮助我。
Please help me.
推荐答案
public class MyPDFTextStripper : PDFTextStripper
{
protected override void writeString(String text, List textPositions)
{
}
// Another option is to hide the original method by using the keyword new
protected new void writeString(String text, List textPositions)
{
}
}
请参阅 []
这篇文章可能会有用 []
这篇关于如何在c#中覆盖pdfBox的PDFTextStripper类的writeString方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!