SynPDF icon indicating copy to clipboard operation
SynPDF copied to clipboard

Stack overflow on encrypted pdf

Open fs999 opened this issue 5 years ago • 0 comments

I have a stack overflow error when saving when I try to encrypt a pdf. The error appears in TPdfRawText.InternalWriteTo

Here is my code :

        p := TMemoryStream.Create;
         Pdf := TPdfDocumentGDI.Create(false, 0, false, TPdfEncryption.New(elRC4_40, '1234', '1234',  [epPrinting]));
        Pdf.GeneratePDF15File := True;
        Pdf.PDFA1 := False;
        Pdf.Info.Title := 'Title';
        Pdf.Info.Author := 'Author';
        Pdf.Info.Creator := 'Creator';
        try
          for i := 1 to QuickReport.QRPrinter.PageCount do
          begin
            aMeta := QuickReport.QRPrinter.GetPage(i);
            try
              Pdf.DefaultPageWidth := MulDiv(aMeta.Width,72,Pdf.ScreenLogPixels);
              Pdf.DefaultPageHeight := MulDiv(aMeta.Height,72,Pdf.ScreenLogPixels);
              Pdf.AddPage;
              Pdf.Canvas.RenderMetaFile(aMeta,1,0,0,0, tpSetTextJustification,99,101,tcNeverClip);
            finally
              aMeta.Free;
            end;
          end;
          Pdf.SaveToStream(p);     <<--- Error appears here
        finally
          FreeAndNil(Pdf);
          FreeAndNil(p);
        end;

fs999 avatar Apr 28 '20 12:04 fs999