Pagebreak (or table break?) to obtain a good formated PDF - php

I had develop an intranet on CakePHP which in one part generates a custom PDF using DOMPDF. The problem is that I have a memo field (mysql text) which I print after getting the result from PHP nl2br function.
The problems is that in some occasions, this text is too long (even on font-size: 6px) and I need some way to make a page break (get again de header, and footer etc)... or maybe a nice way to get a second column to continue with the text inside.
any ideas?

Got this from Google, http://www.digitaljunkies.ca/dompdf/faq.php#page_break . It doesn't solve the secondary question regarding the repeated header and footer, however. Something like http://www.xefteri.com/articles/show.cfm?id=26 might help with that (not recommended).

Is your header just around the memo field? If so you can put your memo field in a table and use a thead/tfoot section for the header/footer. When the table moves to the second page it should be displayed again (though I believe there are problems with tfoot handling).
If these are document-wide headers and footers you could use inline PHP (see also the FAQ). Or, if you're using the latest release (0.6.0 alpha 2) and are up to patching you could add fixed positioning support and use that to create a header/footer.
See the DOMPDF developer site for more information.
If you have a sample document it might be easier to visualize the problem.

You can do it in two ways
One of them is using a section, on pagebreaks, dompdf will repeat the header. You can force a pagebreak using CSS attribute page-break-before:always
The second option is using PHP to draw the header/footer using $pdf->page_text() function like this
http://www.digitaljunkies.ca/dompdf/faq.php#footers

Related

PHPWord Prevent rows from the same table appearing on different pages

thanks for help with previous PHPWord issue. I have another.
I'm creating documents with tables where each table is basically used as a stylized container for a list of items. For example, in my case i have a collection of legal definitions. Each definition has a code, title, and textual description that appears in a table. So when there's multiple definitions, each definition has its own table, and appears like so:
and so on. Each table isnt really a table, its more i'm kind of hijacking tables to stylize my document. The problem is when I have a long list of items, invariably some of the tables will be split between pages where the top row of the table will be at the very bottom of the page and bottom row of the table will be at the very top of the next page, like so
This is very undesired. Is there any way to tell PHP word that "hey, if this table is going to be split between pages, just put the whole table on the next page" ??
I'm also using PDFmake for making pdf's and it has a pageBreakBefore function that can be used for exactly this purpose. I notice that paragraphs have a pageBreakBefore style which can force each pragraph to appear on a new page, but this isnt what i'm looking for. Is there some way i can maybe get into how PHPWord builds the document to put a conditional test in maybe?
Any input is greatly appreciated thanks.
I had the same problem .... and found the answer today in "normal" MsWord documentation. I found the equivalent in the phpWord doucmentation, tried it and it works:
In your paragraph formats, set 'keepNext' => true

OpenTBS/PHP/Word - How can I repeat the first-page-header in block=tbs:page settings

I am creating a multipage Word serial letter with OpenTBS using the [letter.tag;block=tbs:page] method as described in the OpenTBS demo. This works quite fine after I rebuilt the whole template from scratch, since the original resulted in corrupted .docx-files for a not well understood reason.
In this template, only the header of the first page contains the letterhead, all following pages have other, less verbose headers and footers.
The problem
OpenTBS now repeats a page break and the content for every element of the block as expected, but (also expected, but not wanted) uses the default headers and footers for that.
What I want instead
Since it is a serial letter, I want the first page header on the first page of each repetition and the standard header and footer for the following pages of each repetition.
How you can help me
So does anyone have an idea how to achieve this? I would work with sections, but the original template used those and they broke the whole thing, when they were processed with OpenTBS.
Ho do you implement serial letters with Word and OpenTBS?
My workaround
For now, I copied the stuff from the header/footer directly to the first page and disabled differing header/footer for the first page. So OpenTBS can repeat it correctly. But this only works, because only the the header differs on the first page. Not the right solution.
They are 3 types of headers and footers in Microsoft Word : Default, Even (for even numbered pages only) and First (for the first page only). Event and First types are optional.
Each section of the document may have its own set of header/footer of the 3 types, but by default a new section has his headers/footers linked with the previous sections.
So, obviously you cannot use the Even type for your template (unless by chance each letter has exactly 2 pages).
So the only way you have left for changing headers in the same Ms Word document is to use sections (as you felt it).
You will need 2 sections: one section for the first page of a letter, and one section for other pages of a letter. Use a Default typed header for each sections. In Ms Word this is to have both options Different first page and Different odd and even pages unchecked.
In order to set a section with a different set of header/footer you just have to uncheck the option Link to previous.

using php to get two even columns of text

Does anyone know a clever way to create even columns of text using php?
So lets say I have a few paragraphs of text and I want to split this into two columns of even length (not string length, I'm talking even visible length).
At the moment I'm splitting based on word count, which (as you can imagine) isn't working too well. For instance, on one page I have a list (ul li style) which is increasing the line breaks but not the word count. eg: whats happening is that the left column (with the list in it) is visibly longer than the right column (and if there was a list in the right hand column then it would be the same the other way round).
So does anyone have a clever way to split text? For instance using my knowledge of objective c there is a "size that fits" function. I know how wide the columns are going to be, so is there any way to take that, and the string, and work out how high its going to be? Then cut it in half? Or similar?
Thanks
ps: no css3 nonsense please, we're targeting browsers as far back as ie6 (shudder). :)
I know you're looking at a PHP solution but since the number of lines will depend on how it's rendered in the browser, you'll need to use some javascript.
You basically need to know the dimensions of the container the text is in and using the height divided by the text's line-height, you'll get the number of lines.
Here's a fiddle using jQuery: http://jsfiddle.net/bh8ZR/
There is not a lot of information here as to the source data. However, if you know that you have 20 lines of data, and want to split it, why not simply use an array of the display lines, then divide by two. Then you can take the first half of the PHP array and push it into the second column when you hit the limit of the first.
I think you're going to have trouble displaying these columns in a web browser and having a consistent look and feel because you're trying to apply simple programming logic to a visual layout. CSS and jQuery were designed to help layout issues. jQuery does have IE6 compatibility.
I really don't think you're going to find a magic bullet here if you have HTML formatting inside the data you're trying to display. The browser is going to render this based on a lot of variables. Page width, font size, etc. This is exactly why CSS and other layout styles are there, to handle this sort of formatting.
Is there any reason why you're not trying to solve this in the browser instead of PHP? IE6 to me is not a strong enough case not to do this where it belongs.

Multiple column articles in Joomla

I've got a client that requires that an article be displayed in two, sometimes three, columns in Joomla. I am fairly sure they won't be happy with having to edit 3 articles for 3 columns so the splitting would have to be done automatically.
I've done something similar before where it'll split a chunk of HTML into n columns, but have no real idea how to accomplish this within Joomla itself.
Any ideas gratefully recieved!
An alternative approach:
Use Javascript to split up the Article in several column in the browser. Here I could imagine a full-automated approach could work.
Advantages (over the first approach):
As Javascript can know, which height the paragraphs actually have in the browser (unlinke PHP), you could find the optimum split more accurately.
This can be implemented in the template php-File: you tell the template to include the js-File. So it could be made context-dependent,E.g.: If the left column is collapsed (because there are no modules in it), tell the JavaScript-File to initialize to 3 columns, else 2 columns.
However, have in mind that it should rest usable for those who have Javascript disabled.
This doesn't seem to be easy.
At first thought this should be an CSS attribute, but if it exists, it is part of CSS 3.0 and as such only understood by modern browsers (if at all). But I didn't find any way to do this in CSS.
So you actually have to modify your HTML code. I would propose the following:
A Button (editor-xtd plugin) that splits the article into several parts, each one for one column, showing a dotted line in the editor box (similar to the "read-more"-Button).
E.g. it inserts in the article: (you will have to define hr.column in /templates/system/css/editor.css).
A (content) plugin that creates the multiple colum-style,
E.g. replacing the hr-Tag with table or floating divs.
This way, it is half-automized, without mangeling in the Joomla! files but only adding to extensions to it.
the CSS 3 rules for multi-columns are:
-column-width
-column-gap
-column-rule
-column-count
with the vendor label (-moz, -webkit) before.
More info at http://www.css3.info/preview/multi-column-layout/
I would use css and tell the people with Explorer to change browser! (i'm jocking of course)
Otherwise javascript is the way like said before. This script should do (not tested) http://13thparallel.com/archive/column-script/
This should be done through the template, some PHP coding is involved.
One of our clients asked us to do the exact same thing before, and we have done it through template. Note that for very small articles we increased the font in order to split the article into 3 columns.

How can I convert language of a div?

I am recently working in a project. There I need to convert language from English to Japanese by button click event. The text is in a div. Like this:
"<div id="sampletext"> here is the text </div>"
"<div id="normaltext"> here is the text </div>"
The text is come from database. How can I convert this text easily?
Assuming that you have both the English and the Japanese version in the database, you can do two things:
Use AJAX to load the correct text from the database and replace the contents of the div. There are tons and tons of tutorials on the internet about AJAX content replacement.
Put both languages on the website and hide one using CSS display:none. Then use some JavaScript to hide/display the correct div when a button is clicked.
The first is technically more complex but keeps your page size small. The second one is very easy to do, but your page size is larger because you need to send both languages.
If the div is small and there is only one or two of these on the page, I recommend number two, the CSS technique. If the div is large (i.e. a complete article) or there are many of them then use the first method.
If you mean translating the text, you cannot do it easily. To get some idea of the best attempts that software can make at translating natural languages, go to Google Translate or Babelfish. It's not that good, but it's sometimes an intelligible starting point.
If you just mean setting the language attribute on an element, then assign a new language code to the lang property of the div element object.
document.getElementById("normaltext").lang = "en-US";
I don't know the language code for Japanese; possibly ja-ja.
Assuming your literals have an id in your database you could put that id as a class in your div. Then with jquery fetch the ID, send it to your Ajax back-end and fetch the translated one.
First, if you have the texts in a database it really doesn't matter if you render it in divs, tables or whatever.
First you need a php api for some translation service. Here is just an example that might give you some ideas.
$textArray = getTextForThisPage();
?>
...
english_to_japanese($textArray["text1"]);?>
...

Categories