求解为什么会显示不了内容只显示ok按钮
/// <summary>/// 解析PDF,获取PDF文字
/// </summary>
/// <param name="file_path_name">PDF文件路径</param>
/// <param name="startPage">起始页,从第1页开始</param>
/// <param name="endPageValue">结束页</param>
public static string GetText(string file_path_name,int startPageValue,int endPageValue)
{
PDDocument doc = PDDocument.load(file_path_name);
PDFTextStripper stripper = new PDFTextStripper();
// 设置是否排序
stripper.setSortByPosition(true);
stripper.setStartPage(startPageValue);
stripper.setEndPage(endPageValue);
return stripper.getText(doc);
}
private void btnGetText_Click(object sender, EventArgs e)
{
string fileName = txtPDFPath.Text.Trim();
if (fileName.Length <= 0)
{
MessageBox.Show("未加载pdf");
return;
}
StreamWriter sw = new StreamWriter(fileName+".txt", false);
try
{
string s = PDFParser.PDFParser.GetText(fileName, 1, 2);//前两页
sw.Write(s);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sw.Close();
sw.Dispose();
}
MessageBox.Show("OK");
}
这是源代码,为什么显示不了内容string s = PDFParser.PDFParser.GetText(fileName, 1, 2);//前两页
sw.Write(s);这样就可以把内容显示出来?