如何line by line使用iText5 for .NET 读取PDF文件?我通过互联网搜索,但我只发现每页内容阅读PDF文件.
请看下面的代码.
public string ReadPdfFile(object Filename)
{
string strText = string.Empty;
try
{
PdfReader reader = new PdfReader((string)Filename);
for (int page = 1; page <= reader.NumberOfPages; page++)
{
ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
String s = PdfTextExtractor.GetTextFromPage(reader, page, its);
s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s)));
strText = strText + s;
}
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return strText;
}
Run Code Online (Sandbox Code Playgroud) 我想克隆一个pdf,并在复制期间或之后的某个时刻对文档稍作更改.
我设法用页面做了,但我也试图复制所有元数据,表单字段,acrofields等.
我怎么能用iTextSharp做到这一点?
Document document = new Document();
FileStream fs = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None)
PdfCopy copy = new PdfCopy(document, fs);
document.Open();
for (int i = 1; i <= reader.NumberOfPages; i++)
{
PdfImportedPage importedPage = copy.GetImportedPage(reader, i);
copy.AddPage(importedPage);
}
copy.Outlines = SimpleBookmark.GetBookmark(reader);
fs.Flush();
PdfCopyFields copyf = new PdfCopyFields(fs);
Run Code Online (Sandbox Code Playgroud) 我正在创建一个PDF并编写流作为响应.在写入流之前,我想在所有页面中添加背景图像作为水印,以便通过响应刷新的PDF文档是带有水印的最终文档.
嗨,这是我的代码示例.任何帮助都会很有帮助
private static String generatePDF(HttpServletRequest request, HttpServletResponse response, String fileName) throws Exception
{
Document document = null;
PdfWriter writer = null;
FileOutputStream fos = null;
try
{
fos = new FileOutputStream(fileName);
Document document = new Document(PageSize.A4);
writer = PdfWriter.getInstance(document, fos);
document.open();
/**
* Adding tables and cells and other stuff required
**/
return pdfFileName;
} catch (Exception e) {
FileUtil.deleteFile(fileName);
throw e
} finally {
if (document != null) {
document.close();
}
fos.flush();
}
}
Run Code Online (Sandbox Code Playgroud)
我现在想使用下面的代码添加背景图像,并将输出PDF写入相同的流
PdfReader sourcePDFReader = …Run Code Online (Sandbox Code Playgroud) 我正在使用iText5(Java)编写可能包含中文字符的PDF.所以我FontSelector用来处理String,这很好用.
现在的问题是,如果有2个字符串
String str1 = "Hello Test1";
String str2 = "Hello Test2";
Run Code Online (Sandbox Code Playgroud)
我需要写str1女巫Font Color = Blue和size = 10,而str2与Font Color = Gray和size = 25.
我无法弄清楚如何使用它FontSelector.
任何帮助表示赞赏.
我正在Texmaker中更改LaTeX文档,显然pdf没有更新,我也不知道为什么。我有快速生成pdflatex +查看pdf。
我在Windows 7中使用Texmaker版本4.4.1。
在我在另一个版本的Texmaker中使用相同的tex文件之前,它可以工作,但是知道我正在尝试在新版本中进行更改,但不能更改。
乳胶文件中的更改无关紧要,编译时不会显示任何错误或任何内容,完成后pdf完全没有变化。
您知道造成此问题的原因吗?非常感谢大家!
乔治
我正在开发一个Java App.我使用jFreeChart创建了一个饼图,并将其添加到使用iText库创建的PDF文件中,但我无法找到一种方法来对齐PDF中的图形并使其居中.这是我用来添加图表的代码:
PdfContentByte contentByte = writer.getDirectContent();
PdfTemplate template = contentByte.createTemplate(600, 600);
Graphics2D graphics2d = template.createGraphics(600, 600, new DefaultFontMapper());
Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 300, 300);
resultsPieChart.draw(graphics2d, rectangle2d);
graphics2d.dispose();
contentByte.addTemplate(template, 0, 0);
Run Code Online (Sandbox Code Playgroud) 这个问题在 Stackoverflow 上并不新鲜,但我很确定我遗漏了一些明显的东西。
我正在尝试将一些 .pdf 文件转换为 .txt 文件,以便挖掘它们的文本。我的方法基于这个优秀的脚本。.pdf 文件中的文本不是由图像组成的,因此不需要 OCR。
# Load tm package
library(tm)
# The folder containing my PDFs
dest <- "./pdfs"
# Correctly installed xpdf from http://www.foolabs.com/xpdf/download.html
file.exists(Sys.which(c("pdfinfo", "pdftotext")))
[1] TRUE TRUE
# Delete white spaces from pdfs' names
sapply(myfiles, FUN = function(i){
file.rename(from = i, to = paste0(dirname(i), "/", gsub(" ", "", basename(i))))
})
# make a vector of PDF file names
myfiles <- list.files(path = dest, pattern = "pdf", full.names = …Run Code Online (Sandbox Code Playgroud)
我有这段代码,我用它来获取 PDF 的文本。这对于英文 PDF 来说非常棒,但是当我尝试提取阿拉伯语文本时,它向我显示了类似这样的内容。
") + n 9 n <+, + )+ $ # $ +$ F% 9& .< $ : ;"
using (PdfReader reader = new PdfReader(path))
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
String text = "";
for (int i = 1; i <= reader.NumberOfPages; i++)
{
text = PdfTextExtractor.GetTextFromPage(reader, i,strategy);
}
}
Run Code Online (Sandbox Code Playgroud) 情况:
我有100万用户,我想通过标签搜索它们.
这是架构:
const Account = new Schema({
tags: { type: [String], default: ['cats'] }
})
Run Code Online (Sandbox Code Playgroud)
这是第一个查询:
const query = { tags: 'cats'}
const fields = { _id: 0 }
const options = { skip: 0, limit: 5 }
Account.find(query, fields, options)
Run Code Online (Sandbox Code Playgroud)
调用find方法后,Mongoose将开始搜索并返回它匹配的前5个条目.在这种情况下的表现是最佳的.
这是第二个查询:
const query = { tags: 'cats'}
const fields = { _id: 0 }
const options = { skip: 500 000, limit: 5 }
Account.find(query, fields, options)
Run Code Online (Sandbox Code Playgroud)
在这种情况下发生的事情是我感兴趣的.
并Mongoose首先匹配500个000项,然后返回未来5项?
或者它是否以某种方式"跳"到500 000元素而不必事先将它们全部匹配? …
我有一个我想连续旋转的图像。
我想过在特定的时间间隔后将其旋转某个角度。但是,我想实现一个功能,当我单击特定键时,朝图像头部指向的方向发射子弹。
那么在那个时刻,我应该如何在旋转图像中保持我的头部轨迹?