Import XML to pre-generated PDF FORMS - python

I am trying to import XML data into pre-fixed PDF form. The PDF forms are elaborate and have many named fields. An example of two named fields are "Consequence" and "Cause". So, for this example i will have an XML as following :
<multiple>
<Causes> leak </Causes>
<Consequences> fire and explosion </Consequences>
</multiple>
How do I do import this XML into specific PDF form fields programatically? I would prefer Python however I am okay if it is JavaScript

Related

Python: Extract fields from pdf forms into pandas df?

I have a bunch of pdf forms with fillable text/date fields. I would like to build a script with a function that reads pdf fields and parses them into a dataframe. Does anyone with experience doing this know the best place to start?

Upload XML Files in Django, Parse XML & Compare with existing models dataset

Can someone give me a better approach for below use case please ?
upload XML file
Scan XML file with specific tags
Store required data in which format ? (I thought of building JSON dump ?)
I have data in different models for different components.
How can i compare data that i have in step3 with django models and produce some output ? ( Sort of data comparison )
Note : JSON Dump which i get at step 3 is full dump of required data and data at step 4 is being referred to small small chunks of data which has to be combined and compared against recently uploaded file JSON Dump
I would define a Model where you can store the uploaded file and a form.
(https://docs.djangoproject.com/en/3.2/topics/http/file-uploads/#handling-uploaded-files-with-a-model)
Either use lxml etree or generateDS to scan XML Files. (https://www.davekuhlman.org/generateDS.html)
To store you can use a JSON-Dump or a Picklefield where you can store the Object of the XML-File in it, if you use generateDS
Store the data in a the Database and write a model for it in Django. Try to make it as granular as possible so you can compare the new XML-File when you import it and maybe only store the difference as Objects with Pickle.
Hope that helps a bit.

Export PDF with pre-filled and unfilled editable fields

I am trying to print out custom commercial invoices based on a known set of data and allowing for an unknown set of data. My known data includes addresses, general contact information, etc.
What I want is to be able to use a PDF template of a "commercial invoice" and have the known data auto-populated into the form where available. Then, the user can download the (incomplete) PDF and fill in the empty / optional form fields using their own collection of information - stuff like Tax ID, recipient care-of names, internal tracking ids, etc.
How can I use JSON / XML + python + HTML + a PDF template to auto-fill some info and leave some info empty, on an editable PDF form?
Thanks!
You essentially want server-side filling of the form.
There are several possible approaches.
An industry-strength approach would be using a dedicated application which could be called via command line (FDFMerge by Appligent comes to my mind, which is very easy to integrate, as all you'd have to do is to assemble the FDF data, and then the command string).
Another approach is to use one of the PDF creating libraries out there (iText, pdflib or Adobe's PDF Library come to my mind here). In this case, you have considerably more programming effort, but may have somewhat more flexibility.

How do I access PDF form fields with python

I need to automatically save pdf form fields to a database and write some of them later to new forms I am sending out. I can save the fields no problem but I don't know how to write to a PDF form field .. I am using pdf miner but I can't find anything in it to do this.
Can any one point me in the direction of a solution?
Reports labs has a open source PDF kit that let you write PDFs, including form fields http://www.reportlab.com. They also have commercial product the reads PDFs. But I've only used the open source version.
I've never used it, but people seem to like PyPDF

Django: how do I render an XML file, then use that xml in a simultaneously rendered view?

What I'm trying to do is use a SIMILE timeline in my Django app. The timeline requires it's data in an XML file. Now, I know how to render a view in html. And I can probably figure out how to render a view into XML. But how would one render both, then pull in the XML data to the HTML file if the XML file doesn't exist on disk (since it is being generated by Django)?
Thanks!
Edit: The line that takes the XML is in Javascript, and looks like this:
Timeline.loadXML("/static/example1.xml", function(xml,url) {eventSource.loadXML(xml,url); })
I need a path, since inserting the XML directly as a string doesn't work. But no path exists, since the XML file never actually exists on disk.
You seem to be trying to cram too many things into the same view.
What I'd do is the following:
Create a view that generates the XML (every request to the view should generate the XML from scratch).
Create a view that uses the timeline widget and points it to the XML in 1)
Enable Django's caching layer and annotate the XML view appropriately. E.g., #cache_page(60 * 60)
If, for some reason, you need the XML at the time of generation of the HTML (as you seem to indicate in your title), you can just directly call your XML view from the HTML one. E.g.:
#cache_page(..)
def xml(request):
# ... generate xml
def html(request):
xml = xml(request)
# ... generate timeline from xml
Of course, there's nothing stopping you from manually caching to disk but it's easier to just use Django's facilities.
You don't need to generate your XML in a view. Just create an XML template, render it to string, and write the result to a temp file.

Categories