Lucas,

I have many documents that I have uploaded to my django app. The docs are
stored in the file system, but the path is in my django model. The docs are
either pdfs or png images.

This is how I am displaying pdf images in my ModelAdmin change form:

  readonly_fields = ('get_image_3', )

    def get_image_3(self, obj):
        display_image = ""
        if (obj.document_id):
            # Get the path to the main image
            doc_file_path = obj.document_id.storage_file_name.path
            if obj.document_id.storage_file_name.name.endswith('pdf'):
                display_image = '<embed src="{image_link}" width="620px"
height="420px" alt="pdf" pluginspage="
http://www.adobe.com/products/acrobat/readstep2.html";>'.format(image_link =
obj.document_id.storage_file_name.url)
            else:
                display_image = '<div><b>Click to tag people, Ctrl-click to
tag animals</b></div><img src="{document_link}" id="img1" doc_id="{doc_id}"
style="height:{height}"/>'.format(document_link =
obj.document_id.storage_file_name.url, doc_id=obj.document_id.document_id,
height=settings.FACE_ADMIN_PREVIEW_HEIGHT)
        return format_html(display_image)

The adobe reader renders a nice window for scrolling the pdf and changing
pages.

To display a thumbnail of the pdf on the main ModelAdmin page, I used
Pillow to grab the first page of the pdf and make a jpg thumbnail of that
page. Then use similar code from the display_image above after the else
(for displaying an image on the page in the admin).

Hope that helps!

Mark

On Mon, Nov 25, 2019 at 7:46 AM 'Lucas Gärtner' via Django users <
django-users@googlegroups.com> wrote:

> Hello everyone!
>
> I just signed up here, so maybe this thread is wrong in this group.
>
> The problem is as follows:
>
> I need to display a PDF document in a half of a web application.
> I tried it first with Iframe and now today with pdf.js.
> Nothing helped. Do you have any idea?
> It is only showing the pdf, not more.
>
> I am using django: 2.1.10 and Python 3.7.1
>
> Hope you have some good recommendations!
>
> Have a nice day!
> Lucas
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8304b914-3861-4c33-8948-87f9baeaf27f%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8304b914-3861-4c33-8948-87f9baeaf27f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEqej2N_fpXbUYSRftXF4zxJidfAqDebfO6sGM1PYadeU0R_Xg%40mail.gmail.com.

Reply via email to