I am trying to add a custom image format and have WPTools support loading those images.
In this specific case I am trying to make PDF files look like images. I only care about getting the first page of the PDF file as an image.
I created a new class (TPDFImage) derived from TJPEG and overrode the LoadFromStream method to use WPViewPDF to convert the first page of the PDF into a Jpeg and set the internal TJPEG representation. That class is then registered:
TPicture.RegisterFileFormat('pdf', 'Load PDF File as an Image', TPDFImage);
So far everything is working great. I can work with PDF file just like images and show them in TImage controls.
Now I am trying to get PDF's loaded (as a image) during a mail merge with WPTools. To load my images I am doing the following:
Contents.LoadImageFromFile(AttachmentDir + DataValue);
I have traced this through and it eventually calls GetWPObjectForExtension. That returns Nil instead of my TPDFImage class. Is there something extra I need to do in order to get WPTools to recognize my new picture type?
I'm still not working but here is my latest attempt.
I realized that I didn't have GraphicEx turned on even though I am using it in my project. I added the compiler define and got it enabled. I also registered my customer image class with the GraphicEx system.
However it is still not working. I am still just getting blanks.
After some more digging is looks like all image formats need to be explicitly dealt with in the WPTools internals. Adding GraphicEx support just turned on PNG support using the GraphicEx PNG class. Random Graphic classes are never pulled in.
However I did find a solution to load up the Graphic first and then insert it in the document.
all Image handling is done in unit WPObj_Image.pas. This unit containes a lot of information.
Inserint a TPNGImage directly is not the best way to do it. The PNG support should be activated in WPObj_Image and then a TWPOImage should be created and loaded witha PNG stream.
Use the property FileExtension to specify "PNG".
Just inserting a TGraphic will show the image usually, but in many cases the original data (PNG, JPEG) will not be preserved and uncompressed bitmap format will be saved instead.
#4♥ 0
This category is archived. No new posts are possible.