将 PDF 页面解析为 javascript 图像 [英] Parsing PDF pages as javascript Images

查看:22
本文介绍了将 PDF 页面解析为 javascript 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据标题,有什么方法可以将未受保护的 PDF 文件中的页面解析为 javascript Image() 对象?

As per title, is there any way I can parse pages from an unprotected PDF file as javascript Image() objects?

在运行 javascript 之前转换它们也可以,但我希望这能自动完成,不需要任何需要安装的库的帮助.

It would also be ok to convert them before running the javascript, but I would like this to be done automatically and without the assistance of any library which requires installation.

互联网上有人发布了这个 Bash 脚本.不幸的是,我不会 Bash,但运行它非常简单.

Someone over the internet has posted this Bash script. Unfortunately, I don't know Bash but running it was very simple.

#!/bin/bash
PDF='doc.pdf'
NUMPAGES=`identify -format %n "$PDF"`

for (( IDX=0; IDX<$NUMPAGES; IDX++ ))
do
  PAGE=$(($IDX+1))
  convert -resize 1200x900 "$PDF[$IDX]" `echo "$PDF" | sed "s/.pdf$/-page$PAGE.jpg/"`
done

echo "Done"

但是我遇到了这些错误:

But I got these errors:

line 3: identify: command not found
line 5: ((: IDX<: syntax error: operand expected (error token is "<")

使用 Bash 脚本预转换 PDF 将是一个很好的解决方案.有人可以修复上面的脚本或提供替代解决方案吗?

Pre-converting the PDF using a Bash script would be a good solution. Can someone fix the script above or either provide an alternative solution?

非常感谢!

推荐答案

PDF.js将让您将 PDF 渲染到画布上.然后您可以执行以下操作:

PDF.js will let you render the PDF to a canvas. Then you can do something like:

var img = new Image();
img.src = pdfCanvas.toDataURL();

PDF.js 给我留下了深刻的印象.我喜欢让客户端的浏览器为我做尽可能多的工作.

I've been very impressed with PDF.js. I love letting the client's browser do as much of the work for me as possible.

此处演示:http://jsbin.com/pdfjs-helloworld-v2/1/编辑

这篇关于将 PDF 页面解析为 javascript 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆