0

I am trying to read a pdf file in html without downloading the pdf. The down code is working fine for images . In place of images i want to read a pdf. is that possible.

db.define_table('mytable',
          Field('image', type='upload'))

controller

def tables(): 
   return dict(tables=db().select(db.mytable.ALL))

View

{{for table in tables:}}
    <img src="{{=URL('default', 'download', args=table.image)}}" /> <br /> 
{{pass}}
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
Rohit
  • 19
  • 8
  • There are suggestions on how to do this with Django at http://stackoverflow.com/questions/11779246/how-to-show-a-pdf-file-in-a-django-view –  Jul 28 '15 at 07:49
  • Download just mean "get something to the computer". You can't read something which isn't on the computer. Or do I misunderstand your question? – Rasmus Damgaard Nielsen Jul 28 '15 at 08:50
  • i have table where i am sving the pdf . i am fetching the pdf from table and show in html – Rohit Jul 28 '15 at 12:26

1 Answers1

0

You could create an png from the PDF. PDF is not something a browser can render in HTML (sure Chrome and Firefox can open a PDF; but that's fullscreen, just the pdf itself; e.g. another URL). Could be out of scope: In some projects I use a crontab that converts uploaded PDF's to jpg to provide a preview:

#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)
acidjunk
  • 1,751
  • 18
  • 24