PUBLIC SUB Cell2(w AS Float, OPTIONAL h AS Float = 0, OPTIONAL txt AS String = "", OPTIONAL border AS Variant = FALSE, OPTIONAL ln AS Integer = 0, OPTIONAL align AS String = "", OPTIONAL fill AS Boolean = FALSE, OPTIONAL slink AS String = "")
DIM k, x, y, ws, dx, wmax, wlink AS Float
DIM s, op, txt2 AS String
'Output a cell
k = $k
IF (w = 0) THEN w = $w - $rMargin - $x
s = ""
IF (IsBoolean(border)) THEN
IF (fill OR border) THEN
op = IIf(fill, IIf(border, "B", "f"), "S")
s = _stringFloat($x * k, "0.00") & " " &
_stringFloat(($h - $y) * k, "0.00") & " " &
_stringFloat(w * k, "0.00") & " " &
_stringFloat(- h * k, "0.00") & " re " & op & " "
END IF
ELSE IF (IsString(border)) THEN
x = $x
y = $y
IF (InStr(border, "L")) THEN
s &= _stringFloat(x * k, "0.00") & " " &
_stringFloat(($h - y) * k, "0.00") & " m " &
_stringFloat(x * k, "0.00") & " " &
_stringFloat(($h - (y + h)) * k, "0.00") & " l S "
END IF
IF (InStr(border, "T")) THEN
s &= _stringFloat(x * k, "0.00") & " " &
_stringFloat(($h - y) * k, "0.00") & " m " &
_stringFloat((x + w) * k, "0.00") & " " &
_stringFloat(($h - y) * k, "0.00") & " l S "
END IF
IF (InStr(border, "R")) THEN
s &= _stringFloat((x + w) * k, "0.00") & " " &
_stringFloat(($h - y) * k, "0.00") & " m " &
_stringFloat((x + w) * k, "0.00") & " " &
_stringFloat(($h - (y + h)) * k, "0.00") & " l S "
END IF
IF (InStr(border, "B")) THEN
s &= _stringFloat(x * k, "0.00") & " " &
_stringFloat(($h - (y + h)) * k, "0.00") & " m " &
_stringFloat((x + w) * k, "0.00") & " " &
_stringFloat(($h - (y + h)) * k, "0.00") & " l S "
END IF
END IF
IF (txt <> "") THEN
SELECT CASE align
CASE "R"
dx = w - $cMargin - ME.GetStringWidth(txt)
CASE "C"
dx = (w - ME.GetStringWidth(txt)) / 2
CASE "FJ" 'Justify
'Set word spacing
wmax = (w - 2 * $cMargin)
$ws = (wmax - ME.GetStringWidth(txt)) / (Split(txt, " ").Count - 1)
_out(_stringFloat($ws * $k, "0.000") & " Tw")
dx = $cMargin
DEFAULT
dx = $cMargin
END SELECT
IF ($ColorFlag) THEN s &= "q " & $TextColor & " "
txt2 = Replace(Replace(Replace(txt, "\\", "\\\\"), "(", "\\("), ")", "\\)")
txt2 = Conv(txt2, "UTF-8", "ISO-8859-1") ''''''aggiunta
s &= "BT " & _stringFloat(($x + dx) * k, "0.00") & " " &
_stringFloat(($h - ($y + 0.5 * h + 0.3 * $FontSize)) * k, "0.00") & " Td (" & txt2 & ") Tj ET"
IF ($underline) THEN s &= " " & _dounderline($x + dx, $y + 0.5 * h + 0.3 * $FontSize, txt)
IF ($ColorFlag) THEN s &= " Q"
'IF (slink) THEN ME.Link($x + dx, $y + 0.5 * h - 0.5 * $FontSize, ME.GetStringWidth(txt), $FontSize, slink)
IF (slink) THEN
IF (align = "FJ") THEN
wlink = wmax
ELSE
wlink = ME.GetStringWidth(txt)
END IF
ME.Link($x + dx, $y + 0.5 * h - 0.5 * $FontSize, wlink, $FontSize, slink)
END IF
END IF
IF (s) THEN _out(s)
IF (align = "FJ") THEN
'Remove word spacing
_out("0 Tw")
$ws = 0
END IF
$lasth = h
IF (ln > 0) THEN
'Go to next line
$y += h
IF (ln = 1) THEN $x = $lMargin
ELSE
$x += w
END IF
END
PUBLIC SUB MultiRiga(w AS Float, h AS Float, txt AS String, OPTIONAL border AS Variant = FALSE, OPTIONAL align AS String = "J", OPTIONAL fill AS Boolean = FALSE)
DIM cw AS Integer[]
DIM wmax AS Float
DIM s, b, b2, c AS String
DIM nb, sep, i, j, l, ns, nl, ls AS Integer
DIM numeroriga AS Integer
DIM salva$y AS Integer
DIM hriga AS Integer
salva$y = $y
numeroriga = 0
'Output text with automatic or explicit line breaks
cw = $CurrentFont["cw"]
IF (w = 0) THEN w = $w - $rMargin - $x
wmax = (w - 2 * $cMargin) * 1000 / $FontSize
s = Replace(txt, "\r", "")
nb = Len(s)
IF (nb > 0) AND IF (Mid(s, nb, 1) = "\n") THEN DEC nb
b = 0
IF (IsBoolean(border) OR IsInteger(border)) THEN
IF (border) THEN
border = "LTRB"
b = "LRT"
b2 = "LR"
END IF
ELSE IF (IsString(border)) THEN
b2 = ""
IF (InStr(border, "L")) THEN b2 &= "L"
IF (InStr(border, "R")) THEN b2 &= "R"
b = IIf(InStr(border, "T"), b2 & "T", b2)
END IF
sep = -1
i = 1
j = 1
l = 0
ns = 0
nl = 1
WHILE (i <= nb)
'Get next character
c = Mid(s, i, 1)
IF (c = "\n") THEN
'Explicit line break
IF ($ws > 0) THEN
$ws = 0
_out("0 Tw")
END IF
numeroriga += 1
ME.Cell2(w, h, Mid(s, j, i - j), b, 2, align, fill)
INC i
sep = -1
j = i
l = 0
ns = 0
INC nl
IF (IsBoolean(border) OR IsInteger(border)) THEN
IF (border AND nl = 2) THEN b = b2
ELSE IF (IsString(border)) THEN
IF (NOT IsNull(border) AND nl = 2) THEN b = b2
END IF
CONTINUE
END IF
IF (c = " ") THEN
sep = i
ls = l
INC ns
END IF
l += cw[Asc(c)]
IF (l > wmax) THEN
'Automatic line break
IF (sep = -1) THEN
IF (i = j) THEN INC i
IF ($ws > 0) THEN
$ws = 0
_out("0 Tw")
END IF
numeroriga += 1
ME.Cell2(w, h, Mid(s, j, i - j), b, 2, align, fill)
ELSE
IF (align = "J") THEN
$ws = IIf(ns > 1, (wmax - ls) / 1000 * $FontSize / (ns - 1), 0)
_out(_stringFloat($ws * $k, "0.000") & " Tw")
END IF
numeroriga += 1
ME.Cell2(w, h, Mid(s, j, sep - j), b, 2, align, fill)
i = sep + 1
END IF
sep = -1
j = i
l = 0
ns = 0
INC nl
IF (IsBoolean(border) OR IsInteger(border)) THEN
IF (border AND nl = 2) THEN b = b2
ELSE IF (IsString(border)) THEN
IF (NOT IsNull(border) AND nl = 2) THEN b = b2
END IF
ELSE
INC i
END IF
WEND
'Last chunk
IF ($ws > 0) THEN
$ws = 0
_out("0 Tw")
END IF
IF (IsString(border)) THEN
IF (NOT IsNull(border) AND InStr(border, "B")) THEN b &= "B"
END IF
ME.Cell2(w, h, Mid(s, j, i - j), b, 2, align, fill)
IF numeroriga = 0 THEN
hriga = h
ELSE IF numeroriga = 1 THEN
hriga = (h * 2)
ELSE IF numeroriga = 2 THEN
hriga = (h * 3)
ELSE IF numeroriga = 3 THEN
hriga = (h * 4)
ELSE IF numeroriga = 4 THEN
hriga = (h * 5)
ENDIF
$lasthmulti = Max($lasthmulti, hriga)
$y = salva$y
$x += w
END
PUBLIC SUB Lnm()
'Line feed; default value is last cell height
DIM k, x, y, ws, dx, wmax, wlink AS Float
IF ($y + $lasthmulti > $PageBreakTrigger AND NOT $InFooter AND AcceptPageBreak()) THEN
'Automatic page break
x = $x
ws = $ws
IF (ws > 0) THEN
$ws = 0
_out("0 Tw")
END IF
ME.AddPage($CurOrientation)
$x = x
IF (ws > 0) THEN
$ws = ws
_out(_stringFloat(ws * k, "0.000") & " Tw")
END IF
END IF
$x = $lMargin
$y += $lasthmulti
$lasthmulti = 0
END
FOR EACH MyRS
ME.MultiRiga(10, 5, MyRS!quantita, TRUE, "L", FALSE)
ME.MultiRiga(32, 5, MyRS!codice, TRUE, "L", FALSE)
ME.MultiRiga(108, 5, MyRS!descrizione, TRUE, "L", FALSE)
ME.MultiRiga(20, 5, MyRS!prezzo, TRUE, "R", FALSE)
ME.MultiRiga(20, 5, MyRS!totale, TRUE, "R", FALSE)
ME.Lnm()
NEXT
Attenzione nella stessa riga usare sempre Multiriga altrimenti non funziona e cambiare riga con ME.Lnm() non ME.Ln(), poi sotto si può continuare con qualsiasi funzione di PdfWriter.