Mail merge in ruby on rails, but in big numbers - ruby-on-rails

I am trying to implement sort of mail merge for printed documents in Ruby on Rails 3.2. I have about 8000 recipients and template origin in Microsoft Word. Template includes images (photos) and contains about 10-20 pages.
Actual situation is, that I rewritten original template to Textile (redcloth) and pictures are inserted from internet (http address). I did all personalisation etc. So I generate HTML file and must divide it to many small files each for 1000 pages. Total I need print about 8000 x 20 pages = 160.000 pages.
Anyone know how to print it to PDF from HTML? Or how to insert commands for changing paper tray (for first and last page) or for binding after each 20 pages etc?
Thank you for any idea :-)

Here's one idea: in your rails app, set it up to return one html per user. Also, have a nice /users/ index method that returns a list of users in something convenient, maybe json format.
Now, you want a local script, written in ruby, bash, whatever is convenient, to:
fetch a list of users from that /users/ method, probably save it to a file
loop over the list of users (from the file, so they're not all in memory), and fetch the HTML of the email
generate pdf from each HTML downloaded, either inside the loop, or loop over files in a directory where you saved the HTML. Use wkhtmltopdf or similar.
send each pdf to the printer, again either inside the same loop, or loop over the saved pdf's.
If you wanted to get fancy, and a little more efficient, you could use a queueing system like resque, and make each of those bullet points into a queue, and run one worker per queue. That would let you start printing some pdfs while others were still being downloaded and converted, so it should be less time overall. But if you're not already familiar with a queuing system like that, a simple script should get it done as well.

Related

How do you print different templates in netsuite?

I am trying to find the correct template and id to use for a hotprint of an advanced pdf template of an Item Fulfillment.
The hot print url is (with the id bolded) https://system.na3.netsuite.com/app/accounting/print/hotprint.nl?regular=T&sethotprinter=T&id=7600&label=Packing%20Slip&printtype=packingslip&trantype=itemship&orgtrantype=TrnfrOrd&auxtrans=7605
For some reason only certain id=# seems to affect the outcome and the ids I have got to work for two different templates don't match the Custom Transaction Forms ID or the Advanced pdf script id. (example most ids=template 1, while 168,4954, and seemingly random other ids=template 2) I am very confused on how netsuite resolves the hot print url as it normally doesn't include the template= part though I have seen others use it for invoice print urls.
The parameters at the end of the url (the stuff after the ?) are used by Netsuite to control settings used by the webpage which prints the PDFs for you.
In this case, &id=##### refers to the internal id of the document you are printing. You can see this by going to the document, right clicking, selecting inspect, and typing nlapiGetRecordId() into the console. When you click Print, you should see that same number after &id=#####.
&template=### refers to the template you are printing. If you go to Customization -> Forms -> Advanced PDF/HTML Templates, you'll notice a Script ID field in the table. If you substitute the correct Script ID in for the number in &template=###, you'll notice you generate the same PDF. This Script ID acts the same as the number that was previously there.
The reason you're seeing unusual results when you change those numbers is because you're mismatching a record with a template not built for it. So it won't print exactly right, but will sometimes execute anyways.
Anyways, this sort of parameter scheme is a similar scheme to how Suitelets and Restlets work, so in the future, you might experience this sort of thing again.
EDIT: For those reading this in the future, please read the comments.
To customize a packing slip and return form:
If you are printing packing slips and need some customization, you can use a custom invoice form when printing packing slips. For example, you can customize an invoice form to hide the fulfilled item tax rate and amount, and the order total. Then, when you print the packing slip using the custom form through mass print, choose the the packing slip shows the customized information.

TCPDF: In a single document, using multiple page formats, it doesn't print out on correct paper

I'm creating a document that consists of an 8.5"x11" survey, a #10 envelope and a #9 return-envelope. I use the appropriate AddPage calls and the resulting PDF appears to have all of the correct formatting.
When I print it, though, every page only comes out on 8.5"x11" paper...
Is there something in particular that I need to be doing to enable multiple page formats in a single document?
So, it appears that this is an issue with each particular reader/viewer, where, as far as I can tell, the end user is required, on a case by case basis, to manually override using the default paper size and tell the print engine to use the paper size(s) specified by the document instead. It's frustrating that this wouldn't be the default configuration, but this appears to be the only solution that I could find.

YAT: Save final console output to file

I want to save final data from console output to file without intermediate.
How can i do that?
The report module exports all info into html in JSON format. You can get some info from there (cumulative percentiles, for example). You even don't have to modify python code in that case, just add some JS to the page that generates a table.
On the other hand, if you want something more then that info included there, you should implement it in the report module.
What particular pieces of last screen data are you interested in?
P.S by the way, one may create a couple of templates and then provide the template parameter in report section of load.ini to specify which one you want to use.
This screen is good report only for "const" benchmarking. For "line" and "step" ramping the last screen always demonstrates the worst timings and resources. But we are thinking about this feature request.

Parsing a CSV for Database Insertion when Formatted Incorrectly

I recently wrote a mailing platform for one of our employees to use. The system runs great, scales great, and is fun to use. However, it is currently inoperable due to a bug that I can't figure out how to fix (fairly inexperienced developer).
The process goes something like this...
Upload a CSV file to a specific FTP directory.
Go to the import_mailing_list page.
Choose a CSV file within the FTP directory.
Name and describe what the list contains.
Associate file headings with database columns.
Then, the back-end loops over each line of the file, associating the values with a heading, and importing these values into a database.
This all works wonderfully, except in a specific case, when a raw CSV is not correctly formatted. For example...
fname, lname, email
Bob, Schlumberger, bob#bob.com
Bobbette, Schlumberger
Another, Record, goeshere#email.com
As you can see, there is a missing comma on line two. This would cause an error when attempting to pull "valArray[3]" (or valArray[2], in the case of every language but mine).
I am looking for the most efficient solution to keep this error from happening. Perhaps I should check the array length, and compare it to the index we're going to attempt to pull, before pulling it. But to do this for each and every value seems inefficient. Anybody have another idea?
Our stack is ColdFusion 8/9 and MySQL 5.1. This is why I refer to the array index as [3].
There's ArrayIsDefined(array, elementIndex), or ArrayLen(array)
seems inefficient?
You gotta code what you need to code, forget about inefficiency. Get it right before you get it fast (when needed).
I suppose if you are looking for another way of doing this (instead of checking the array length each time, although that really doesn't sound that bad to me), you could wrap each line insert attempt in a try/catch block. If it fails, then stuff the failed row in a buffer (including the line number and error message) that you could then display to the user after the batch has completed, so they could see each of the failed lines and why they failed. This has the advantages of 1) not having to explicitly check the array length each time and 2) catching other errors that you might not have anticipated beforehand (maybe a value is too long for your field, for example).

rails best way to receive xml data from flex application

Can anybody give me any hints on that? I'm able to display xml content on my swf file but how can I send the changed xml file back to my rails Server?
Thanks in advance!
Markus
RestfulX is by far the best way to do this with Rails :).
Check out their cool examples to get running, it takes 5 minutes. You can generate an application based on models (like Page/Post/Comment/Category...) that'll look like this:
(source: github.com)
You basically run 3 commands and you have a full CMS. And, by default, everything happens via XML, but that's converted (serialized and deserialized) to and from xml, so you can use class objects in ActionScript. You can easily change that to AMF/JSON if you needed to, which is very powerful. Then you can customize everything from there: create a class (MyVideo), add properties (title, url, description, comments), manipulate them in ActionScript, then just do create/update/destroy/save/show, and it handles all the xml requests to/from Rails.
They've solved hardcore things like authentication and session management, file uploading, nested sets and list, etc, which you've probably already run into or will. It's very cool.
Everything works via REST (and CRUD operations), which Rails takes full advantage of. If you just want to use ruby (and not Rails), you can do that no problem. Or if you just wanted to use Flex and no backend, but still wanted to read/write XML without having to create a whole library to handle that, same thing; they handle it all.
You just do:
Rx.models.index(Project) (if you had a my.package.Project class), and it'd return:
<?xml version="1.0" encoding="UTF-8"?>
<projects type="array">
<project>
<completed type="boolean">false</completed>
<created_at type="datetime">2008/07/09 20:08:28</created_at>
<end_date type="date">2008/07/09</end_date>
<id type="integer">490909803</id>
<name>Project4NameString</name>
<notes>Project4NotesText</notes>
<start_date type="date">2008/07/09</start_date>
<updated_at type="datetime">2008/07/09 20:08:28</updated_at>
<user_id type="integer">276171944</user_id>
</project>
</projects>
Then if you wanted to save it (or delete it), you'd just do something like:
var projects:IList = Rx.models.index(Project);
var project:Project = projects.getItemAt(0); // first item in IList;
project.title = "My New Title!";
project.save();
// then later, maybe onClick for a Button with label "Delete Project"...
project.delete();
This is by far the best library for XML processing. And they have a very active group which is a plus.
I saw you asked this question about writing xml via Flex. You'll run into lots of edge cases. Try out RestfulX, it's super sick.
Hope that helps.

Resources