How to render a pdf file as pdf in browser using django - django

I am using Django web frame work. I am taking pdf files from users (notes/book/etc). Then I want to display those pdf in website, but I could not find a way. Methods that failed 1)iframe 2)simple rendering using django 3)pdf.js library. Also browser blocks rendering initially. Care to suggest a method and steps to implement it.

I the answer to your problem is here :
https://docs.djangoproject.com/en/3.0/howto/outputting-pdf/

Well the answer has to be very very clear here. You can not display pdf using. There is no such library for that. Like pdf.js for javascript based frameworks. I have done the research. So if you want a really good pdf viewer for your django powered website you have to use pdf.js for sure. I have asked people working with django professionally.
output in firefox
ouput in chromium browser
Now 2nd output is what we want
here is the code

Related

Django - how to render all pages of pdf files at once

I am trying to make a pdf viewer in HTML template using pdf.js in Django framework.
I had used a code that I got from a Youtube channel Traversy Media on how to create a custom PDF Viewer With JavaScript. It is working but I want to know if it's possible to render all pages at once.
Here's the link of the pdf.js full code in GitHub...
Is there an alternative way rather than sticking to this code?

How to turn a Django webpage into a PDF

I would like to add a feature to my Django website where the user can click on a link saying "Save as PDF". I would like this link to 1) produce a slightly different version of the page the user is currently on and 2) generate a PDF file in a separate window that the user can then save to wherever he or she wants.
All of the PDF functions I came across related to Django assumed that you already had a PDF that you wanted to render. In this case though, I want to create a PDF based on the content of the current page. Any idea how to do this? Thank you.
You can try this tool WeasyPrint. You can use it with Django
Any webpage is just a HTML basically so any html to pdf library would work. But this one is specifically built for django. Hope this helps.
Documentation for django-wkhtmltopdf

get image frames webcam from server with selenium python script

I need to take image frames from a webcam server using selenium python module.
The frames webcam is show on the selenium browser ( using http:// .....html webpage) .
The source code of the page show me it's done using some java script.
I try to use:
capture_network_traffic() and captureNetworkTraffic
Not working , also I don't think is a good way to do that.
Also I don't want to use capture_screenshot functions , this take all canvas of the browser.
Any idea ?
Thank you. Regards.
First, what you'll need to do is navigate to the webpage with Selenium.
Then, analyse the web page source HTML which the Javascript will have rendered by you navigating to the page, to get the image URL. You can do this with Selenium or with an HTML parser.
Then you can easily download the image using wget or some other URL grabber.
You might not even need Selenium to accomplish this if when you get the page, the image is already there. If that is the case you can just use the URL grabber to get the page directly.
Let me know if you want more details or if you have any questions.

Django image insertion in Admin

I am building a small side project - a simple news site. I want to use the Django Admin for uploading articles and allow access to non-coders so as they can publish articles a la Wordpress or such. I have added some functionality to the admin, first trying out TinyMCE and Dojo rich text editors. However, these do not come with the ability to insert an image into an article from a file (just urls).
I really only want some light text formatting in the text area plus the ability to upload and insert images from the users's harddrive directly into the article. Is there a simple way to achieve this?
If you are already using django-tinymce, you can integrate django-filebrowser with it. See django-tinymce's documentation.
There is also a commercial choice which looks good, but I have never tested it.

How to integrate multiple image uploading with UPLOADIFY in django administration?

I met the django-uploadify (multiple file uploading) application, but the only template-use is described in wiki of the project. I need to integrate it with django admin. Any ideas?
#rebus and #Mordi have good suggestions; one of those is probably your best bet. Still...
The current implementation of file uploads in web browsers is single file only. That's a limitation of the HTML standards and the browsers themselves. When you see multiple file upload capability (all at once / select multiple) in some web app, something like Flash or Java is in play. You could potentially use a Flash or Java applet (check out Uploadify - about the easiest to work with you'll find), if you wanted, but you'd have to do some work tying it into Django: namely mapping the output of the applet to the input the Django Admin expects on POST.
Personally I found this package to be painful when I attempted to do this locally. It is 7 years old and not maintained. django-filer is a more modern implementation that has this exact functionality built into the admin panel, it was quick to set up and it seems to be maintained a lot better. And the UI is excellent!
If your really set on using uploadify my attempt was quite painful. When I went to the website to download the uploadify jQuery plugin it was a paid download. After looking a bit I found a fork, and was able to get it going locally, but because the python package is old it required a lot of changes from python 2.7..
To integrate this with your project in the admin will definitely require you to write your own custom admin template. In your admin.py you would have to override the default template and methods, this faq has some insights. In your new template you would include the uploadify jquery script and put the upload file field inside the form where your model fields would be. When you upload files the signal sender in the package will fire, and you would just have to intercept the signal and handle it with your intended logic
Very easy to implement multiple image upload with this project:
https://github.com/tstone/django-uploadify