Automatically Create Number of Pages for Content

Previous topic - Next topic

Luke.Whitehorn

I'm looking at ways of automating some document generation and so far Scribus looks like the best candidate. However there's one element that I cannot find information on, so I'm wondering if someone here can enlighten me.
Via scripting, I will be loading document content. Now that content may be a small amount of text, or a large amount that will span multiple pages. Does Scribus have the ability to handle this natively or script it? I would love to hear your recommendations on how you would go about this.

dragonfly

#1
Intuitively .. I would try creating a python script which first calculates the area of the text corpus - taking into account font sizes, page breaks etc. rather than just characters - and then calculating the number of textframes/pages to match.

Another thought .. it could be that parsing markdown would allow text layout such as insets, paragraph breaks to be reflected. I use Atom editor plus Markdown Preview Enhanced package for document creation.   I envisage that this can be used to break content into blocks to import into Scribus textframes. For example markdown through pandoc can output slides, and instead of slides think "export slide to textframe".

The advantage is that you can preview each textframe (like an HTML revealjs slidedeck) before injecting into Scribus textframes. The markdown can also be exported as beamer (pdf) slides which can be imported into image frames.

I have also found in experiments that I can use PHP server to generate sla as xml file. You can then dynamically expand number of pages  and output xml as sla. I have found that I can also use this workflow to dynamically change content in svg objects.

Another approach would be to amend Scribus Generator python script where VAR's pointing to text blocks can be injected into a series of textframes.  Each textframe would then import the text linked through VAR. You would produce a csv file which is a table showing
VAR_text1 -> path_to_textblock1
VAR_text2 -> path_to_textblock2
VAR_text3 -> path_to_textblock3
VAR_text4 -> path_to_textblock4

Study ScribusGenerator video to see the approach .. but instead of short text vars you would need to expand links to blocks perhaps in a database.

So these are a few ideas off the top of my head.

Luke.Whitehorn

Thanks dragonfly, those are a good few avenues to explore. Your first instinct
QuoteI would try creating a python script which first calculates the area of the text corpus
was the same as mine. However, it feels like this could be very awkward to figure out. I've looked over the python API here https://impagina.org/scribus-scripter-api/ and there doesn't seem like there's any built in functions for this.
Another thing is that I will absolutely need tables and currently there doesn't seem to be any function in the API to actually set a cell's contents.

I've done back and forth between Scribus and LaTeX, but Scribus feels quiet solid and LaTeX is just horrible to use.

Editing the XML directly is another option, but will eliminate the ability to see if text is overflowing, so I think it has to be done via the Scribus exe.

dragonfly

QuoteEditing the XML directly is another option, but will eliminate the ability to see if text is overflowing, so I think it has to be done via the Scribus exe.

I had in mind auto linking all text frames in the template *.sla (xml) but you might wish to force a break - e.g. not to break an embedded table if table straddles two pages/textframes.

You could insert a PHP tage in at points where you want to force break, otherwise it is assumed all linked textframes.  Unused pages ar end with empty textframes would be stripped out.

When printing the final *.sla using PHP you would need PHP header type xml.

RobSay

Quote from: Luke.Whitehorn on December 23, 2020, 11:27:53 PM
Via scripting, I will be loading document content. Now that content may be a small amount of text, or a large amount that will span multiple pages. Does Scribus have the ability to handle this natively or script it? I would love to hear your recommendations on how you would go about this.

Yes,- I did exactly this in the scripter with ~20 pages of content that I regenerate as the source changes.

In your script:

  • Select the page you want the content to start in
  • Create a text frame of the appropriate size on that page, format as needed
  • Add *all* of the content from you source to this frame
  • check if the text frame is overflowing (using textOverflows(frameName, 1) ) - if you get a non-zero result you need another frame
  • move to, or add the next page, insert a text frame
  • link your new frame to the previous, test for overflow in the new frame, rinse and repeat
  • Use getAllText to select content across all of the linked frames and apply paragraph style formatting as needed

It is faster / easier to create the linked frames up front if you know the content length .. or can estimate it. Create the maximum frames you need, add text and delete empty frames from the end of the collection.

Rob