You are not logged in.
Hello,
Is it possible to print a QuickReport report to a PDF file directly ?
Offline
I don't use QuickReport but I suspect it's not a problem, since QuickReport uses metafiles for its internal page storage.
Some sample code (not checked, just written into this forum):
procedure ExportAsPdf(QuickRep: TQuickRep; const aFileName: TFileName);
var Pdf: TPdfDocument;
aMeta: TMetaFile;
i: integer;
begin
Pdf := TPdfDocument.Create;
try
Pdf.DefaultPaperSize := psA4;
QuickRep.Prepare;
for i := 1 to QuickRep.QRPrinter.PageCount do begin
Pdf.AddPage;
aMeta := QuickRep.QRPrinter.GetPage(i);
try
// draw the page content
Pdf.Canvas.RenderMetaFile(aMeta,1,0,0);
finally
aMeta.Free;
end;
end;
Pdf.SaveToFile(aFileName);
finally
Pdf.free;
end;
end;
Offline
Hi,
as I am still using Delphi 6 prof. with built-in QuickReport which has no direct way of exporting a Quick Report into PDF file, I was searching for
a freeware component capable of doing this.
I found this page and tried to get things work...
1) small bug in your samle code:
procedure ExportAsPdf(QuickRep: TQuickReport; const aFileName: TFileName);
should be changed to
procedure ExportAsPdf(QuickRep: TQuickRep; const aFileName: TFileName);
2) bigger problem:
After extracting the files of synpdf.zip into a directory and adding this directory to the delphi library search path,
I tried to write a small demo app. Unfortunately, the compiler reports an error:
[Fataler Fehler] SynCommons.pas(222): Datei nicht gefunden: 'SynLz.dcu'
(means "file not found: SynLz.dcu").
Obvioulsy, the package SynLZ.pas is not included in the zip-package.
After getting a complete checkout of the SVN-archive, I added SynLZ.pas, and it works!
So maybe you will add SynLZ to the download-zip.
3) last problem:
After changing your sample code
Pdf.Canvas.RenderMetaFile(aMeta,0.8,aMeta.Width*0.1,aMeta.Height*0.1);
into
Pdf.Canvas.RenderMetaFile(aMeta,1,0,0);
I now have a perfect exact copy of the QuickReport (GREAT!!!) - only one problem with horizontal lines:
if the font is underlined, the text is displayed not correctly, also top frame border of detail band (see examples:
http://www.gymnasium-hohenschwangau.de/ … s-soll.pdf original Output
http://www.gymnasium-hohenschwangau.de/tmp/verweis.pdf PDF-Engine Output).
It's not a big problem, I can change the font/layout, but maybe you have an idea how to fix this?
Thanks for your efforts!
Regards
Heiko
Offline
1) code above edited
2) I'll add SynLZ to the SynPdf.zip archive
3) code above edited
4) about font underlining, could you export the page as an emf file, so that I may check it out?
you can send it to me at webcontact01 at synopse dot info
Thanks for the feedback and interest!
Offline
QuickReports printed in Landscape?
Hi,
I'm using Delphi 6 Enterprise, with exactly the same requirement to export QuickReports to PDF.
But I can't get the PDF to print in Landscape. I've searched the site and looked through the code. It just doesn't work for me.
The code above works great for portrait printing to PDF though. And looks Excellent.
Offline
If you want the code to work with any page layout, you can set the page size from the QuickReport settings.
That is:
procedure ReportExport(aReport: TQuickRep; const aFileName: TFileName);
var Pdf: TPdfDocument;
aMeta: TMetaFile;
i: integer;
begin
Pdf := TPdfDocument.Create;
try
aReport.Prepare;
for i := 1 to aReport.QRPrinter.PageCount do begin
aMeta := aReport.QRPrinter.GetPage(i);
try
Pdf.DefaultPageWidth := MulDiv(aMeta.Width,72,Pdf.ScreenLogPixels);
Pdf.DefaultPageHeight := MulDiv(aMeta.Height,72,Pdf.ScreenLogPixels);
Pdf.AddPage;
// draw the page content
Pdf.Canvas.RenderMetaFile(aMeta,1,0,0);
finally
aMeta.Free;
end;
end;
Pdf.SaveToFile(aFileName);
finally
Pdf.free;
end;
end;
Offline
Wow, it works great.
I can now export my QuickReport (version 3.0 that comes with Delphi 7) to PDF with this simple function.
Thank you very much.
I don´t need to buy any extra components or create new reports with some other reporting component.
Great job.
Offline
Great work. Excelent PDF exporter.
By the way, anything in mind for Delphi XE3 ?
Thanks.
Last edited by Cusco (2012-10-10 14:55:23)
Offline
I do not have Delphi XE3 at hand, and do not have the intent (nor money) to buy the update.
I paid for XE2, and never used it...
AFAIK current trunk version is working as expected with XE3. There was some weird issue about http.sys kernel-mode server (misalignement of variable record structures), but it has been solved due to the efforts of [Hans](http://synopse.info/forum/profile.php?id=702).
So I guess there should be no issue with SynPDF with XE3.
Feedback is welcome here.
Offline
Hi,
the latest SynCommon.pas does not compile with XE3.
[dcc32 Error] SynCommons.pas(15707): E2016 Array type required
[dcc32 Warning] SynCommons.pas(15707): W1024 Combining signed and unsigned types - widened both operands
[dcc32 Error] SynCommons.pas(16446): E2016 Array type required
[dcc32 Error] SynCommons.pas(16542): E2016 Array type required
[dcc32 Warning] SynCommons.pas(16542): W1024 Combining signed and unsigned types - widened both operands
[dcc32 Error] SynCommons.pas(16886): E2016 Array type required
[dcc32 Error] SynCommons.pas(17146): E2016 Array type required
[dcc32 Warning] SynCommons.pas(17146): W1024 Combining signed and unsigned types - widened both operands
[dcc32 Error] SynCommons.pas(19627): E2029 Expression expected , but 'END' found
[dcc32 Warning] SynCommons.pas(21276): W1058 Implicit string cast with potential data loss from 'string' to 'WinAnsiString'
[dcc32 Fatal Error] SQLite3Pages.pas(437): F2063 Could not compile used unit 'SynCommons.pas'
The E2016 Errors (Array type required) occurs after each
Field.TypeInfo^^.Name[0]
{ Delphi 2009/2010/XE: set Code page for this AnsiString }
if Len<>0 then
PWord(PPtrUInt(R)^-12)^ := PWord(PtrUInt(Field.TypeInfo^)+
ord(Field.TypeInfo^^.Name[0])+2)^;
{$endif}
This are a few too many pointers for me. Unfortunately, I do not understand the code.
What do I need to change so that the unit under XE3 can be compiled?
Thank You,
Regards,
Jens
Last edited by JensW_2000 (2012-10-15 01:38:31)
Offline
There is no such "Field.TypeInfo^^.Name[0] " in SynCommons.pas.
Could you download the latest version from http://synopse.info/fossil/wiki?name=Get+the+source then report any exact error?
Did you set some project options?
Here Name[0] is the length of a shortstring, which is correct since decades in Delphi.
I've seen it compile with XE3 with no problem last week.
Feedback of users owning XE3 is needed, since I do not have (nor need) this version, even if I would like to use it.
Offline
Hi,
sorry.
I had an old SynCommons.pas in an other library path.
After deleting this file my project compiles with XE3 and the PDF generation works as expected.
Thank You.
Regards,
Jens
Offline
I see that QuickReport now has a PDF exporter that uses the Synopse library. Details here http://forum.quickreport.co.uk/default. … osts&t=589
Offline
@acrobatter
This is great news!
They did not notify use about this use, but this is pretty fair use, as:
- They do provide the full source code of SynPDF, including the license terms;
- They do provide the QRPDFSynFilt.pas code, which is a very good example of using low-level TPDFCanvas;
- Even the PDF producer property contains "QuickReport+Synopse PDF".
In fact, they do not rely on our TMetaFile converter, but call low-level TPDFCanvas classes.
See TQRSynPDFDocumentFilter.Finish() method.
My only implementation concern is that it does use TPdfCanvas.TextOut() for text rendering, which is OK for non Unicode versions of Delphi, but is not Unicode-ready. They should have used TPdfCanvas.TextOutW() instead for Delphi 2009+.
... and perhaps the fact that they are using the somewhat old 1.15 revision.
A lot of fixes have been included since.
Very nice!
Offline