Breaks lines in creating the . pdf with Synpdf

Asked

Viewed 132 times

1

My question is this. I have a String with more than 6000 characters and need to put the contents of this variable in a file .pdf. only that saved to pdf the text is in a single line, it does not break the string to put on other lines.

I’m going through here the code of how to save the string in .pdf.

...
uses
  SynPdf;

{$R *.dfm}
...
procedure TForm2.SalvarPdfClick(Sender: TObject);
var
  PDF : TPdfDocumentGDI;
  Page: TPdfPage;
  FileName: string;
  I, J: Integer;
begin
  ...
  Descricao := JsonValue.Value;

  PDF  := TPdfDocumentGDI.Create();
  try
    PDF.Info.Author       := 'Autor';
    PDF.Info.CreationDate := Now;
    PDF.Info.Creator      := 'Criador';
    PDF.Info.Subject      := 'Assunto';
    PDF.Info.Title        := 'Título'

    Page := PDF.AddPage;
    Page.PageLandscape    := False;
    PDF.DefaultPaperSize  := psA4;
    PDF.VCLCanvas.TextOut(100,100, Descricao);
    PDF.SaveToFile('C:\MySysten\Pdf\Pdf_Publ.pdf');
  finally
    PDF.Free;
  end;

The text stays like this and does not break to the next lines inserir a descrição da imagem aqui

I am used Synopse PDF engine to save in .pdf

1 answer

1


Opa!
I went through this a while ago and it turned out that I decided to do another way with the Synopse PDF engine. See if it helps you.

In the Uses puts it like this:

uses
...
SynCommons, SynPdf, mORMotReport,
...; 

And in the code you can put more or so:

with TGDIPages.Create(self) do
try
  Caption := 'Título Aqui!';
  BeginDoc;
  SaveLayout;
  Font.Size := 9;
  AddTextToHeaderAt(Caption,LeftMargin);
  TextAlign := taRight;
  AddTextToHeader(DateTimeToStr(Now));
  AddLineToHeader(true);
  TextAlign := taLeft;
  AddLineToFooter(true);
  AddPagesToFooterAt('Page %d/%d',LeftMargin);
  TextAlign := taRight;
  AddTextToFooterAt('Testo de Rodapé',RightMarginPos);
  RestoreSavedLayout;
  DrawTitle('Título do capítulo',true);
  AppendRichEdit(RichEdit.Handle);
  DrawTitle('Last page content',true);
  NewHalfLine;
  DrawText('Seu Texto...');
  EndDoc;
  ExportPDF(FileName,True,False);
  ShowPreviewForm;
finally
  Free;
end;

This Example I removed directly from the Site: synopse.info/forum i visual of .pdf is very good and well organized in website will have a link to download the sample source.

  • 1

    I’ll take a look yes. It can only be with RichEdit has a with Memo?

  • 1

    Try to adapt...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.