0

Let me provide a little background. An organization i am volunteering for delivers meals to people who are unable to come pick them up during the holidays. They currently have a SQL Server DB that stores the information of all their clients along with the meal information for each year. Currently a Java desktop application connects to the SQL Server DB and allows several functions to happen.

i.e. Add a client, add meals, remove clients, print delivery sheets.

I am hoping to use python Flask to rewrite the application as a web based application. The one function i am interested in at the moment is the print delivery sheets function.

The way this works is there is a setting for the current year. When you click the print deliveries for year button it will batch print a document for each customer onto an 8.5" x 11.5" paper. The sheet will be split in two with the same exact information on each side. This information includes the customer name, address, number of meals and so forth.

What i am wondering is how/what would be the best way to setup this template so that i could batch print it using python. I was thinking of creating an html template for the page but i am not sure how that would work.

Again i need to pass in every customer within that year into the template and batch print to 8.5" by 11.5" sheet.

What i am asking is.....

How could i create a template for the print that i can pass every customer two. How would i print that template for every customer in a batch manner for every customer.

I was hoping to do this all in python if possible. Thank you for your time and help.

hfrog713
  • 400
  • 1
  • 5
  • 18
  • Do you mean it will print a separate page for each customer in one batch, or it will batch print all deliveries/invoices for a single person? – Edward Minnix Jun 18 '18 at 19:38
  • What i mean is, that with one button click it will print a separate page for each customer in the batch. So the template would need to be customized as many times as there are customers and then printed for each one. Please let me know if this is clear. Thanks. – hfrog713 Jun 18 '18 at 21:23

1 Answers1

0

If you are already deploying this as a web app, it will probably be easier to design and generate a pdf. You can use an html to pdf converter, which there are several of on PyPI, or there are plenty of resources online, such as:

Once you have found a way to generate PDFs, you can then just use them like any other PDF, and either have the user download them or print them from the browser (this may require a little bit of Javascript, but this shouldn't be that hard since it should pretty much just be a window.open call.

For instance, you can add a button

<button onclick="getPDF()">Download PDF</button>

Which will then call a function called getPDF() which you define, which finds a way to generate the pdf.

function getPDF() {
  // Find the uri for the pdf by some method
  var urlToPdf = getUrlToPdf();

  // Open PDF in new window
  window.open(urlToPdf, "_blank");
}

Note Since you are using Flask, you can include the URL for the pdf in the source for the page, even the Javascript using the {{ }} syntax. Then the pdfs are only generated when someone requests that route.

This way you will not have to worry about connecting to a printer yourself at all, just use the browser to handle those kinds of tasks.

Edward Minnix
  • 2,889
  • 1
  • 13
  • 26
  • Hi Edward, i appreciate the quick reply. It is currently deployed as a java application but i would like to convert it to a web application. What i am still a little confused about is that i would like to print this in a batch form, without having to display the PDF for say all ~500 clients. I want to be able to click the button once, and print a sheet for each of the clients for that year. – hfrog713 Jun 18 '18 at 21:18
  • For that, the easiest solution would probably be to find a way to create one 500-page PDF with a separate page for each customer. The user would still need to open-then-print, but this way it would only be one PDF instead of hundreds of documents. – Edward Minnix Jun 18 '18 at 21:35