如何在没有下载文件的情况下阅读pdf中的view.html
问题描述:
我想在不下载pdf的情况下阅读pdf文件。下来的代码工作正常的图像。代替图片我想阅读pdf。那可能吗。如何在没有下载文件的情况下阅读pdf中的view.html
db.define_table('mytable',
Field('image', type='upload'))
控制器
def tables():
return dict(tables=db().select(db.mytable.ALL))
查看
{{for table in tables:}}
<img src="{{=URL('default', 'download', args=table.image)}}" /> <br />
{{pass}}
答
您可以创建从PDF的PNG文件。 PDF不是浏览器可以在HTML中呈现的东西(确保Chrome和Firefox可以打开PDF;但是这是全屏幕,只有PDF本身;例如另一个URL)。可能是超出范围:在一些项目中,我使用转换上传PDF文件为JPG格式,提供预览的crontab中:
#Render all PDF's to thumb when no thumb is found
#convert -thumbnail x600 -background white "1.pdf"[0] "1.jpg"
import os,sys
OVERWRITE_EXISTING=False
PDFDIR='uploads'
THUMBDIR=os.path.join('static','thumbs')
import glob
import os
def insensitive_glob(pattern):
def either(c):
return '[%s%s]'%(c.lower(),c.upper()) if c.isalpha() else c
return glob.glob(''.join(map(either,pattern)))
#get all the pdf file names in the current folder
os.chdir('uploads')
files = insensitive_glob("*.pdf")
# and convert each file if needed
for f in files:
convert_needed=True
newFile=os.path.join('..',THUMBDIR,'%s.jpg' % f[:-4])
if not OVERWRITE_EXISTING:
if os.path.exists(newFile):
#print 'Warning:: .jpg already exists; skipping %s' % f
convert_needed=False
if convert_needed:
cmd='convert -density 144 %s[0] %s' % (f,newFile)
print "Converting with: %s" % cmd
os.system(cmd)
+0
另一种方式:http://stackoverflow.com/questions/276434/converting-pdf-to-html-with-python?lq=1 – acidjunk
有关于如何在http://stackoverflow.com/questions Django的做到这一点建议/ 11779246/how-to-show-a-pdf-file-in-a-django-view – 2015-07-28 07:49:13
下载只是意味着“把东西拿到电脑上”。您无法阅读电脑上没有的东西。或者我误解了你的问题? –
我有表格,我正在阅读pdf。我从表中提取PDF并在html中显示 – Rohit