berteh / ScribusGenerator

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

How to set my layout as portrait or landscape dynamically #221

Closed ignutanz closed 3 months ago

ignutanz commented 6 months ago

My csv will specify in each row whether the layout has to be portrait or landscape. How can i make each generated sla be in the layout specified in each row. eg; If the layout is specified as landscape in the row, the corresponding generated sla should be in landscape layout

berteh commented 6 months ago

If I understand correctly you want to specify the current page orientation, right?

Never tried it yet but it should be feasible.

First you gotta identify the attribute(s) and value(s) that change in the SLA when switching layout. For this I'd recommend saving one empty SLA file with portrait layout, then switching its layout, saving under another name and using any open source 'text diff' tool to identify the differences between the 2 files. I guess at least the page width and height will have changed, and maybe some other attribute as well.

Second you should create data columns for these values and attributes in you data set, eg one column 'page-height', 'page-width', and any other required (text or number) value/attribute.

Lastly create one SG dynamic attribute in your SG template (see readme 'advanced' section or video tutorial) for each of these changing values.

Finding out the exact syntax for the XPATH selector of the dynamic attribute can be a bit tricky but it 'simply' boils down to the list of parents elements in the XML tree of the SLA file. One way to see this tree more explicitly is to rename one of your empty layout test SLA file with an '.xml' extension and open it in a web browser (Firefox, chrome,...): they usually show xml files as collapsible trees. Look for a quick introduction to the XPATH selector syntax may help (you may have seen something close in advanced CSS syntax, that is based on XPATH).

Good luck. Kindly let me know how this works for you. If it's too technical let me know or ask again here, and I (or someone else) might be able to help.

Greetings. B.

ignutanz commented 6 months ago

I created one landscape file and a copy of it changing orientation to portrait. I find the following changes using diffchecker showing changes in portrait as compared to the landscape file:

How should i create the SGAttributes. I need to give the orientation through csv file. but what about other parameters which change when the orientation changes. should i specify the pagewidth and pageheight through csv.

ignutanz commented 6 months ago

I added an SGAttribute named ORIENTATION with value %VAR_orientation% and provided a column inside the csv input with values as 0 and 1 on alternative rows. But I find that all the generated sla files are still in the landscape orientation.

ignutanz commented 6 months ago

i find that the orientation and pagewidth,pageheight changes in the attributes of the resulting file while passing it through the csv input file, but visually there is no difference!!

DavidPesticcio commented 4 months ago

Just a thought - but I suspect the values that changed are needed together to inform other things - the dimensions of a page are essentially irrelevant without an orientation, certainly to a printer etc.

I.e. the shape is not an indication of it's orientation, except by convention or prior knowledge.

A bit like the marker on a map to inform you of which direction is North, the map itself tells you nothing unless you know already this - hence the symbol for North. :smiley:

berteh commented 3 months ago

Hello. I tried really hard to implement this, but to no avail. Sorry.

I did find a way to tailor objects width and position per the size of their parent page, but you still need to click on each page and change it's orientation manually. It goes fast but is still manual.

If interested attached is a sample template and Spreadsheet used to compute the relate page dimension, positions and objects locations. test is using the dimensions of "Letter" format, but easily adapted to others.

orientation-calculator.ods orientation-test.sla.txt orientation-test.csv

objects are already in place or stretched per page orientation, but page "background" still needs to be manually rotated before getting the expected result: image

If you're interested in the technical specifics of the obstactle (and for my own note): I find no way to store the (new/oriented) page size information on the Scribus (XML) <PAGE> element... as this one does not support the "Attribute" mechanism available only on <PAGEOBJECT>. And since Scribus does not store the <PAGEOBJECT> as a child of its parent <PAGE> but at a random place in the SLA files (likely by order of creation?) I cannot easily find the parent page of an SGAttribute to orient the said page accordingly. To make things even worse the XPath engine of eTree does not support advanced queries, making other type of relations (eg current-position()-1) unusable, that would have been a possible workaround for "simple" templates containing a single page to be oriented/resized: https://docs.python.org/3/library/xml.etree.elementtree.html#supported-xpath-syntax