#1 Re: PDF Engine » EOutOfResources Error (RTF to PDF) » 2022-06-02 14:25:36

I downloaded it.  That appears to be a part of the download. 

I removed that unit from the uses and added in 'mORMotReport',  it now works. 

So I am not sure how I got that unit,  but I saw that AppendRichEdit was indeed in there:
rGxyhfc.png.

However,  the other unit has it as well.


Thanks for helping me on this.  I guess it was confusing to be that both units had those methods and an early example made reference to it from another forum link. 


Now my uses section looks like this:

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, SynCommons, SynPdf, mORMotReport;

and it works perfectly.

#2 Re: PDF Engine » EOutOfResources Error (RTF to PDF) » 2022-06-02 14:04:58

With an empty project and the code you sent as well as the rtf file  I got:

First chance exception at $00007FFE400D4FD9. Exception class Exception with message 'GetTextExtentExPointA WinApi error in TGDIPages'. Process Project1.exe (8756)

in Win64 and in Win32 I get get the same long delay.  The content is loaded in the RichEdit window however,  but it fails.

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, SynCommons, SynPdf, SQLite3Pages;

type
  TForm1 = class(TForm)
    RichEdit: TRichEdit;
    btnReportToPDF: TButton;
    procedure btnReportToPDFClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnReportToPDFClick(Sender: TObject);
begin
  RichEdit.Lines.LoadFromFile(GetEnvironmentVariable('USERPROFILE') + '\Downloads\sample.rtf');

  with TGDIPages.Create(self) do
    try
      Caption := self.Caption;
      BeginDoc;
      AddTextToHeader(paramstr(0));
      SaveLayout;
      Font.Style := [fsItalic];
      TextAlign := taRight;
      AddTextToFooterAt('http://synopse.info', RightMarginPos);
      RestoreSavedLayout;
      AddTextToFooter(DateTimeToStr(Now));
      NewHalfLine;

      RichEdit.Clear;
      RichEdit.Lines.Add('Some text');
      RichEdit.Lines.Add('Some more text');
      RichEdit.Lines.Add('even more text');

      DrawTitle('Rich Edit Content', true);
      AppendRichEdit(RichEdit.Handle);
      DrawTitle('Last page content', true);

      EndDoc;
      ExportPDF(ChangeFileExt(paramstr(0),'.pdf'),true,false);
      ShowPreviewForm;
    finally
      Free;
    end;
end;

end.

Here are my paths I have included with work:
d1LDlbY.png
hs6GhZ3.png

#3 Re: PDF Engine » EOutOfResources Error (RTF to PDF) » 2022-06-01 22:00:51

rvk wrote:
drmoorejr wrote:

Also to the best if my knowledge I am using the newest version.

Did you read my previous post?

I can confirm the crash with your selected code (found on the forum here).
I got that too.

But try the exact code I gave (with an empty project).


I will do exactly as you suggest.   I will post back here by morning.

Thanks for the help.

#4 Re: PDF Engine » EOutOfResources Error (RTF to PDF) » 2022-06-01 21:59:31

I replaced my code with yours and I get a long pause before getting the same EOutOfResources.  Now if I just use DrawText instead of AppendRichEdit  I get a bit further.

#5 Re: PDF Engine » EOutOfResources Error (RTF to PDF) » 2022-06-01 21:47:19

rvk wrote:
drmoorejr wrote:

Are you suggesting I try a blank project?

Yes, I just created an empty project with one TButton and TRichEdit and dropped this code in the Button1.OnClick.

What bitness and platform are you compiling for? 32 bit or 64 bit (I tried 32 bit VCL).

(Just tried 64 bit VCL too and that also works for me, so I don't know what's wrong on your end. Maybe someone else knows more about it.)


I tried win32,   with win64 I get [dcc64 Fatal Error] Unit1.pas(7): F2048 Bad unit format: 'C:\Embarcadero\SynPDF-master\SynPdf.dcu' - Expected version: 32.0, Windows Unicode(x64) Found version: 32.0, Windows Unicode(x86),  so I stuck with Win32.


Also to the best if my knowledge I am using the newest version.

#6 Re: PDF Engine » EOutOfResources Error (RTF to PDF) » 2022-06-01 21:27:18

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, SynCommons, SynPdf, SQLite3Pages;

type
  TForm1 = class(TForm)
    RichEdit: TRichEdit;
    btnPDF: TButton;
    btnCancel: TButton;
    procedure btnCancelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btnPDFClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnCancelClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  RichEdit.Text := StringFromFile(ExtractFilePath(paramstr(0))+'testrtf.rtf');
  RichEdit.Clear;


  RichEdit.Clear;
  RichEdit.SelText := 'Some text';
  RichEdit.SelText := 'Some more text';
  RichEdit.SelText := 'even more text';
  RichEdit.Lines.Add('Hello');

  RichEdit.Lines.Add('Some text');
  RichEdit.Lines.Add('Some more text');
  RichEdit.Lines.Add('even more text');
end;

procedure TForm1.btnPDFClick(Sender: TObject);
begin
  with TGDIPages.Create(self) do
  try
    Caption := 'SynPDF RichEdit Print Preview & PDF Creation';
    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('-=- Test Right click on the report then "Export as PDF" -=-',RightMarginPos);
    RestoreSavedLayout;
    DrawTitle('Rich Edit Content',true);
    AppendRichEdit(RichEdit.Handle);
    DrawTitle('Last page content',true);
    NewHalfLine;
    DrawText('We are also able '+
      'to know at where Y position the RichEdit content was finished printing....'#13+
      'Therefore, any further writing to the report continue to the same page.');
    EndDoc;
    ExportPDF(ChangeFileExt(paramstr(0),'.pdf'),true,false);
    ShowPreviewForm;
  finally
    Free;
  end;
end;

end.

#7 Re: PDF Engine » EOutOfResources Error (RTF to PDF) » 2022-06-01 21:21:12

Are you suggesting I try a blank project?    If so  I did try this as well.  I know if there is only one line of text in the RichEdit box, then it works fine.

#8 Re: PDF Engine » EOutOfResources Error (RTF to PDF) » 2022-06-01 21:12:47

I am using that code and the test rtf you used,  but when I change only the content I load its when I get the error.

I am merely using:

          RichEdit.Clear;
          RichEdit.Lines.Add('Some text');
          RichEdit.Lines.Add('Some more text');
          RichEdit.Lines.Add('even more text');

I get the Same result with this:

          RichEdit.Clear;
          RichEdit.SelText := 'Some text';
          RichEdit.SelText := 'Some more text';
          RichEdit.SelText := 'even more text';

#9 Re: PDF Engine » EOutOfResources Error (RTF to PDF) » 2022-06-01 19:34:42

The problem seems to be with AppendRichEdit method,  if I just use DrawText everything works fine.



David

#10 PDF Engine » EOutOfResources Error (RTF to PDF) » 2022-06-01 18:41:03

drmoorejr
Replies: 20

Hi,


I am using Delphi (Tokyo) 10.2.3 and and using the rtfrichedit example code and I get an EOutOfREsources error when I try to convert the RichEdit content to PDF.  I am able to get it to work if its a single line of text or even a very short two lines but anything longer it just fails after a long delay with a EOutOfREsources error.  Is this a know issue or is there something that I need to do to correct?  I tried finding an answer here before posting.

Thanks,


David

Board footer

Powered by FluxBB