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

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?

Related

Does Django render JS on server side?

I know that Django has default config of SSR (server-side rendering) but all the articles I have gone through mention that the Django-forms are rendered on server side and then sent to the browser. No specific information on the use case when javascript is mixed in the template.
I want to know if I use jquery tables in my Django template. Does that still render on server side? If yes then how does it render Javascript/jquery on the server-side?
I'd be glad if someone corrects me if my question itself has invalid argument.
JavaScript is for browsers so it doesn't matter if you write it in your template or add a link to it. The only way to render JS on the server-side is to actually have an engine doing that for you which Django doesn't.
What Django's template engine does is it will render the template based on the tags and HTML you provided and sends a valid HTML to the user containing the js code or js files alongside CSS and then browser runs those js and CSS codes and renders the final webpage.

How to render a pdf file as pdf in browser using 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

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

django sorl-thumbnail json

I am using Sorl-Thumbnail to generate thumbnails within pages via template tags.
This all works perfectly fine.
However I have now added a store locator function to the site which feeds into my Google Maps JS via JSON.
In the infowindow popups I would like to put a tiny image of the storefront.
So I need to create another size of thumbnail and I need to include the URL for this within my JSON.
It seemed initially that Sorl doesnt support this due to its requirement for Tags within a page.
I have looked at the low level API version "get_thumbnail" and have tried to implement this within my Model without much luck so far.
I have no problem with my JSON and serialisation, just getting the thumbnail generated and into the model prior to this.
Has anyone had any experience with this scenario previously?
Cheers
Kev

How to begin creating a web application using a Python and xlrd/django script?

I'm not sure where to begin, as in do I start working towards PHP, Ruby or what, but here is what I'd like to do:
I have a Python script that takes a pre-formatted Excel document and using xlrd and Django, I output a nicely formatted HTML page, based on a template HTML page.
But currently on my team, I'm the only one that can use this Python script because our setups, and I'd like to simplify the process by creating a web app that has a couple drop down menus to specify which script to run, then let me upload the .xls file, at which point the HTML file is automatically generated and a download link is created or the HTML file is spit out somehow.
Does anyone have any guidance as to how I should even begin this project?
I would suggest having a good read of the django docs, and probably working through the tutorials.
Django's documentation is very good.
If you just want to hack at the code you've got then probably read the following to get a very basic overview of some core django functionality -
url dispatcher
views
models
forms
templating
With your app, the url dispatcher will pass the request to a view which will use a template to render your excel document.
You want a form to handle your user parameters and a single view to render and process the form and also render the excel template.