Forum How do I...?

Stop Prince from putting a page break between fetched URLS

bookdev
Could you please be so kind as to suggest how to stop Prince from putting a page break between the content of multiple URLs that have one or two paragraphs each, if you don't mind?

For example:

prince file1.htm file2.htm file3.htm file4.htm -o out.pdf

This creates four pages with one paragraph each. What I need is one page with the four paragraphs in newspaper style.

I'm laying out the content with the first header spanning two columns, followed by the paragraphs in a two column format. That should then be followed by the first header of the second URL spanning two columns (e.g. a newspaper style layout).

In the Prince style sheet I have experimented with variations on @page :first {page-break-before: avoid;}.

I have played with fetching the HTML from each URL first and combining them. On a simple combination Prince replied with "combination error: Extra content at the end of the document." Combining only the content between <body>..</body> Prince replied with hundreds of "error: ID content already defined."

I would like to avoid a massive restructuring of the documents (I'll be putting 100+ URL/documents in a PDF) before having Prince process them. But I need a 25 page PDF, not a 100 page PDF.

A search of the forums didn't turn up anyway to stop Prince from inserting a page break between each URL. Any suggestions, please?
mikeday
At the moment processing multiple documents is very similar to processing each document individually and concatenating the PDF files, so there will always be a page break between the subdocuments. One way around this is to use XInclude to glue all the documents together into one big document, avoiding this problem.
dauwhe
We've had a related issue, where we didn't want each new chapter in a book starting a new page. Since they were separate HTML files, we had to combine them before processing.
bookdev
Thanks, Mike. XInclude works great for a one column format.

Unfortunately, I need to do a three column format, incorporating Håkon's brilliant suggestion to float headings to the top and tables to the bottom so they run in a one column format.

The result is a mess. If three articles fit on a page then all of their headings jump to the top of the page and all of their tables drop to the bottom (or the next page).

A simple solution would be to apply a column-span:all to headings and tables.

In a forum search I found Håkon's comment:
Prince does not support the 'column-span' property, so you can't have tables that span multiple column unless you float them to the top or bottom.


I also found Mike’s posting from a year and a half ago that adding column-span is on the Road Map. Could you please be so kind as to let me know if you are likely to add it soon?

Alternatively, when you are merging three articles from three URLs into one PDF page using XInclude, is there anyway to float a heading/table to the top/bottom of the article and not the entire page?
mikeday
Prince 8.1 is now available, and supports "column-span: all".
bookdev
Could you please be so kind as to let me know the recommended way to apply column-span: all to tables in Prince 8.1, if you don't mind, Mike?

According to CSS documentation, column-span applies to all block-level elements, but neither table {column-span: all} nor table {column-span: all; display:block;) worked. And when I tried tr {column-span: all} the tables disappeared. Only div {column-span: all} worked.

However, I'm having trouble writing a program to surround all tables with <div></div> since nested tables end up as:
<div><table><table>...</table></div></table>
or
<div><table><div><table>...</table></div></table></div>
which also doesn't work.
mikeday
It seems that you have found a bug where column-span is not applying correctly to tables. We shall have to fix this in the next release. The workaround is to wrap up the table in a div element as you suggest. Are you using JavaScript to wrap it, or something else?
bookdev
Thanks for the confirmation, Mike.

I unsuccessfully tried to wrap nested tables with a single <div> using Regular Expressions.

I also tried:
<script type="text/javascript">
var wrapper = document.createElement('div');
wrapper.setAttribute('class', 'tabl');
var myDiv = document.getElementsByTagName('table');
wrapper.appendChild(myDiv.cloneNode(true));
myDiv.parentNode.replaceChild(wrapper, myDiv);
</script>

But Prince returned: TypeError: value is not an object
Any idea what I did wrong?
mikeday
getElementsByTagName() returns a NodeList, not a single node. You can wrap the tables like this:
var tables = document.body.getElementsByTagName("table");

for (var i = 0; i < tables.length; ++i)
{
    var table = tables[i];
    var parent = table.parentNode;
    var div = document.createElement("div");

    parent.insertBefore(div, table);
    parent.removeChild(table);
    div.appendChild(table);
}
bookdev
Yes, that works perfectly. Thanks, Mike!
mikeday
By the way, we have fixed the column-span issue now in Prince 8.1 rev 2, and there are packages available for Windows, MacOS X, and Ubuntu, with more coming soon.