Dynamic hight for Recordsets in PDF-Report

Hi,
how is it possible to get a dynamic hight for recordsets in a PDF-Report?
In my recordset is a multiline field with formatted text,
one recordset uses 1 line
some recordsets more, lets say 10 lines.
if I set the hight to small, the recordsets are overlapping,
if I set the hight to large, most of the page is blank.
I want, that each recordset uses only so many lines of the page which it needs.

Now I use different print-Buttons with different recordset-hights,
but that is not a solution:

                switch ($myHight) {
                    case "mikro":
                        sc_pdf_sub_sel_end(6);
                        break;
                    case "mini":
                        sc_pdf_sub_sel_end(11);
                        break;
                    case "klein":
                        sc_pdf_sub_sel_end(16);
                        break;
                    case "mittel":
                        sc_pdf_sub_sel_end(20);
                        break;
                    case "gross":
                        sc_pdf_sub_sel_end(32);
                        break;
                    default:
                        sc_pdf_sub_sel_end(26);
                        break;
                }

I found a try to manipulate the cursor position on the page with that:

$j = sc_pdf_get_y();
sc_pdf_set_y($j+30);

but this position seems NOT to be the position the the last pixel was set,
but where the last recordset was started to print.

Thanks for any ideas how this can be solved.
Frederic Espitalier

I just saw my old post here, I solved that problem, in anybody is interested, just ask
frederic

Im interested in your solution :slight_smile:

Hi frederic, i have exactly the same problem. a lot of lines in the text field and overlapping by pdf, Im realy interested

regards from Switzerland
Salvatore Reinemuth

That would be really nice, but does static height work??
Whatever I set as Line Height in “PDF Report Settings” is honored only on the first page.
Then all remaining records are clusterd as a single record on page 2, as shown here (that’s the actual output on page 2, not altered by me).

UPDATE: I’m using a single field (populated onRecord, with html tags for bold and line breaks) and this issue appears only when using sc_pdf_print_html, i.e. the field has “Show HTML content” off.

[ATTACH=JSON]{“alt”:“Click image for larger version Name: sc_pdf2.png Views: 0 Size: 98.6 KB ID: 90283”,“data-align”:“none”,“data-attachmentid”:“90283”,“data-size”:“full”,“title”:“sc_pdf2.png”}[/ATTACH]

sc_pdf2.png

1 Like

Hi, I did not noticed that there was interest,
I just watched my code, so far I understand my code, I wrote 2 functions to get the hight of a multilinetext
What I do is writing the field into a temporary pdf document and than I can see how much the vertical cursor position changed
If You want I can document it a and post it, now without documentation:


function multiline_get_textfieldheight($field, $index)
    {    multiline_get_parameters($field, $index, $multilinetext, $width, $posX, $fontHight, $fontName);

        $pdf1 = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        $pdf1->setImageScale(PDF_IMAGE_SCALE_RATIO);
        $pdf1->SetFont($fontName, '', $fontHight);
        $pdf1->AddPage();
        $pdf1->writeHTMLCell($width, 0, $x, $y, $multilinetext, $border=0, $ln=0, $fill=0, $reseth=false, $align='', $autopadding=false);

         return  $pdf1->getLastH();
    }

function multiline_get_parameters($field, $index, &$multilinetext, &$width, &$posX, &$fontHight, &$fontName)
    {        $multilinetext = $field['data'][$index];
                    $width = $field['width'];
                     $posX = $field['posx'];
                $fontHight = $field['font_size'];
                 $fontName = $field['font_type'];
    }


I put those functions into the code of the report,
here is how I called them:

$cell_rechnungspositionText, ist the object which of the multiline text (html)

to get the height of the block first for checking if there is enough space on the page:


$currentlineheight = multiline_get_textfieldheight( $cell_rechnungspositionText, $NM_ind);

and later on:


        multiline_get_parameters($cell_rechnungspositionText, $NM_ind, $multilinetext, $width, $posX);
        $pdf->writeHTMLCell($width, 0, $posX, $y, $multilinetext, $border=0, $ln=0, $fill=0, $reseth=false, $align='', $autopadding=true);

// and than I have to move the vertical cursor:

        $pdf->SetY($pdf->GetY()+$currentlineheight);


Did that help?

Frederic

It works ! thnks a lot for sharing

Tambien me funciono , muchas gracias

Another solution, maybe simpler, is:

        foreach ({product} as $NM_ind => $Dados)
        { 
            sc_pdf_print_sub_sel($cell_product_name[$NM_ind]);
			

	$add_space = ceil(strlen($cell_product_name['data'][$NM_ind])/75)*5;
            sc_pdf_ln( $add_space );
        }

Split the text into lines of 75 characters each, then multiply the number of lines by 5 mm. This way, if there is a single line, it will add 5 mm; if there are two lines, 10 mm; and so on. You can adjust the 75 characters or the 5 mm as needed.

$cell_product_name is an array. It contains another array 'data' with the actual product names. Then we use $NM_indas index to identify which product we are measuring to see how many characters it has

Very good angelrobv, this should work and I think it is quicker than my solution.
But what I had to solve was something without touching the text to print
(so far I can remember) and without fixed line heights or character count per line.

I understand — you had a more complex situation. In older versions of ScriptCase, using sc_pdf_ln in the subselect worked correctly and simply broke the row at the point where it was called. Now, however, sc_pdf_ln breaks the row from the first line, even if the text is longer and has already wrapped onto three lines, which is why the overlap occurs. A slightly better solution than the one I mentioned above is the following script, which monitors not only the number of characters but also whole words, since the wrapping is done without breaking words

$text_wrapped = wordwrap($cell_product_name[‘data’][$NM_ind], 75, “\n”, true);
$add_space = count( explode("\n", $text_wrapped) )*5;
sc_pdf_ln( $add_space );

Surely all the solutions from these discussions will be useful to others

Thank you angelrobv, I will remember that the next time I have to solve something like this.