Scribusoid

Author Topic: Automatically Create Number of Pages for Content  (Read 785 times)

Luke.Whitehorn

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
  • Scribus User
Automatically Create Number of Pages for Content
« on: December 24, 2020, 12:27:53 am »
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

  • Full Member
  • ***
  • Posts: 204
  • Karma: 0
  • Scribus User
Re: Automatically Create Number of Pages for Content
« Reply #1 on: December 24, 2020, 03:21:39 pm »
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.
« Last Edit: December 24, 2020, 03:25:31 pm by dragonfly »

Luke.Whitehorn

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
  • Scribus User
Re: Automatically Create Number of Pages for Content
« Reply #2 on: December 24, 2020, 07:20:26 pm »
Thanks dragonfly, those are a good few avenues to explore. Your first instinct
Quote
I 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

  • Full Member
  • ***
  • Posts: 204
  • Karma: 0
  • Scribus User
Re: Automatically Create Number of Pages for Content
« Reply #3 on: December 24, 2020, 10:41:18 pm »
Quote
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.

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

  • Newbie
  • *
  • Posts: 33
  • Karma: 0
  • Scribus User
Re: Automatically Create Number of Pages for Content
« Reply #4 on: February 18, 2021, 06:20:34 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

 

palmate