Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Rtf with richtext wrong formatted

edited September 12 in General
Hello,
I am trying to print a report in .rtf format. (I use delphi 12.1 and report builder 22.04.
I have an rtf that I generate on the fly this is the rtf:

{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\fnil\fcharset0 Arial;}}\qj\b AAAAAA Test TFR\b0 \line \line ()\line \line \b \tab\tab\tab\tab\tab\tab\tab\tab , 1 2/09/2024\b0 \line \line \line \b \tab\tab\tab\tab\tab\tab\tab\tab TFR test\b0 \line \tab\tab\tab\tab\tab\tab\tab\tab \line \tab\tab\tab\tab\tab\tab\tab\tab ()\line \line \line Subject: \b LETTER FROM RECRUITMENT \b0 \line \line \par Following the verbal agreements reached, your hiring is confirmed. In accordance with the provisions of Legislative Decree 152/97, as amended by Legislative Decree 104/2022 in implementation of Directive (EU) 2019/1152 on transparent and predictable working conditions, we inform you of the aspects characterizing your employment relationship:\par \par \b START OF THE RELATIONSHIP\b0 \line The start of the relationship is established no later than 01/10/2024. After this date, in the event of failure to take up service, regardless of the reason, this contract will cease to have binding effect for the undersigned.\par \par \b PLACE OF WORK\b0 \line () in . You may be required to perform your services at other locations, in the event of a transfer, even temporary, of your employer, a transfer which, subject to adequate notice, you declare to accept.\par \par \b DURATION OF THE RELATIONSHIP\b0 \line Permanent.\par \par \b WORKING HOURS\b0 \line The work commitment will have the following daily distribution, listed below: \par \line \tab\tab Morning\tab Afternoon\tab Total hours\tab \line \b Day\b0 \tab \b From\b0 \tab \b To\b0 \tab \b From\b0 \tab \b To\b0 \tab \tab \line Monday\tab 08:00\tab 12:00\tab -\tab -\tab 4.00\tab \line Tuesday\tab -\tab -\tab -\tab -\tab 0.00\tab \line Wednesday\tab -\tab -\tab -\tab -\tab 0.00\tab \line Thursday\tab -\tab -\tab -\tab -\tab 0.00\tab \line Friday\tab -\tab -\tab -\tab -\tab 0.00\tab \line Saturday\tab -\tab -\tab -\tab -\tab 0.00\tab \line Sunday\tab -\tab -\tab -\tab -\tab 0.00\tab \line \line For a total of\par 4.00 hours per week, 17.33 hours per month, 208.00 hours per year.\line \line \line \par \par }


This content is passed to the RichText component but is modified when report is generated and in this way when opening the file the formatting is lost and the file does not appear as in the original format which is editable and perfectly formatted.

The rtf that is generated by the richtextbox (with the rtf above) after printing the report is this:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl
{\f0\fCharset1 Arial}
{\f1\fCharset0 Arial}
}
{\colortbl;
\red255\green255\blue255;\red0\green0\blue0;}
\viewkind1\lnbrkrule\truncex\nolead\pard\f0\fs20
\sectd
\pgwsxn11905\pghsxn16837\marglsxn360\margtsxn360\margrsxn360\margbsxn360\notvatxbx\pard\f0\fs24\sl-276\slmult0
\tx0
\b\cf2\f1\fs24 AAAAAA Test TFR
\plain
\par\pard\f0\fs4\sl-57\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 ()
\plain
\par\pard\f0\fs4\sl-42\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-276\slmult0
\tx5775
\tab\b\cf2\f1\fs24 , 12/09/2024
\plain
\par\pard\f0\fs6\sl-83\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-276\slmult0
\tx5775
\tab\b\cf2\f1\fs24 Test TFR
\plain
\par\pard\f0\fs4\sl-42\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-269\slmult0
\tx5775
\tab\cf2\f1\fs24 ()
\plain
\par\pard\f0\fs10\sl-91\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-269\slmult0
\tx0\tx1058
\cf2\f1\fs24 Oggetto :
\plain
\b\cf2\f1\fs24 LETTERA DI ASSUNZIONE
\plain
\par\pard\f0\fs8\sl-83\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 Facendo seguito agli accordi verbali intercorsi, si conferma la sua assunzione. In base alle previsioni del
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 D.Lgs. 152/97, come modificato dal D.Lgs. 104/2022 in attuazione della direttiva (UE) 2019/1152 sulle
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 condizioni di lavoro trasparenti e prevedibili, la informiamo sugli aspetti caratterizzanti il suo rapporto di
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 lavoro:
\plain
\par\pard\f0\fs2\sl-44\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-276\slmult0
\tx0
\b\cf2\f1\fs24 INIZIO DEL RAPPORTO
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 L'inizio del rapporto viene stabilito entro e non oltre il 01/10/2024. Oltre tale data, in caso di mancata
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 presa di servizio, indipendente dal motivo, il presente contratto cesser\u224? di avere effetto vincolante per la
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 scrivente.
\plain
\par\pard\f0\fs4\sl-43\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-276\slmult0
\tx0
\b\cf2\f1\fs24 LUOGO DI LAVORO
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 () in . Potrebbe esserle richiesto di effettuare le sue prestazioni presso altre sedi, in caso di trasferimento
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 anche temporaneo del Suo datore di lavoro, trasferimento che, salvo congruo preavviso, dichiara di
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 accettare.
\plain
\par\pard\f0\fs4\sl-44\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-276\slmult0
\tx0
\b\cf2\f1\fs24 DURATA DEL RAPPORTO
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 A tempo indeterminato.
\plain
\par\pard\f0\fs4\sl-42\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-276\slmult0
\tx0
\b\cf2\f1\fs24 ORARIO DI LAVORO
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 L'impegno lavorativo avr\u224? la seguente, sotto elencata, distribuzione giornaliera:
\plain
\par\pard\f0\fs4\sl-43\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-269\slmult0
\tx1443\tx2887\tx4331
\tab\cf2\f1\fs24 Mattina
\plain
\tab\cf2\f1\fs24 Pomeriggio
\plain
\tab\cf2\f1\fs24 Totale ore
\plain
\par\pard\f0\fs24\sl-276\slmult0
\tx0\tx1443\tx2165\tx2887\tx3609
\b\cf2\f1\fs24 Giorno
\plain
\tab\b\cf2\f1\fs24 Dalle
\plain
\tab\b\cf2\f1\fs24 Alle
\plain
\tab\b\cf2\f1\fs24 Dalle
\plain
\tab\b\cf2\f1\fs24 Alle
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0\tx1443\tx2165\tx2887\tx3609\tx4331
\cf2\f1\fs24 Luned\u236?
\plain
\tab\cf2\f1\fs24 08:00
\plain
\cf2\f1\fs24 12:00
\plain
\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 4,00
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0\tx1443\tx2165\tx2887\tx3609\tx4331
\cf2\f1\fs24 Marted\u236?
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 0,00
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0\tx1443\tx2165\tx2887\tx3609\tx4331
\cf2\f1\fs24 Mercoled\u236?
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 0,00
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0\tx1443\tx2165\tx2887\tx3609\tx4331
\cf2\f1\fs24 Gioved\u236?
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 0,00
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0\tx1443\tx2165\tx2887\tx3609\tx4331
\cf2\f1\fs24 Venerd\u236?
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 0,00
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0\tx1443\tx2165\tx2887\tx3609\tx4331
\cf2\f1\fs24 Sabato
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 0,00
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0\tx1443\tx2165\tx2887\tx3609\tx4331
\cf2\f1\fs24 Domenica
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 -
\plain
\tab\cf2\f1\fs24 0,00
\plain
\par\pard\f0\fs4\sl-46\slmult0
\par\pard\f0\fs20\sl-228\slmult0
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 Per un totale di
\plain
\par\pard\f0\fs24\sl-269\slmult0
\tx0
\cf2\f1\fs24 4,00 ore settimanali, 17,33 ore mensili, 208,00 ore annuali.
\plain
\par}.


which is different from what I passed.
If you copy the first text in editor and save in rtf it allows to display the correct formatting (justified text etc), the second generated by richtextbox does not allow it. Is it possible to pass an rtf so that it is not modified?

This is the code to print:

dmReport := TModLettera1Form.Create(nil);
try
dmReport.ppRichText1.Clear;
dmReport.ppRichText1.RichText := MyRtf;
dmReport.ppLettera.EnableProcessMessages := False;
dmReport.ppLettera.ShowAutoSearchDialog := False;
dmReport.ppLettera.ShowPrintDialog := False;
dmReport.ppLettera.AllowPrintToArchive := True;
dmReport.ppLettera.TextFileName := PathToPrint
dmReport.ppLettera.Print;
finally
dmReport.Free;
end;

Thank you for support

Andrea



Comments

  • Hi Andrea,

    When ReportBuilder exports a report to RTF, it cannot simply copy the existing RTF from any TppRichText components present into the resulting exported file. RTF files must be built from the ground up.

    RB parses the entire embedded TppRichText, converts it to a metafile, then generates drawcommands based on each Windows API command. From there each drawcommand is then converted to RTF the same way the rest of the report is.

    I suggest looking at the following article on how to get the best results from RTF export. It's kind of like trying to fit a square peg in a round hole :).

    https://rbwiki.digital-metaphors.com/output/rtf/rtf-fundamentals/
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
Sign In or Register to comment.