我的项目是发送带有pdf附件的电子邮件。我所有的pdf是在一个文件夹中的谷歌驱动器,我需要寻找特定的pdf相关的特定客户。pdf只包含文字和客户号码。
因此,我需要一个脚本,以提取文本从pdf到字符串,并研究这个字符串,以确定它是否包含客户编号。
现在我用这个:
function myFunction() {
// Creates a new file and logs its content
var file = DocsList.getFileById('my pdf file id here')
Logger.log(file.getContentAsString()); // logs 'sample file contents'
}但是日志显示了一个编码问题:
m��:�B�C-�BݣXaP�{���{��( v���GE�O�_����������q�o�v�)��p���u�\9�[�G��
有人知道如何从pdf中提取文本到字符串吗?
发布于 2014-10-29 05:33:42
来自pdfToText()的Get pdf-attachments from Gmail as text实用程序使用高级驱动服务和DocumentApp将PDF转换为Google为文本。您可以以这种方式获取OCR的文本,也可以将其直接保存到驱动器上任何文件夹中的txt文件中。
// Start with a Blob object
var blob = DriveApp.getFilesByName("my.pdf")[0];
// filetext will contain text from pdf file, no residual files are saved:
var filetext = pdfToText( blob, {keepTextfile: false} );一旦你有了文本,搜索关键字就变得非常容易了!
if (filetext.indexOf( keyword ) !== -1) {
// Found keyword...
}https://stackoverflow.com/questions/23632060
复制相似问题