berteh / ScribusGenerator

Create beautiful documents with data. Open source pdf (and Scribus) template and mail-merge alternative.
http://berteh.github.io/ScribusGenerator/
MIT License
243 stars 37 forks source link

Is conditional merging possible? #195

Closed w9ran closed 3 weeks ago

w9ran commented 2 years ago

I understand the process for creating multiple records on a single page and can successfully do so. But I'm wondering if Scribus Generator has the ability to test for conditions. An example might explain what I'd like to do best:

Imagine my csv file includes the names and some information about all the members of a club, and I want to create a document after each club meeting that includes dynamic text and images, but only for those who attended. So if there is, for example, 50 members data in my spreadsheet, after each meeting I'd like to add a special field to denote those who were in attendance (say, 27 people) and produce the merged document that would only include the data for those 27 members.

I can probably do what I want by sorting in the spreadsheet and then printing only partial data, selecting records 1-27, but I thought I'd ask first to see if there is a better way.

Thanks, Bob

berteh commented 2 years ago

Hi Bob. I would rather avoid implementing support for conditions (or loops) in ScribusGenerator (SG).

The main reason is that I would like the SG tool to be usable by graphic designers without needing to dive into coding, thus the SG template should be easy to edit via the GUI interface of Scribus... and I found no way to support such procedural instructions in an intuitive way therein. (The more "advanced dynamic parameters" of SG already require the user to dig into the SLA format to find the appropriate attribute name and values, and some XPATH understanding, which I already find way too technical).

The second reason is that it's actually quite easy to tailor a spreadsheet to handle very complex scenarios exporting to another spreadsheet just the subset of wanted data, using ifs or filter (in excel, openoffice, googlesheet), or the even more versatile query function (in googlesheet)... so you can actually get exactly the data you want, automatically updated with no extra work, just export the appropriate sheet to csv and run your generator. It can all be batch-run quite easily too.

I'm open to other arguments or suggestions... but really want to keep the "technical" requirement on SG as low as possible.

w9ran commented 2 years ago

Thanks Berteh, I understand your reasoning. The easiest way I can think of to implement such a feature would be to have a variable that could tell SG to "skip this record", but I'll do the subset in the spreadsheet. Mostly I wanted to make sure I wasn't overlooking a feature that already exists.

I do think there's a problem however when creating a document with multiple records on a single page. I can run SG with my full data set which produces perfect output, three columns of 14 items each or 42 total. But if I just tell SG to "use partial data", say from 1 to 12 - the result is a blank pdf document. The same is true if I just select .sla output. I've had no problem running SG normally (i.e. not with multiple records) using partial data.

Bob

berteh commented 2 years ago

Nope, no feature missed there. Will check partial+merge in #196.

berteh commented 2 years ago

And by the way yes, I think having one 'skip' variable would be acceptable on my 'not too technical' scale.

Would the opposite 'include only' be more intuitive?

w9ran commented 2 years ago

Either would work for me. Maybe the simplest method would be for the script to simply stop merging if it encounters a blank row in the spreadsheet file. To work around the problem I previously mentioned where selecting partial records causes the one-page pdf to appear blank, I sort my spreadsheet to put the desired records on top, then insert a bunch of empty rows before the unwanted records begin, and the result is just what I want - only the desired records appear. So this seems to be a sort of default behaviour, intentional or otherwise.

berteh commented 3 weeks ago

I won't implement the support for a "skip this line" (boolean) variable anytime soon, but remain open to checking/integrating a PR if anyone else wants to give it a try.