#1 2013-03-04 19:36:11

dec
Member
Registered: 2013-03-04
Posts: 9

Background images using TGDIPages

Hello there,

First of all, many thanks to the Synopse author for their work. I begin to use the PDF engine and found super interesting and very very useful. Like I say, I begin to use this library in the "TGDIPages" way instead of use "TPdfDocument". I found a way to to place a background image into the PDF document, however, this manner use the "TPdfDocument" class. So, exists a possible way to do the same (or maybe a similar thing) in order to put a background image into a PDF document but using the "TGDIPages" class?

I try to use the "Draw" and "StrechDraw" method for the "TGDIPages.Canvas" property, however, I cannot obtain what I wanted: I only put the image into the page, but do not look as a background image, and have some "problems" with the image position, width and height. Maybe anyone can tell me what I can do it in order to get similar results like the "TPdfDocument", or, at the least, a possible solution, even if we need to repeat the background bitmaps along the pages.

Hope somebody can help me in this question.

Thanks in advance. smile

Offline

#2 2013-03-05 09:26:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Background images using TGDIPages

I've added TGDIPages.ExportPDFBackground property for custom pdf background picture.
It just uses the same code you quoted, at PDF export level.

See http://synopse.info/fossil/info/0dbe9d2230

Hope it helps.

Offline

#3 2013-03-05 12:57:50

dec
Member
Registered: 2013-03-04
Posts: 9

Re: Background images using TGDIPages

Hello,

Thank you very very much for your answer. I will try with your proposed solution and back here to explain the results.

Thank you very much again. wink

Offline

#4 2013-03-05 13:16:56

dec
Member
Registered: 2013-03-04
Posts: 9

Re: Background images using TGDIPages

Hello,

Well, I download and text the latest "TGDIPages" addition and work like a charm, so thank you very much again. Just one thing to say, because may can help in some manner. I note that the "BackgroundImage" is not instantiated, so we need to instantiate before assign the apropiate bitmap. I'am not really sure if we need to free this "TGraphic" object instance, since "TGDIPages" do not free it when destroy. I test it without free and do not get any error, and also try to free the "TGraphic" when "TGDIPages" is destroyed.

Maybe can be a good idea to instantiate the object itself by "TGDIPages"? I really don't know at this time but maybe you can think on this. Anyway the issue of this thread are well finished, since now it's possible to add a background image without any problems and with good results. What to say... thank you very much again!

Offline

#5 2013-03-05 14:23:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Background images using TGDIPages

You have to instantiate and free the instance after TGdiPage use, in current implementation.

But may be worth making a private copy, just like most VCL methods.
It does make perfect sense.

Offline

#6 2013-03-05 15:05:23

dec
Member
Registered: 2013-03-04
Posts: 9

Re: Background images using TGDIPages

Hello,

Yes. In fact the implementation have sense. And finally work like a charm. wink

Offline

#7 2013-03-05 23:40:54

dec
Member
Registered: 2013-03-04
Posts: 9

Re: Background images using TGDIPages

Hello,

I found something curious I want to share here. Maybe we can think it's a good idea to instantiate a "TBitmap" in "ExportPDFBackground" just when create the "TGDIPages" object, in other words, because some documents have backgrounds and others not, but, we think can be a good idea to prepare this object to be ready in the case of documents wich use the bitmap background. Bad decision...

I doing this and no found any problem with Nitro PDF reader, for example, but, a coleague tell me that have problems when try to open the PDF file using Acrobat Reader. This program say something like "This file is incorrect and may not show propertly. Contact with the author of the PDF to solve the problem.". So how I solve this "problem"? Simply create by instantiate the "ExportPDFBackground" just before load a bitmap and not when the "TGDIPages" is created.

Ok. The described aproach solve the problem, however, I want to say something more. If we doing the things bad (like described in the first paragraph), even when a document have a bitmap background, we get the same problem with Acrobat Reader... And I cannot imagine at this time what is the reason for this. I can understand the problem when we created the "ExportPDFBackground" and finally do not use it (it's an empty bitmap), but, what happend when the bitmap are provided?

Anyway, maybe this words did not help at all and I need go to sleep right now. wink Fortunatelly, the problem with Acrobat is solved if you try the right way: create the object just before load the bitmap from a file, for example. Then you can free the object just when you free the "TGDIPages" also. And then the PDF files can be viewed also in Acrobat Reader without problems, as well other readers like the embedded in latest Firefox releases.

Thanks for reading!

Offline

#8 2013-03-06 05:33:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Background images using TGDIPages

It just does not make sense to use the property like a container to a TBitmap.

The property is to be assigned with an existing bitmap, or left nil.

Offline

#9 2013-03-06 08:28:01

dec
Member
Registered: 2013-03-04
Posts: 9

Re: Background images using TGDIPages

ab wrote:

It just does not make sense to use the property like a container to a TBitmap.

The property is to be assigned with an existing bitmap, or left nil.

Yes. Maybe you can have absolutely reason. However, why the project wich create the instance at the beginning and then assign a bitmap file? Doing this the PDF have the same "problems", so I imagine that, for some reason, the image background is "try to added" before the bitmap is really provided. Anyway, if we instantiate the class just when need and load th bitmap just after we do not get any problem at all. Do not touch (more) on this and thank you for your amazing work and support.

Offline

Board footer

Powered by FluxBB