You are not logged in.
Pages: 1
Hello,
I have to change a very old delphi program (delphi 7) to extend it by the PDF function.
I have installed the latest version of the PDF tool.
Source code:
procedure CreateReportAsPDF(aReport: TQuickRep; const aFileName: TFileName);
var Pdf: TPdfDocument;
aMeta: TMetaFile;
i: integer;
begin
Pdf := TPdfDocument.Create;
try
aReport.Prepare;
pdf.DefaultPaperSize := psA4;
for i := 1 to aReport.QRPrinter.PageCount do begin
Pdf.AddPage;
aMeta := aReport.QRPrinter.GetPage(i);
try
Pdf.Canvas.RenderMetaFile(aMeta,1,0,0);
finally
aMeta.Free;
end;
end;
Pdf.SaveToFile(aFileName);
finally
Pdf.free;
end;
end;
I tried in that style, but no better result:
procedure CreateReportAsPDF(aReport: TQuickRep; const aFileName: TFileName);
var Pdf: TPdfDocument;
aMeta: TMetaFile;
i: integer;
begin
Pdf := TPdfDocument.Create;
try
aReport.Prepare;
// pdf.DefaultPaperSize := psA4;
for i := 1 to aReport.QRPrinter.PageCount do begin
Pdf.AddPage;
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;
When I create the invoice, sometimes the rendering works, but sometimes not. The quickreport result always looks perfect. When I print the quickreport report by FREEPDF it looks good as well.
What's wrong.
Thanks
BR, Klaus
Last edited by KlausV (2022-07-28 10:02:39)
Offline
I found the problem, but still strange.
I changed the length of the format command from format('%11.2n) to format('%7.2n) and now it seems correct, but why?
It is very strange to me and I see the problem that I cannot trust them.
As I mentioned, If I print out the QR to freepdf it works in all cases.
Klaus
Offline
Sorry, for my bad explanation.
The QR has some labels to show the prices for net, vat and brut, like.
lblSum4.Caption:= format('%7.2n',[Gesamtsumme]); // 28.07.2022 changed from 11,2
Offline
Hello,
When I create the invoice, sometimes the rendering works, but sometimes not. The quickreport result always looks perfect. When I print the quickreport report by FREEPDF it looks good as well.
What's wrong.
Since you don't show the actual code where you used format
and don't even mention what exactly isn't working or HOW it doesn't render correctly it is impossible to answer this question.
A correct pdf and incorrect pdf or screenshots, preferably with the code to generate it, would go a long way to explain your exact problem.
And additionally, you do a aMeta := aReport.QRPrinter.GetPage(i);
So you could also save that aMeta to a metafile (.wmf) and look with a metaviewer if the problem is not just in QRPrinter itself.
Offline
Hi, sorry for my bad explanation, but I tried already to give you some sample results, but not possible for me to create the link ;-).
Now, I have created the meta WMF file and it looks correct, but the PDF file does not.
Additionally, I have created the WMF file out of QR and it looks perfect as well.
Pls have a look at my source:
procedure CreateReportAsPDF(aReport: TQuickRep; const aFileName: TFileName);
var Pdf: TPdfDocument;
aMeta: TMetaFile;
i: integer;
begin
Pdf := TPdfDocument.Create;
try
aReport.Prepare;
// pdf.DefaultPaperSize := psA4;
for i := 1 to aReport.QRPrinter.PageCount do begin
aMeta := aReport.QRPrinter.GetPage(i);
aMeta.SaveToFile('C:\temp\WMF\meta.wmf');
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;
.
I have no idea why it doesn't work.
BR, Klaus
Offline
We still haven't seen what exactly the problem is. Alignment problems? Or something else? "Doesn't render properly" isn't really a clear description.
I changed the length of the format command from format('%11.2n) to format('%7.2n) and now it seems correct, but why?
That would suggest some alignment problems. If you use spaces you would need to use (right aligned or decimal aligned) tabs to always correctly align numbers.
These also don't align in text:
145.12
133241.12
(and the first has 4 spaces, so is 7.2, second has 1 space so is also 7.2)
But I'm not sure why this would be correct in a WMF format (IF that's the actual problem of course).
Maybe it has to do with font substitution (in WMF one font and when rendered to PDF another font is chosen).
Now, I have created the meta WMF file and it looks correct, but the PDF file does not.
Additionally, I have created the WMF file out of QR and it looks perfect as well.
In that case it might be useful (especially for the developer) to have the sample meta.wmf to check where this goes wrong.
(It then can be loaded with aMeta.LoadFromFile('C:\temp\WMF\meta.wmf); and debugged properly.)
Last edited by rvk (2022-08-02 10:39:29)
Offline
Please forget the alignment problem. It was only a workaround but now I have used another invoice and it's wrong again.
I cannot understand why sometimes it's correct.
To debug the meta data, I'm not the expert and I see the problem to solve my problem. In the quick report, I'm using the font Arial Size 9.
I will try to upload my samples to dropbox and hopefully, I can create the link for you.
Offline
Now, I hope, you can download the files.
meta file:
https://www.dropbox.com/s/eoy8leijphzu0t0/meta.wmf?dl=0
pdf file
https://www.dropbox.com/s/k6zy5xenmr7ig … 2.PDF?dl=0
What's wrong:
- values on the right
- footer text
Last edited by KlausV (2022-08-02 13:42:42)
Offline
Yes, download went fine. I see what the problem is.
Somehow the spaces in between words are too large.
And that throws off the entire layout.
(I haven't got time right now to look into it further but maybe someone else recognizes this problem.)
Maybe TPdfDocumentGDI.UseMetaFileTextPositioning can help? (have to test that if I got some time)
For clarity here the PDF screenshot:
From the WMF loaded in LibreOffice Draw:
Last edited by rvk (2022-08-02 12:23:12)
Offline
Thanks for your help.
But the top line looks good with 5,00 EUR. Only the lines below are wrong.
Now, I added: pdf.UseMetaFileTextPositioning:= tpExactTextCharacterPositining, but no better result.
Now, it seems to be solved, hopefully.
I changed some parameters and now all of my test pdf files are OK.
procedure CreateReportAsPDF(aReport: TQuickRep; const aFileName: TFileName);
var Pdf: TPdfDocumentGdi;
aMeta: TMetaFile;
i: integer;
begin
Pdf := TPdfDocumentGdi.Create;
try
aReport.Prepare;
//pdf.UseMetaFileTextPositioning:= tpExactTextCharacterPositining;
pdf.DefaultPaperSize := psA4;
pdf.UseFontFallBack := True;
pdf.UseUniscribe := True;
pdf.FontFallBackName :='Arial';
pdf.ScreenLogPixels :=96;
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;
Have somebody any idea, what was wrong before? Or something wrong on my QR definitions?
Last edited by KlausV (2022-08-02 14:58:24)
Offline
Yes, I can confirm the UseUniscribe := true works in this case.
The UseFontFallBack were not needed for me (and seeing that the PDF already contains Arial I think they don't do much).
I don't now why UseUniscribe is needed when a fairly simple Arial font is used (I'm not that familiar with the inner workings of SynPDF).
But maybe it has something to do with the way everything is rendered into the WMF and after that the font-info becomes complex in which case there is a need for UseUniscribe (just guessing here).
BTW The reason some lines work fine and others not is in the fact that the space between words is wrong. And text which is combined is stretched. But text snippets that were placed on a certain position is fine.
The amount (Betrag) on the productline is on a specific position (so that works fine).
The amount for subtotal and MWST probably have multiple spaces in front of them and that's because they are shifted too much to the right (the multiple spaces are all expanded).
(hey, and that's where that format('%11.2n) and format('%7.2n) comes in. The 11.2 has more spaces and each space is expanded to multiple spaces. 7.2 has less space and that's why that one seemed to fix some of the issues )
Maybe @ab can elaborate on the reason for the need for UseUniscribe.
Offline
Yes, you're right. I need only the UseUniscribe := True. All others have no effect.
Offline
Pages: 1