#1 2012-04-11 20:11:58

mrgcms
Member
Registered: 2012-04-11
Posts: 5

Multiple calls to AppendRichEdit fails

I've written a routine which takes a PCL printer file, strips out the PCL codes and prints the remaining text to a PDF using TGDIPages.  One of the features is that when a PCL new page command is found, a new PDF page should be created. At this point, the rich edit contents are written to the PDF, the rich edit is cleared for the next page and a new page is added to the PDF. When I run the app, which has two pages, the first page is placed in the PDF, but the second page is not. The rich edit does have the correct second page contents though. This is the code that I'm using:

procedure TPCLForm.ConvertReport(rpFileName, outputFile: string);
var
  i    : Integer;
  line : string;
  pdf  : TGDIPages;
begin
  FPclFile := TStringList.Create;
  FPclFile.LoadFromFile(rpFileName);
  try
    pdf := TGDIPages.Create(self);
    try
      pdf.BeginDoc;
      try
        i := 0;
        while i < FPclFile.Count do
        begin
          line := FPclFile[i];

          // see if font needs to be changed
          CheckFont(line);

          // see if there is a newline command in the line
          if IsNewline(line) then
          begin
            pdf.AppendRichEdit(RichEdit.Handle);
            RichEdit.Clear;

            // create a new page in the PDF
            pdf.NewPage;
          end;

          // remove the PCL codes
          RemoveCode(PCL_LANDSCAPE, line);
          RemoveCode(PCL_VERTICAL, line);
          RemoveCode(PCL_PORTRAIT, line);
          RemoveCode(PCL_NEW_PAGE, line);

          RichEdit.Lines.Add(line);

          Inc(i);
        end;
        if RichEdit.Lines.Count > 0 then
          pdf.AppendRichEdit(RichEdit.Handle);
      finally
        pdf.EndDoc;
      end;
      pdf.ExportPDF(ChangeFileExt(outputFile, '.pdf'), true, false);
      pdf.ShowPreviewForm;
    finally
      pdf.free;
    end;
  finally
    FPclFile.Free;
  end;
end;

This is using Delphi 7 and the latest stable version of your components.

Last edited by mrgcms (2012-04-11 20:12:42)

Offline

#2 2012-04-12 08:54:52

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Multiple calls to AppendRichEdit fails

Try to explicitely add the header:

pdf.NewPage;
pdf.NewHalfLine;

If it works, they may be an issue in procedure TGDIPages.AppendRichEdit(RichEditHandle: HWnd):

procedure TGDIPages.AppendRichEdit(RichEditHandle: HWnd);
var Range: TFormatRange;
    LogX, LogY, LastChar, MaxLen, OldMap: integer;
    TextLenEx: TGetTextLengthEx; // RichEdit 2.0 Window Class
begin
  CheckHeaderDone; // add this line !!!!!
  if (Self<>nil) and (fCanvas<>nil) then
  with Range do begin
 (...)

Please report here if it works.
Then I'll commit the fix.

Offline

#3 2012-04-12 16:32:52

mrgcms
Member
Registered: 2012-04-11
Posts: 5

Re: Multiple calls to AppendRichEdit fails

Thanks Arnaud, that did the trick.

I added the NewHalfLine to my code and that fixed the problem. I then removed that and modified the TGDIPages code to verify that your fix would work - that also worked fine.

Thanks for a great package and great support!

Offline

#4 2012-04-12 18:22:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Multiple calls to AppendRichEdit fails

I've committed the corresponding fix to the trunk.

See http://synopse.info/fossil/info/aff2dcadf1

Thanks for your report and interest.

Offline

Board footer

Powered by FluxBB