As of now we are using XHTML2PDF to dynamically generate PDFs and outputting to browser whenever required. Now our requirements is changed to generate the PDF only once and store it in the server. The link should be displayed to user to view the PDF. Could you please point out any resources or snippets to achieve this?
Django provides a powerful form library that handles rendering forms as HTML, validating user-submitted data, and converting that data to native Python types. Django also provides a way to generate forms from your existing models and use those forms to create and update data.
It's not easy to learn Django if you don't have a strong foundational knowledge of Python. You don't need to learn everything in Python but at least make your fundamental concepts clear in Python to start with the Django application. Focus especially on classes and object-oriented programming in Python.
This is pretty easy to do. Observe:
from django.core.files.base import ContentFile
# get_pdf_contents should return the binary information for
# a properly formed pdf doc.
pdf_contents = get_pdf_contents()
file_to_be_saved = ContentFile(pdf_contents)
item = Item.objects.get(pk=1)
item.myfilefield.save('blarg.pdf', file_to_be_saved)
The get_pdf_contents function shouldn't be too hard to write - basically take whatever function you have already and chop it off before it funnels the results into an HttpResponse object. If you need help with that, post the code you have already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With