#1 2022-06-01 18:41:03

drmoorejr
Member
Registered: 2022-06-01
Posts: 10

EOutOfResources Error (RTF to PDF)

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

Last edited by drmoorejr (2022-06-01 18:41:51)

Offline

#2 2022-06-01 19:34:42

drmoorejr
Member
Registered: 2022-06-01
Posts: 10

Re: EOutOfResources Error (RTF to PDF)

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



David

Offline

#3 2022-06-01 20:59:02

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

Can you show an example (preferable with example rtf)?

If I use this code (with a sizable rtf, see attached) it works fine for me.

Simple project with just a button and a TRichEdit on form.

procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEdit1.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;

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

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

Rtf download here: https://jeroen.github.io/files/sample.rtf

Offline

#4 2022-06-01 21:12:47

drmoorejr
Member
Registered: 2022-06-01
Posts: 10

Re: EOutOfResources Error (RTF to PDF)

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';

Last edited by drmoorejr (2022-06-01 21:19:39)

Offline

#5 2022-06-01 21:17:43

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

This works fine for me. I'm on Delphi 10.2 (Embarcadero® Delphi 10.2 Version 25.0.27659.1188)

Do you have the latest version of SynPDF?
Did you really try an empty project with just a button and TRichEdit with this code???
(important because it could also be something else in your program)

procedure TForm1.Button1Click(Sender: TObject);
begin
  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;

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

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

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

3o0NV80.png

Offline

#6 2022-06-01 21:21:12

drmoorejr
Member
Registered: 2022-06-01
Posts: 10

Re: EOutOfResources Error (RTF to PDF)

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.

Offline

#7 2022-06-01 21:26:13

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

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.)

Offline

#8 2022-06-01 21:27:18

drmoorejr
Member
Registered: 2022-06-01
Posts: 10

Re: EOutOfResources Error (RTF to PDF)

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.

Offline

#9 2022-06-01 21:30:47

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

Yeah, I found that code too when I tried to reproduce this and I can confirm THIS code doesn't work.
It crashes in ExportPDF with a invalid meta image.

Try my code (found it somewhere else). Does that work???

(I remember with TGDIPages I got this error before when I used BeginDoc or something. Not sure anymore because I completely rewrote it differently for myself with TPDFDocumentGDI.)

Offline

#10 2022-06-01 21:47:19

drmoorejr
Member
Registered: 2022-06-01
Posts: 10

Re: EOutOfResources Error (RTF to PDF)

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.

Offline

#11 2022-06-01 21:50:15

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

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).

Last edited by rvk (2022-06-01 21:50:29)

Offline

#12 2022-06-01 21:54:39

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

Mmm, the code I found here https://synopse.info/forum/viewtopic.php?id=76 was missing an EndDoc.

Your code does have it and doesn't crash for me :confused:

Offline

#13 2022-06-01 21:59:31

drmoorejr
Member
Registered: 2022-06-01
Posts: 10

Re: EOutOfResources Error (RTF to PDF)

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.

Offline

#14 2022-06-01 22:00:05

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

Where is your TGDIPages defined?
I'm not seeing an uses for mORMotReport in your code??

Last edited by rvk (2022-06-01 22:00:33)

Offline

#15 2022-06-01 22:00:51

drmoorejr
Member
Registered: 2022-06-01
Posts: 10

Re: EOutOfResources Error (RTF to PDF)

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.

Offline

#16 2022-06-01 22:02:48

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

I wonder if your AppendRichEdit is really the one in TGDIPages because I don't see it included in your uses.

Try to trace into that function tomorrow and see where it leads you.
(I wonder if it's in mORMotReport or somewhere else)

Sleep tight smile

Offline

#17 2022-06-02 14:04:58

drmoorejr
Member
Registered: 2022-06-01
Posts: 10

Re: EOutOfResources Error (RTF to PDF)

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

Last edited by drmoorejr (2022-06-02 14:07:56)

Offline

#18 2022-06-02 14:10:55

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

drmoorejr wrote:

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

You have SQLite3Pages in there.
I don't have that. I use mORMotReport.pas.

I'm not sure where that SQLite3Pages comes from and how different it is from mORMotReport.pas.

I see you can get it from here https://synopse.info/forum/viewtopic.php?id=41
Still not sure how it is different.
Maybe that's the problem.

Edit: That one doesn't have the AppenRichEdit.

Where did you get the SQLite3Pages??
It has a date of 2010 !! Really OLD.

Last edited by rvk (2022-06-02 14:14:59)

Offline

#19 2022-06-02 14:22:55

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

You shouldn't use SQLite3Pages anymore.
It was renamed mORMotReport.

https://github.com/synopse/SynPDF/blob/ … Report.pas

Version 1.18
  - renamed SQLite3Pages.pas to mORMotReport.pas

Offline

#20 2022-06-02 14:25:36

drmoorejr
Member
Registered: 2022-06-01
Posts: 10

Re: EOutOfResources Error (RTF to PDF)

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.

Offline

#21 2022-06-02 14:35:36

rvk
Member
Registered: 2022-04-14
Posts: 47

Re: EOutOfResources Error (RTF to PDF)

Glad it works now smile

Last edited by rvk (2022-06-02 14:35:46)

Offline

Board footer

Powered by FluxBB