You are not logged in.
Pages: 1
Hello,
when creating encrypted PDF file, the following code causes Access Violation at address 00030000:
procedure TPdfForm.CreatePdfClick(Sender: TObject);
var
D: TPdfDocument;
begin
D := TPdfDocument.Create(False, 0, False, TPdfEncryption.New(elRC4_128, '', 'XXXX', PDF_PERMISSION_NOMODIF));
try
D.NewDoc; // <--- This line causes the AV during SaveToFile
D.AddPage;
D.Canvas.SetFont('FixedWidth', 10, []);
D.Canvas.TextOut(50, 500, 'Text');
D.SaveToFile('Test.pdf');
finally
D.Free;
end;
end;
The problem is related to the NewDoc method - after deleting the line D.NewDoc; the code works fine.
My problem is that I want to generate several PDF files, so after SaveToFile I need to initialize new document by calling NewDoc, AddPage and so on. This works fine without encryption, but with PdfEncryption the second call to NewDoc (the first call is part of the TPdfDocument constructor) causes the next call to SaveToFile will raise AV.
Example of saving two PDF files:
procedure TPdfForm.CreateTwoFilesClick(Sender: TObject);
var
D: TPdfDocument;
begin
D := TPdfDocument.Create(False, 0, False, TPdfEncryption.New(elRC4_128, '', 'XXXX', PDF_PERMISSION_NOMODIF));
try
D.AddPage;
D.SaveToFile('Test1.pdf'); // Ok, create valid empty PDF
D.NewDoc;
D.AddPage;
D.SaveToFile('Test2.pdf'); // Fails with AV.
finally
D.Free;
end;
end;
Remove the encryption from this example and both fiels will be saved OK.
Thank you,
Petr
Offline
Hello,
Thank you for you reply.
Creating another TPdfDocument instance should of course help. But I wanted to inform you that there is probably a bug in the SynPdf code, because the procedure that woked fine without encryption (the NewDoc method) suddenly has stopped working when using with the TPdfEncryption. The description of the NewDoc menthod says:
/// create a new document
// - this method is called first, by the Create constructor
// - you can call it multiple time if you want to reset the whole document content
procedure NewDoc;
There is no mention that it cannot be used for encrypted documents, so I believe that this is a bug rather than a feature by design. This may also confuse another users; you can find a post called "How to create a protected PDF ?" by fantoni (2015-04-22) that is related to the same bug.
Sincerely
Petr
Offline
Pages: 1