You are not logged in.
Pages: 1
Hi!
I finally found the real BUG.
The problem occurrs when I use this windows API functions over the MetafileCanvas.
CreateRectRgnIndirect
SelectClipRgn
I create my MetafileCanvas setting a custom clip region to draw my stuff, and when I draw some images over the MetafileCanvas the PDF cannot render it correctly.
Here is the sample that reproduces the problem.
https://www.dropbox.com/s/ikoi2dv1wgzbf … g.zip?dl=0
To fix, I just removed my clip region!
ab, problem solved!
I think the problem was around EMR_STRETCHBLT.
Below the complete solution that worked for me:
I upgraded to the latest version.
But I made some extra changes. I realy think that the faulty is about the image drawing (StretchDraw and different types of image).
I was drawing using the canvas Draw(X,Y,Graphic) and StretchDraw(Rect,Graphic), the images were bitmaps, jpgs, pngs.
Now I changed it to always generate a bitmap with the expected result size and without transparency. Then I draw it (using Draw(X,Y,Bitmap)) to the MetafileCanvas. So now I have only bitmaps in the metafile, so as in the resulting PDF.
I'll let this changes in test in some of my customers, because I wasn't able to reproduce the problem. I'll update this thread with the results in some days.
I upgraded to the latest version.
But I made some extra changes. I realy think that the faulty is about the image drawing (StretchDraw and different types of image).
I was drawing using the canvas Draw(X,Y,Graphic) and StretchDraw(Rect,Graphic), the images were bitmaps, jpgs, pngs.
Now I changed it to always generate a bitmap with the expected result size and without transparency. Then I draw it (using Draw(X,Y,Bitmap)) to the MetafileCanvas. So now I have only bitmaps in the metafile, so as in the resulting PDF.
I'll let this changes in test in some of my customers, because I wasn't able to reproduce the problem. I'll update this thread with the results in some days.
Try to find out, using EmfExplorer, which EMF_* commands may be faulty.
Once you identified which part of SynPdf needs improvement, we may start looking into it.
I don't known how to do that, this is because that I'm here!
How does your application generate the EMF?
Is it a known reporting tool/component?
It is generated using delphi native api (TMetafileCanvas, textOut, Draw, etc...)
If there is no image/logo, does it work as expected?
Yes, it works!
Which version of SynPDF are you using? Current from our source code repository is 1.18.2273.
I'm using version 1.18.1417.
My application generate EMF images and I render them into PDF using RenderMetaFile function.
Sometimes, not every, the resulting pdfs have render problems, normally when they contains images/logos.
Below 2 PDFs with the problem. They only work inside Chrome. Using another reader like Acrobat Reader they dont present errors.
https://dl.dropboxusercontent.com/u/697 … %20151.pdf
This is the EMF source:
https://dl.dropboxusercontent.com/u/697 … 0147-2.emf
I tried EMFExplorer, but I have no idea how to use it and what I need to search for.
This ?
R0808: [081] EMR_STRETCHDIBITS (s=36884) {rclBounds(55,155,72,167), Dest[x:0, y:0, cx:134, cy:91)], dwRop(0x00CC0020), Src[x:0, y:0, cx:134, cy:91, iUsage:0, offBmi:80, Bmi:40, offBits:120, Bits:36764] BmiHeader[biSize:40, biWidth:134, biHeight:91, biPlanes:1, biBitCount:24, biCompression:0, biSizeImage:36764, biXPelsPerMeter:0, biYPelsPerMeter:0, biClrUsed:0, biClrImportant:0]}
You cannot download my source code and take a look ?
http://www.mediafire.com/?ftesmt6xm4k9r70
OK, I found the image problem, but only it, using the EMF Explorer.
If you open the generated PDF with that EMF, you will able to see others bugs:
- image size (barcode image)
- rectangles drawed in incorrect positions
Only one thing I do not understand ....
Printing the report from QuickReport with PDFCreator printer, all is well. The resulting PDF becomes correctly.
There is no possibility to make a work around? I don`t want to "hunt" this bug over QuickReport, it sucks!
Thanks!
I`m using the latest version ...
Please try download from this one http://www.mediafire.com/?ftesmt6xm4k9r70
I created a filter implementation for QuickReport, to export the report to a PDF, using PdfEngine 1.15.
The example attached reproduces the bug.
Take a look at "Page1.emf" inside the zip, note that the metafile is correct, but when I play it to the pdf, the metafile imagens become larger...
Zip with sourcecode to reproduce the bug:
http://www.4shared.com/zip/01AQRFxN/Syn … e_bug.html
Thanks.
What I mean with "shutdown" is, my application halt, exit, closes instantaneously!
I was using FastMM 4.98 with SynPDF 1.15
Now I'm using FastMM 4.99 with SynPDF 1.16 (from trunk).
I cannot reproduce this, because the problem occurs indefinitely....
... sometimes when the user click on any button... sometimes when the user moves the mouse... this is bizzare!
I will try downgrade to SynPDF 1.15, checking for old bugs, and I will report...
I will try downgrade FastMM to 4.98 too...
Thanks for this moment....
Hi...
Recently I was forced to migrate to a version of PDFengine coming from TRUNK.
With this version my system began to shut down without giving any error. The enduser is using a screen, that does not use SynPDF, and suddenly the application halt!
This problem started after I used version 1.16 of the trunk (SynPdf, SynCommons, ...).
To solve the problem, I created a DLL to create PDFs for me, and apparently the problem stopped occurring.
I suspect that there is a problem in SynCommons. I've already reported two problems that I encountered in this unit (check posts with my name).
I recently had problems with an access violation in PNFIMAGE.PAS unit, that I use .... the strange thing is that I use that unit more than five years, and it never had problems, but now with this version a problem appeared. I solve this problem by enabling PURE_PASCAL to prevent SynCommons to override the MOVE, FillChar and RECORDCOPY, but this didn't solve the halting problem...
I use in my system:
- Delphi 7 Enterprise.
- Runtime Packages
- FastMem 4.99
Can someone help me?
This was my AV:
[007526ED] SynCommons.Move (Line 8576, "JJWCommon\Third Part\pdf\SynCommons.pas" + 21) + $0
[0068219D] Windows.CopyMemory + $1
[0069F583] pngimage.TChunkIHDR.Assign (Line 2233, "JJWCommon\Third Part\PngImage\pngimage.pas" + 14) + $19
[006A43F8] pngimage.TPNGObject.AssignPNG (Line 5300, "JJWCommon\Third Part\PngImage\pngimage.pas" + 15) + $1A
[006A28B0] pngimage.TPNGObject.Assign (Line 4409, "JJWCommon\Third Part\PngImage\pngimage.pas" + 6) + $11
[016898DE] Graphics.TPicture.SetGraphic + $2A
[0070CBBE] JJWDBImage.TJJWDBImage.FDataLinkDataChange (Line 303, "JJWComponents\JJWDBImage.pas" + 21) + $12
[4080B2B8] Dbctrls.TFieldDataLink.RecordChanged + $18
[4080B0D8] Dbctrls.TFieldDataLink.SetField + $18
[4080B114] Dbctrls.TFieldDataLink.UpdateField + $30
[4080B21D] Dbctrls.TFieldDataLink.ActiveChanged + $5
[40348A2D] Db.TDataLink.SetActive + $21
[40348A5C] Db.TDataLink.UpdateState + $18
[40348B76] Db.TDataLink.DataEvent + $E
[4080B2FF] Dbctrls.TFieldDataLink.DataEvent + $F
[403491B1] Db.TDataSource.NotifyLinkTypes + $3D
[403491E2] Db.TDataSource.NotifyDataLinks + $1E
[40348FEA] Db.TDataSource.SetState + $16
[40349031] Db.TDataSource.UpdateState + $15
[403491FC] Db.TDataSource.DataEvent + $10
[4034DB78] Db.TDataSet.DataEvent + $130
[402F8288] Dbclient.TCustomClientDataSet.DataEvent + $58
[4034BC89] Db.TDataSet.SetState + $21
[4034C1BB] Db.TDataSet.OpenCursorComplete + $47
[4034C0EB] Db.TDataSet.SetActive + $77
[4034C12F] Db.TDataSet.SetActive + $BB
[4034BF14] Db.TDataSet.Open + $4
[00741EC0] UJJWDBXDataModule.TJJWDBXDataModule.SQLOpen (Line 1370, "JJWMiddleManagers\SQLManager\UJJWDBXDataModule.pas" + 7) + $6
[0658EFB3] Ufrmfatnfs.TFrmFATNFS.LnkPESPessoasClientesClick + $7F
[01701C38] Controls.TControl.Click + $64
[016A80FC] Buttons.TSpeedButton.Click + $0
[00833F26] JJWUIChildFormLinkButton.TJJWUIChildFormLinkButton.Click (Line 216, "JJWManagersComponents\JJWUIChildFormLinkButton.pas" + 94) + $2
[016A80E6] Buttons.TSpeedButton.MouseUp + $E2
[01702024] Controls.TControl.DoMouseUp + $2C
[01702099] Controls.TControl.WMLButtonUp + $69
[01701A98] Controls.TControl.WndProc + $188
[00834150] JJWUIChildFormLinkButton.TJJWUIChildFormLinkButton.WndProc (Line 296, "JJWManagersComponents\JJWUIChildFormLinkButton.pas" + 1) + $2
[01701868] Controls.TControl.Perform + $24
[01704B2E] Controls.TWinControl.IsControlMouseMsg + $82
[4000341A] System.@GetMem + $A
[01704C1A] Controls.TWinControl.WndProc + $DA
[40006F33] System.@LStrFromPCharLen + $23
[01704914] Controls.TWinControl.MainWndProc + $2C
[4003E038] Classes.TDataModule.WriteHeight + $20
[017506AD] Appevnts.TCustomApplicationEvents.DoMessage + $D
[0172568B] Forms.TApplication.ProcessMessage + $83
[017256C2] Forms.TApplication.HandleMessage + $A
[017258F2] Forms.TApplication.Run + $96
(000244B3) [004254B3]
I got an AV while using SynCommons.pas and FastMM4.pas.
The AV has ocurred at the MOVE procedure, what is replaced by the SynCommons (internal move)...
I solved the problem using PUREPASCAL definition...
My suggestion is to create a DEFINITION to disable this optimization (copyrecord, move, etc.) in the SynCommons.pas.
I wasn't able to reproduce the AV with a sample code, sorry (I will continue trying..)
"Thanks" you man, nice support!
Now I'm able to inactive PUREPASCAL define, and all works fine!!!
.... BUT using PUREPASCAL another AV occurs...
Version: 1.16 (trunk)
[005EC479] SynPdf.HashOf (Line 4994, "JJWCommon\Third Part\pdf\SynPdf.pas" + 3) + $C
[005EC4CB] SynPdf.DoHash (Line 5028, "JJWCommon\Third Part\pdf\SynPdf.pas" + 2) + $4
[005EC616] SynPdf.TPdfDocument.CreateOrGetImage (Line 5051, "JJWCommon\Third Part\pdf\SynPdf.pas" + 19) + $D
[005F294A] SynPdf.TPdfEnum.DrawBitmap (Line 7603, "JJWCommon\Third Part\pdf\SynPdf.pas" + 16) + $11
[005F2611] SynPdf.EnumEMFFunc (Line 7501, "JJWCommon\Third Part\pdf\SynPdf.pas" + 216) + $30
[005F272A] SynPdf.TPdfCanvas.RenderMetaFile (Line 7538, "JJWCommon\Third Part\pdf\SynPdf.pas" + 18) + $1F
I got a WORKAROUND:
// setting on TPdfDocumentGDI
pdf.ForceNoBitmapReuse := True;
Here is the example: http://www.4shared.com/zip/eLNLqKEZ/SynPDF_AV.html
Zip password is: synpdfav
Take a look on the algorithm of (SynCommons.pas 1.16)
function SubHash(P: PCardinalArray; L: integer): cardinal;
// from line = 13838
// L = 3072
1: for i := 1 to L shr 4 do begin // 16 bytes (4 DWORD) by loop - aligned read
inc(s1,P^[0]);
inc(s2,s1);
inc(s1,P^[1]);
inc(s2,s1);
inc(s1,P^[2]);
inc(s2,s1);
inc(s1,P^[3]);
inc(s2,s1);
2: inc(PtrUInt(P),16);
end;
for i := 1 to (L shr 2)and 3 do begin // 4 bytes (DWORD) by loop
inc(s1,P^[0]);
inc(s2,s1);
inc(PtrUInt(P),4);
end;
3: inc(s1,P^[0] and Mask[L and 3]); // remaining 0..3 bytes
inc(s2,s1);
result := s1 xor (s2 shl 16);
1 -> ((L = 3072) shr 4) = 192
2 -> 192 * 16 = 3072 (END OF CARDINAL ARRAY)
3 -> (THERE ISN'T 4 REMAINING BYTES, NOW AV!)
I tried with the trunk version (1.16), I defined USEPACKAGES in Synopse.inc (because I'm using the SynPdf in a runtime package).
I got another AV.....
[007B47CA] SynCommons.Hash32 (Line 13908, "JJWCommon\Third Part\pdf\SynCommons.pas" + 35) + $0
[007EB080] SynPdf.DoHash (Line 5027, "JJWCommon\Third Part\pdf\SynPdf.pas" + 1) + $4
[007EB1D6] SynPdf.TPdfDocument.CreateOrGetImage (Line 5051, "JJWCommon\Third Part\pdf\SynPdf.pas" + 19) + $D
[007F150A] SynPdf.TPdfEnum.DrawBitmap (Line 7603, "JJWCommon\Third Part\pdf\SynPdf.pas" + 16) + $11
[007F11D1] SynPdf.EnumEMFFunc (Line 7501, "JJWCommon\Third Part\pdf\SynPdf.pas" + 216) + $30
[007F12EA] SynPdf.TPdfCanvas.RenderMetaFile (Line 7538, "JJWCommon\Third Part\pdf\SynPdf.pas" + 18) + $1F
At the first post, I was using PUREPASCAL define...
I got a AV when I trying to create a PDF, drawing a Metafile that contains a bitmap image.
SynCommons: 1.15
SynPdf........: 1.16
Error stack trace:
[007B3440] SynCommons.SubHash (Line 13358, "JJWCommon\Third Part\pdf\SynCommons.pas" + 20) + $A
[007B3458] SynCommons.Hash32 (Line 13365, "JJWCommon\Third Part\pdf\SynCommons.pas" + 0) + $0
[007E931C] SynPdf.DoHash (Line 5018, "JJWCommon\Third Part\pdf\SynPdf.pas" + 1) + $4
[007E9472] SynPdf.TPdfDocument.CreateOrGetImage (Line 5042, "JJWCommon\Third Part\pdf\SynPdf.pas" + 19) + $D
[007EF7A6] SynPdf.TPdfEnum.DrawBitmap (Line 7596, "JJWCommon\Third Part\pdf\SynPdf.pas" + 16) + $11
[007EF470] SynPdf.EnumEMFFunc (Line 7494, "JJWCommon\Third Part\pdf\SynPdf.pas" + 215) + $30
[007EF586] SynPdf.TPdfCanvas.RenderMetaFile (Line 7531, "JJWCommon\Third Part\pdf\SynPdf.pas" + 18) + $1F
Code:
with TPdfDocumentGDI.Create do
try
//evita o problema de não rendenizar o texto corretamente
UseUniscribe := True;
CompressionMethod := cmFlateDecode;
ScreenLogPixels := 72;
NewDoc;
with AddPage do
Canvas.RenderMetaFile(myTMetafileInstance, 1, MARGIN, -MARGIN, False, 0, 0);
finally
Free;
end;
If you need the source metafile, send me a private message with your email address, and I will send you it.
Thanks.
Working 100%, nice work!
Ps.: I also need to use UniScribe=true to render the PDF correctly....
Thanks!
bye!
Example at:
http://www.4shared.com/file/U8fV6lTV/SynPdfBUG.html
Decompress, open in delphi, run and click on the button!
The example creates a TPdfDocumentGDI and render 24 metafiles on it. At the TPdfDocumentGDI.savetostream the A.V. occours.
Bye.
This PDF is only created drawing Metafiles (renderMetafile method)...
In this metafiles exists custom fonts (created by windows API CreateFont http://msdn.microsoft.com/en-us/library … s.85).aspx ). This fonts are created based on Courier New and has diferent fixed widths.
Can this be the problem? If yes, how can I fix this? (I cannot stop using the CreateFont because of my Report Generator)
PDF Engine 1.15
I`m creating a PDF GDI and saving to a stream. During the save progress, a access violation occours (accessing a NIL value)
I have done a workaround (but I dont known if is correct) in SynPdf.pas added after line 3047:
procedure TPdfDictionary.AddItem(const AKey: PDFString; AValue: TPdfObject;
AInternal: Boolean);
var FItem: TPdfDictionaryElement;
begin
RemoveItem(AKey);
if AValue = nil then Exit; /// <<<<<<<< THIS IS MY W.A. <<<<<<<<<<
if AValue.ObjectType = otDirectObject then
The exception cause comes from (line 6490, SynPdf.pas):
procedure TPdfFontTrueType.PrepareForSaving;
....
if fDoc.PDFA1 or not WinAnsiFont.fFixedWidth then begin
WR.Add('['); // fixed width will use /DW value
// WinAnsiFont.fUsedWide[] contains glyphs used by ShowText
for i := 0 to n-1 do
with WinAnsiFont.fUsedWide[i] do
if int<>0 then
WR.Add(Glyph).Add('[').Add(Width).Add(']');
Descendant.AddItem('W',TPdfRawText.Create(WR.Add(']').ToPDFString));
end;
Descendant.AddItem('FontDescriptor',WinAnsiFont.fFontDescriptor); //// BUG: WinAnsiFont.fFontDescriptor = nil !!! WHY ?
fDoc.FXref.AddObject(Descendant);
This is the stacktrace :
[0080BEBD] SynPdf.TPdfDictionary.AddItem (Line 3048, "JJWCommon\Third Part\pdf\SynPdf.pas" + 3) + $3
[0080BEB5] SynPdf.TPdfDictionary.AddItem (Line 3046, "JJWCommon\Third Part\pdf\SynPdf.pas" + 1) + $6
[0080BF78] SynPdf.TPdfDictionary.AddItem (Line 3062, "JJWCommon\Third Part\pdf\SynPdf.pas" + 1) + $19
[00815974] SynPdf.TPdfFontTrueType.PrepareForSaving (Line 6491, "JJWCommon\Third Part\pdf\SynPdf.pas" + 28) + $13
[0080BF11] SynPdf.TPdfDictionary.AddItem (Line 3052, "JJWCommon\Third Part\pdf\SynPdf.pas" + 7) + $9
[0081010C] SynPdf.TPdfDocument.SaveToStream (Line 4631, "JJWCommon\Third Part\pdf\SynPdf.pas" + 15) + $3
[00817AB5] SynPdf.TPdfDocumentGDI.SaveToStream (Line 7119, "JJWCommon\Third Part\pdf\SynPdf.pas" + 12) + $C
Sorry about my english!
Bye.
I solved the problem.
I noticed the following:
Change the page size causes the problem. I had to use the DefaultPageWidth and DefaultPageHeight.
And thanks about the tip:
"Note also that PDF coordinates are not working the same as GDI coordinates: they are bottom-left based."
Please, make tests changing the page size to smaller and bigger pages.
I think there is any problem related to changing the page size.
Try to make a PDF, add a new page and decrease the size of this page. Then try to paint a metafile of the same size on this page.
Thanks.
This is my code:
with TPdfDocumentGDI.Create do
try
UseUniscribe := True;
CompressionMethod := cmFlateDecode;
ScreenLogPixels := 72;
NewDoc;
page := TMetafile.Create;
try
for i := 1 to GraphicReport.PageCount do
begin
GraphicReport.DrawPage(i, page); // this this the METAFILE generated by my ReportGenerator
with AddPage do
begin
PageWidth := Max(PageWidth, page.Width + (MARGIN * 2));
PageHeight := Max(PageHeight, page.Height + (MARGIN * 2));
Canvas.RenderMetaFile(page, 1, 0, 0, False);
end;
end;
finally
page.Free;
end;
SaveToStream(Stream);
finally
Free;
end;
After the export, the PDF has rendered my metafile out of the pdf page. the OffsetY seems not being respected.
More curious still is the following ...
The more I increase the offsetY (200, 300, 400 ...) the top margin decreases instead of increasing.
Hi.
I need to render a Metafile using canvas.RenderMetafile at position x:0, y:0.
After do this, a got Margins at the resulting pdf.
How can I force the PDF to have NO MARGINS ?
Guys, I solved the problem.
I just set the TPdfDocumentGDI.UseUniscribe to true.
Bye.
Hi.
I have found a bug at the PDF engine.
My report generator is using the PDF engine to export the report as PDF.
Internaly, the generator create a metafile and draw it to the PDF via VCLCanvas.
Below, the resulting PDF:
http://www.4shared.com/document/3mxTiIPt/teste.html?
Note, at the end of the PDF, exists a text, drawed as:
"Valor das mercadoria"
If you select the line text, and press CTRL+C (to copy the text) you will get this:
"Valor das mercadoria s:"
Any idea ?
Thanks, and sorry about my english...
Pages: 1