You are not logged in.
I'm having problems trying to use SaveToStreamDirectBegin etc. with VCLCanvas and metafiles. For example, here's a simple demo program that produces an empty PDF file. You'll recognise the code since I took it from here: http://blog.synopse.info/post/2010/05/0 … PDF-engine
If I switch from SaveToStreamDirectBegin to SaveToFile then the generated PDF file is as expected.
I'm using your code from this revision: http://synopse.info/fossil/vinfo?name=d … 0ec68b709b
Can I expect SaveToStreamDirectBegin to work in this setting, or should I give up on it?
program SaveToStreamDirectBeginQuery;
{$APPTYPE CONSOLE}
uses
SysUtils, Classes, Graphics, SynPdf;
procedure MakePDF(const FileName: string);
var
i: Integer;
Stream: TStream;
begin
with TPdfDocumentGDI.Create do
try
Stream := TFileStream.Create(FileName, fmCreate);
try
SaveToStreamDirectBegin(Stream);
for i := 1 to 9 do
begin
AddPage;
with VCLCanvas do
begin
Font.Name := 'Times new roman';
Font.Size := 150;
Font.Style := [fsBold, fsItalic];
Font.Color := clNavy;
TextOut(100, 100, 'Page ' + IntToStr(i));
end;
SaveToStreamDirectPageFlush;
end;
SaveToStreamDirectEnd;
finally
Stream.Free;
end;
finally
Free;
end;
end;
begin
MakePDF('C:\desktop\test.pdf');
end.
Offline
In fact, it could not work as such.
Direct content flushing was working not with TPdfDocumentGDI metafile content, only within SaveToStream.
I've introduced a new TPdfDocumentGDI.SaveToStreamDirectPageFlush overriden method.
It can be used to reduce the used memory even more, by-passing page content compression.
See http://synopse.info/fossil/info/a2cc7123b0
Now your sample code will work as expected.
Offline
OK, that does a lovely job solving my problem. Thank you kindly.
But the SynPdf unit does not compile at the moment when USE_PDFSECURITY is not defined.
Offline
You are rigvht.
I've fixed SynPdf compilation issue when USE_PDFSECURITY conditional is not defined.
Offline
Thank you very much for that. Much appreciated.
My next step is to try drawing a metafile onto a PDF doc that is using SaveToStreamDirectBegin. I'm hoping that will work. I'll get back to you if I have problems, but since I'm moving house at the moment, it may be a little while.
Offline
Internally, the VCLCanvas is already a metafile.
It should work as expected.
We used nested metafiles with success (including plain external EMF, or charts).
EMF support is pretty good, due to user feedback and patches.
In your case, using TPdfDocumentGDI is not even needed.
You can use a plain TPdfDocument, then render the metafile content on each page one after the other.
See how TGdiPages component in mORMotReport.pas is implemented.
Offline
Thanks again. I'm sure it will work out!!
Offline