WPCubed Product Support

Pasting an image into UseDefEditor

I was hoping that I could just copy and paste some text and a graphic in from Word and when I save it, it would be a compressed image. I see my users wanting to do this a lot.

The resulting image + text = 112KB.
In Word the .dot with it in is about 30KB, so I am guessing it is being stored as an uncompressed bitmap.

Is there something I can do before saving the text in userDefEditor.pas to convert to a png?

Regards,

#1 ♥ 0
16.4k Views 2 links 2 users read 10 min

<bump> as they say.

i am trying to get a number of documents live and they are still 120K+ instead of 30K+ and people are about to start producing large numbers of documents based on these templates.

Cheers,

JAC.

#2 ♥ 0
support

Hi,

In the altest wptools image unit - wpobj_image.pas I added some code to compress an image to PNG. This code in in the procedure Compress which is called for pasted images.

Julian

#3 ♥ 0

Julian,

I have 5.23.6 standard and have rebuilt UserDefEditor.dpr with wpobj_image.pas added to teh uses of the project (i.e. in UserDefEditor.dpr).
I have loaded my RTF and saved as and it is still 115KB for a doc header, which seems far too high.

When you said

In the altest wptools image unit

Is this in your latest of the release that I have?

Basically they we can't afford for all the documents to be 120+KB.

Regards,
Jason Chapman.

#4 ♥ 0
support

Hi,

I assume the problem is a bitmap. If you use PNG images this will be also compatible. You can use PNGLib to use PNG images in WPTools.

Please see the notes in unit WPObj_image.

Julian

#5 ♥ 0

I have sent you the test file.

I can't remember how I embedded the image, probably edit copy and edit paste from a word document or a graphics package.

assume the problem is a bitmap. If you use PNG images this will be also compatible. You can use PNGLib to use PNG images in WPTools.

When I went Insert Image and selected a png file, gave me an exception.

Please see the notes in unit WPObj_image.

I have, but have always been reluctant to change 3rd party or VCL code. I did add the unit to the project WPOBJ_Image, but did not add any defines.

Is the following correct:
If I have an rtf with embedded images and want my program to do mailmerge and save compressed images I need to:
Add WPObj_image to my application (although this on its own doesn't work with example program userdef....).
--- Do I also need to add {$DEFINE something in my project file?

Sorry for being dense.

#6 ♥ 0

I think I see now. I try to avoid digging around in components, but I can see the power that having these compiler options give.

So general advice. For a company logo, would you recommend:
COMPRESSBITMAPASJPEG
PNGIMG
GRAPHICEX

And I am assuming I will need to download and install additional components to use
PNGIMG or GRAPHICEX

I have not used either library and would prefer not to have to unless required. Am I on the right track?

Regards,

#7 ♥ 0

OK, I tried adding:
{$DEFINE COMPRESSBITMAPASJPEG}
{$DEFINE PNGIMG}

To the beginning of the Project unit and rebuild, and it has made no difference to the size of the file when I load & save, load, cut image, paste it back in and save.

#8 ♥ 0
support

You probably used copy&paste to insert this image. The
clipboard does not know PNG (or JPEG) and will always use
metafile or bitmaps.

You need to insert the file directly, either with Drag&drop
(AcceptFiles = true) or the InsertGraphicDialog

#9 ♥ 0

But the notes in the pas file say that if you add {$DEFNIE COMPRESSBITMAPASJPEG} then it will save them compressed.

The userdefEditor does not allow me to select a PNG, even if I change the filter. I changed the "acceptFiles" of the WPRichText to true.

The top of the project unit looks like:

program UseDefEditor;
{$I WPINC.INC}
{$DEFINE COMPRESSBITMAPASJPEG}
{$DEFINE PNGIMG}

{$DEFINE USE_LOCALISATION} // activate to use WPLanguagControl, see unit WPLocalU!

uses
  Forms,
  SysUtils,
  WPDefEditor,
  WPSplash,
  WPOBJ_Image
  {$IFDEF USE_LOCALISATION} , WPLocalU{$ENDIF}
  ;

If I drag a png, nothing gets pasted in, if I drag a text file, it works fine. So I am still doing something wrong?
[/code]

#10 ♥ 0
support

Hi,

With Delphi compiler defines are only valid in the unit which is currently beeing compiled.

So the $defines you make here are not know when the compiler works on WPObj_Image.

You need to either add those defines to WPINC.INC or, better, add them under "Conditionals" in the options dialog of your project. After doing so make sure to make a "Build all".

Julian

#11 ♥ 0

Silly me, should have realised that.

I added COMPRESSBITMAPASJPEG to the project | Options | Conditional and now get a much better 15KB.

When I did the same for PNGIMG it obvioulsy wanted the units that I need to download from sourceforge etc.

I think JPG may be all we need (although I need to print out on their hi-res printers to ensure quality is OK).

What might be useful would be a demo, demonstrating how to enable these features (even though some of it is not a WPTools issue e.g. defines).

Also any tweaks to change the default compression of the JPG's.

So now I have my mailmerge tool that handles:

  • sections that can be optional / mandatory choices o-n, 1-n, n.
  • Includes
  • nested fields (e.g. <vatdescription> -> "VAT NUMBER:<subtrust>" -> "VAT NUMBER: 012589388"
  • Tables with n rows fileld from a query.

Thanks for your help and patience. Next is embedding fields that ask the user for input and save just the data that the user entered. I might do a talk for UKBug RE: what little I have learned about WPTools later in the year.
Regards,

#12 ♥ 0

OK, so I opened the champagne too early. The letters actually end up being saved and users open them in Word and often print them from there. I currently have 2 problems and a question:

  1. The JPG has "fluffy" edges, which I should have guessed would happen. So I will try the PNG. I have opted for the PNG only library from sourceforge. I use envision components that also handle PNG, but I am guessing
  2. Will Word handle the PNG format with the RTF extension?
  3. When we print to one of our big printers, we have to adjust the contrast in Word for the image. Normally to 51% from 50% - it stops a very light grey background. It must eb a bug in one of the printers driverset as it doesn't happen on the other printer. When I saved a JPG I got the same thing. Can you adjust the contrast with PNG's - my guess is they have no concept of contrast.

Regards,

#13 ♥ 0

And another observation. If I produce a PNG'd rtf and open in word and then save it leaps from 30KB -> 226KB. This causes us another problem as once the letters are produced, they may be edited by the user and they would probably do that in Word.

Anyway, I think we are as far as we can get unless you have any other suggestions.

I can build all the templates using RTF & PNG. I can produce letters and save as small files. We will have to live with the fact that one of the printers will not be able to be used and that if the file is subsequently edited in Word it becomes 6 times larger.
Regards,

#14 ♥ 0
support

Hi,

  1. The JPG has "fluffy" edges, which I should have guessed would happen. So I will try the PNG. I have opted for the PNG only library from sourceforge. I use envision components that also handle PNG, but I am guessing <<It>>2) Will Word handle the PNG format with the RTF extension?

Yes, PNGImage are defined for RTF and very comon.

  1. When we print to one of our big printers, we have to adjust the contrast in Word for the image. Normally to 51% from 50% - it stops a very light grey background. It must eb a bug in one of the printers driverset as it doesn't happen on the other printer. When I saved a JPG I got the same thing. Can you adjust the contrast with PNG's - my guess is they have no concept of contrast. <<I> 226KB. This causes us another problem as once the letters are produced, they may be edited by the user and they would probably do that in Word. <<

Yes, Word will store then PNG and another copy (hex encoded!) as BMP or metafile. But I think this also happens when using JEPG. There is no way to avoid this in Word as far as I know.

Kind Regards,

Julian

#15 ♥ 0

Hi Julian, it's been a while as they say. They have been using the system with the 32 letters I put in there, but I think we are about to have a big push at getting more letters / reports in.

One of the problems I have at the moment is back to the company logo at the top of the page. They actually use word to print the documents we produce and they may tweak the letter and re-save it, so the letter goes from 30K -> 300K (in fact 500K in office 2007).

You said:

Yes, Word will store then PNG and another copy (hex encoded!) as BMP or metafile. But I think this also happens when using JEPG. There is no way to avoid this in Word as far as I know.

Do you have any further thoughts on that. Basically we:

  • take an RTF file produced in WPTools editor
  • include other files, all of which are from WPTools editor (one has logo and header)
  • save RTF file.
  • Launch in word
  • they normally just print and close, but often tweak / save it.

In a month we start doing print runs of 1500, so worse case scenario, the storage goes from 30 x 1500 = 43MB -> 732MB for that one run.

Do you have any ideas.
Users are using a mix of Office 2003 / 2007.
TIA.
Jason

#16 ♥ 0

Hi All,

I asked the same question on http://news.microsoft.com/m.public.word.docmanagment and asked:
Subject: RTF doc opened and saved goes from 30K to 300K - one image in the header
got a reply from: Peter Jamieson - kudos to him

which I did on office 2007 and the file went from 35K -> 60K, which is a whole lot better than 300 -> 600K.

Might be good to do a FAQ on it and some sample code to check / fix the registry.

Regards

#17 ♥ 0
support

Hi,

thanks for the tip. It is interesting that there is a "ExportPictureWithMetafile" registry key. I didn't know this.

Julian

#18 ♥ 0
This category is archived. No new posts are possible.