Thread Einfacher PDF Creator gesucht (35 answers)
Opened by mikdoe at 2009-07-03 08:25

mikdoe
 2009-07-17 12:41
#123232 #123232
User since
2007-08-13
98 Artikel
BenutzerIn
[default_avatar]
Guest wer
Da bin ich ja richtig froh meine Zeit nicht mit dir verschwendet zu haben.

Und der ganze Thread ist sowieso sinnlos, da du deine Lösung nicht zeigst, falls nochmal jemand so ein Problem hat...


Es gab ja kein konkretes Problem mit einer konkreten Lösung.
Aber vielleicht interessiert in Zukunft mal jemanden, wie man mittels des Moduls Fließtext umbricht. Dazu hab ich mal ein Beispiel gemacht.

Verbesserungshinweise gern gesehen.
Vorschläge, Code unleserlicher zu machen sind unerwünscht.
Rechtschreib- und Übersetzungsfehler sind ebenfalls kostenfrei dabei :)

Grüße

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Test it with soft and hard break:
my $textline = 'This is a very long text and I think it breaks on end of line. But you don\'t know it already and so wie test and test and test. And now comes a very long line for hard break_because_we_dont_take_space_but_underline_for_word_seperating_and_now_we_look_what_happens_with_this_line. And? How looks it?';
my $column_width = 280;
$line_spacing = 2;      # without 'my' because I use this code in another content
for (my $fontsize = 5; $fontsize <= 21; $fontsize += 3) {
        # for each font size 5 up to 20 in step 3
        my @word = split / /,$textline; # split text into words
        my (@zeile,$word_new,$width,$inserted);
        my $myline = 0;
        while (scalar @word) {
                $zeile[$myline] = '' if !defined $zeile[$myline];       # prevent "use of uninitialized value...."
                $word_new = shift @word;        # get next word
                $width = $page->string_width($font,$zeile[$myline] . ' ' . $word_new) * $fontsize;      # width of line inc. new word
                $width = ($width - int($width) ? int($width) + 1 : $width);             # round up
                if ($width > $column_width) {   # new line to long with new word
                        if ($zeile[$myline] ne '') {
                                $myline ++;
                                unshift @word,$word_new;        # back to list for new width check in next round
                        }
                        else {  # word to long for one line, hard break
                                $inserted = 0;
                                for (my $xpos = 0; $xpos < length($word_new); $xpos ++) {
                                        $width = $page->string_width($font,substr($word_new,0,$xpos + 1)) * $fontsize;  # width of line inc. new word
                                        $width = ($width - int($width) ? int($width) + 1 : $width);             # round up
                                        if ($width > $column_width) {
                                                # hard break
                                                $zeile[$myline] = substr($word_new,0,$xpos);    # take well-fitting portion in line
                                                $myline ++;
                                                unshift @word,substr($word_new,$xpos);  # put rest back to list für next round
                                                $inserted = 1;
                                                last;
                                        }
                                }
                                if (!$inserted) {       # word alone is well-fitting for one line
                                        $zeile[$myline] = $word_new;
                                        $myline ++;
                                }
                        }
                }
                else {
                        # add word to line soft break
                        $zeile[$myline] .= ($zeile[$myline] ne '' ? ' ' : '') . $word_new;      # insert splited blank
                }
        }
        while (scalar @zeile) {
                $page->stringl($font,$fontsize,295,$position_y,shift @zeile);   # print out line
                $position_y -= ($fontsize+$line_spacing);       # cursor to next line
        }
}
Antworten mit Zitat

View full thread Einfacher PDF Creator gesucht