Categories > [old] TbsOoo & TinyDoc >

page breaks & a multiple page merged doc.

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: sam
Date: 2006-01-19
Time: 09:40

page breaks & a multiple page merged doc.

Hello all ,

I am querying a mysql db and able to get the records out. I can populate the tbs block OK but  I want each record to occur
*** ON A NEW PAGE ***. At the moment its coming out in the table going down as a list on 1 page.
Could anyone edit the code I've supplied to include the page break (section break?) whatever is needed so that the pref_name and the surname occur at the top of every page. ie if there is 10 records the following code needs to produce a 10page openoffice download.

Here is the OO template that lives on the server. I think the page break needs to go in here somewhere:

+--------------------------------------------------------------------+
+   Num    +  Firstname                             +    Surname     +
+--------------------------------------------------------------------+
+ [blk1.#] + [blk1.pref_name;block=table:table-row] + [blk1.surname] +
+--------------------------------------------------------------------+
+     [blk1;block=table:table-row;nodata]There is no data.           +
+--------------------------------------------------------------------+


Here is the php code to produce the OpenOffice download (OO)


<?php
include_once('../tbs_class.php');
include_once('../tbsooo_class.php');
include_once('../../../common.php');


$result= mysql_query ("SELECT * from 800lines limit 10");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
while($row = mysql_fetch_array($result))
{
$f[]=array(pref_name=>$row[pref_name],surname=>$row[surname]);
}

// instantiate a TBS OOo class
$OOo = new clsTinyButStrongOOo;

// setting the object
$OOo->SetZipBinary('zip');
$OOo->SetUnzipBinary('unzip');
$OOo->SetProcessDir('tmp/');

// create a new openoffice document from the template with an unique id
$OOo->NewDocFromTpl('sams_try4b.odt');

// merge data with openoffice file named 'content.xml'

$OOo->LoadXmlFromDoc('content.xml');
$OOo->MergeBlock('blk1',$f) ;
$OOo->SaveXmlToDoc();

// display
header('Content-type: '.$OOo->GetMimetypeDoc());
header('Content-Length: '.filesize($OOo->GetPathnameDoc()));
$OOo->FlushDoc();
$OOo->RemoveDoc();
?>

BTW is the way I have made the associative array $f[] the only way to get the fields out of the db?  Cant I get them out straight away since  $row[] is already an associative array? (ie is there the need to create $f[]?)

Thanks in advance
sam
By: Olivier Loynet
Date: 2006-01-19
Time: 11:09

Re: page breaks & a multiple page merged doc.

Hello Sam,

There are 2 methods to make page-break in OO text document for each row.

1/ Define the start and the end of the block (explicit syntax) with a PAGE BREAK inside the block

[BlockName;block=begin]
[BlockName.data1] [BlockName.data2]
PAGE-BREAK
[BlockName;block=end]

The TBS tags for the block definition will be deleted during the merging.

When the OOo document will be merge, you'll get a new page for each row, but it still remain a blank page at the end.

2/ Create a table with one row and one colum in your document.
Fix the height of the row to be more than the half the page height

When the OOo document will be merge, you'll get a row on each page with no blank page at the end

3/ I have heard about an another method, I've to ask to Skrol who made it.

Olivier

BTW : You don't have to pass the result from the query fetch in a array, you can merge block directly from a SQL request

$TBS->MergeBlock('blk1',$cnx_id,'SELECT * FROM t_tbs_exemples') ;



By: sam
Date: 2006-01-19
Time: 11:35

Re: page breaks & a multiple page merged doc.

Thanks for replying Olivier.
I'm working through your suggestions.

Firstly No 1
-----------
The code I used is as yours:
[BlockName;block=begin]
[BlockName.#] [BlockName.pref_name] [BlockName.surname]
PAGE-BREAK
[BlockName;block=end]

But the PAGE-BREAK is coming up as text all on 1 page, rather than a page break:

1 Rosie Abel
PAGE-BREAK

2 Breeanna Adams
PAGE-BREAK

3 Dave Adams
PAGE-BREAK
etc

Am I being silly or did you mean I should actually put a page break in via OO's insert->manual break->page break
OR is PAGE-BREAK not correct?

thanks sam
By: Olivier Loynet
Date: 2006-01-19
Time: 11:40

Re: page breaks & a multiple page merged doc.

Hello Sam,

As you said, you have to make a page break via insert->manual break->page break

Olivier
By: sam
Date: 2006-01-19
Time: 12:14

Re: page breaks & a multiple page merged doc.

Weird things.
First it worked! Excellent I thought it was solved.
ie It worked OK for about 5 merges giving outputs on new pages. (only did limit 10 so 10page docs)

then the error:

read error,Format error discovered in the file in sub-document content.xml at 2,3731(row,col)

I've tried it on another machine as well (both OpenOffice 2.0beta)

Now only the error occurs on both machines

sam
By: Skrol29
Date: 2006-01-19
Time: 13:15

Re: page breaks & a multiple page merged doc.

Hello Sam,

I sent to you a demo.sxw and a demo.php which show how to do this using OO sections.
Didn't you get them ?
By: sam
Date: 2006-01-19
Time: 13:18

Re: page breaks & a multiple page merged doc.

No,
the only emails I have got are from the postings from this forum.
Please send again:
sam@rwb.com.au
By: sam
Date: 2006-01-19
Time: 13:36

FIXED!! Re: page breaks & a multiple page merged doc.

Great stuff all is now working.
Ignore the read error from previous posting
I did the odt file from scratch and its working perfectly.
the code:
[BlockName;block=begin]
[BlockName.#] [BlockName.pref_name] [BlockName.surname]
PAGE-BREAK (insert->manual break->page break)
[BlockName;block=end]
works nicely now.

The php code:
<?php
include_once('../tbs_class.php');
include_once('../tbsooo_class.php');
include_once('../../../common.php');

// instantiate a TBS OOo class
$OOo = new clsTinyButStrongOOo;

// setting the object
$OOo->SetZipBinary('zip');
$OOo->SetUnzipBinary('unzip');
$OOo->SetProcessDir('tmp/');

// create a new openoffice document from the template with an unique id
$OOo->NewDocFromTpl('sams_try4cII.odt');

// merge data with openoffice file named 'content.xml'
$OOo->LoadXmlFromDoc('content.xml');
$OOo->MergeBlock('BlockName',$connection,'SELECT * from 800lines limit 100') ;
$OOo->SaveXmlToDoc();

// display
header('Content-type: '.$OOo->GetMimetypeDoc());
header('Content-Length: '.filesize($OOo->GetPathnameDoc()));
$OOo->FlushDoc();
$OOo->RemoveDoc();
?>
works with it.

Thanks for all your help indeed!
sam

BTW
I did read the class does not support dynamic images.
If my table has the location (relative) of the image of each person [BlockName.imagepath]
How can I get the image of each person on each page?
By: sam
Date: 2006-01-19
Time: 15:35

Nested page breaks across mysql queries

OK, I've tried but cannot do.
I have a mysql table with 5 school classes each with different number of students in each class.
Lets say:
class 1  has 15 students (fname,surname)
class 2  has 18 students (fname,surname)
class 3  has 22 students (fname,surname)
class 4  has 17 students (fname,surname)
class 5  has 20 students (fname,surname)

I'd like to merge them and put each class on a seperate page.
ie:
page 1 has class1 with a table of 15 rows down it
page 2 has class2 with a table of 18 rows down it
page 3 has class3 with a table of 22 rows down it
page 4 has class4 with a table of 17 rows down it
page 5 has class5 with a table of 20 rows down it

ie a 5 page openoffice doc.

I've tried using sublocks but still only get the one page (+1 page break as well=2page doc)

[data;block=begin]

[data2;block=begin]
[data2.fname] [data2.surname]
[data2;block=end]

PAGE-BREAK
[data;block=end]

The main codin in the php file is:
$sql1="select distinct(class) from table";
$sql2="select fname,surname from table";

$OOo->MergeBlock('data',$connection,$sql1) ;
$OOo->MergeBlock('data2',$connection,$sql2) ;


Any help would be appreciated

Thanks sam
By: zolcord
Date: 2006-11-28
Time: 13:55

Re: page breaks & a multiple page merged doc.

Je suis très interessé par les exemples en question.
Si c'est possible, merci de me les envoyer.
By: Skrol29
Date: 2006-12-11
Time: 18:09

Re: page breaks & a multiple page merged doc.

I post here the source of the content.xml subfile file for an ODT document which displays one rox per page using the section technique.
With this technique, the very first page is always blank. We can play to have the very last page blank instead.
<?xml version="1.0" encoding="UTF-8"?>
        <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0">
            <office:scripts/>
            <office:font-face-decls>
                <style:font-face style:name="Tahoma1" svg:font-family="Tahoma"/>
                <style:font-face style:name="Arial Unicode MS" svg:font-family="&apos;Arial Unicode MS&apos;" style:font-pitch="variable"/>
                <style:font-face style:name="MS Mincho" svg:font-family="&apos;MS Mincho&apos;" style:font-pitch="variable"/>
                <style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-pitch="variable"/>
                <style:font-face style:name="Times New Roman" svg:font-family="&apos;Times New Roman&apos;" style:font-family-generic="roman" style:font-pitch="variable"/>
                <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/>
            </office:font-face-decls>
            <office:automatic-styles>
                <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard">
                    <style:paragraph-properties fo:break-before="page"/>
                </style:style>
                <style:style style:name="Sect1" style:family="section">
                    <style:section-properties style:editable="false">
                        <style:columns fo:column-count="0" fo:column-gap="0cm"/>
                    </style:section-properties>
                </style:style>
            </office:automatic-styles>
            <office:body>
                <office:text>
                    <office:forms form:automatic-focus="false" form:apply-design-mode="false"/>
                    <text:sequence-decls>
                        <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/>
                        <text:sequence-decl text:display-outline-level="0" text:name="Table"/>
                        <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
                        <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
                    </text:sequence-decls>
                    <text:section text:style-name="Sect1" text:name="Section1">
                        <text:p text:style-name="Standard"/>
                        <text:p text:style-name="P1">
Firstname: [blk1.fn;block=text:section]
                        </text:p>
                        <text:p text:style-name="Standard">
Subname: [blk1.sn]
                        </text:p>
                        <text:p text:style-name="Standard">
Mark: [blk1.mark]
                        </text:p>
                    </text:section>
                </office:text>
            </office:body>
        </office:document-content>