Dynamics Ax printing logo’s from batch

Hi,

*Edit Microsoft has released a fix for this problem contact support for this*

As all of you know the Image class in Dynamics Ax 4.0 and 2009 can only run on client. This poses a problem when you want to print for example invoices with your company logo on it. Having this found out I went to look for an alternative!

I’ve added this code to the top of the PDFViewer class in the writeBitmap(OutputBitmapField _field, OuputSection _section) method

For the method BLOGWriteBitmapOnServer(OutputBitmapField _field, OuputSection _section) I have copied everything from the writeBitmap and started by replacing the Image object with a System.Drawing.Image object, you can make a company parameter for this file path.

After compiling there are a few errors witch I’ve corrected and ended up with this code.

This could probably been done much cleaner, but it does the job. ๐Ÿ™‚

20 thoughts on “Dynamics Ax printing logo’s from batch”

  1. Kevin,
    This is REALLY nice thanks. I’m having sort of a weird problem with it though. I wrote a process that queues up the invoices that we’ve generated during that day and at night I go through and print a copy of the invoices to a PDF file and then email them out. The problem is that about 10% of the PDF’s are now corrupt. I’ve included an entire bad PDF file below and also the header of a good one. I’m attaching a b+w jpg (our logo) to the pdf. I tried a gif but AX didn’t seem to like that. Any ideas would be great. Thanks.

    Paul

    AX2009 SP1 RU4 + EE localization

    Bad:
    %PDF-1.3
    % Invoice 00477715 – Report
    % Generated by ppica on 2/9/2011 at 20:02:14
    5 0 obj <>
    1 0 obj <> endobj
    2 0 obj <>endobj
    3 0 obj <> endobj
    4 0 obj
    [/PDF /Text /ImageC]
    endobj
    xref
    0 6
    0000000000 65535 f
    0000000286 00000 n
    0000000350 00000 n
    0000000394 00000 n
    0000000450 00000 n
    0000000082 00000 n
    trailer <>
    startxref
    488
    %%EOF

    Good:
    %PDF-1.3
    % Invoice 00477717 – Report
    % Generated by ppica on 2/9/2011 at 20:02:16
    5 0 obj <>
    1 0 obj <> endobj
    2 0 obj <>endobj
    8 0 obj <<
    /Type/XObject /Subtype/Image /ColorSpace /DeviceRGB
    /Name /I8 /BitsPerComponent 8
    /Filter [/ASCII85Decode/DCTDecode] /DecodeParms[null<>]
    /Length 20511
    /Width 479 /Height 367
    >>
    stream

    (followed by the binary data for the jpg and everything else)

    1. Hmm we are using a jpg file too, sometimes we get an error ‘Could not convert Glyphs’ but I don’t think its related. I should do some more testing with this code I don’t have any time now ๐Ÿ™‚ If you find a solution for your problem let me know ๐Ÿ™‚

  2. Unfortunately, my solution was pretty lame. Since this is a batch process that sends copies of the invoices out I simply check the file size on the PDF that’s generated and if it’s less that 5k I throw it out and try again until I get a good one and then move on.

    The only thing that seemed to help was putting in a small delay. It’s almost like things were happening too fast within AX and the OS couldn’t keep up with reading in the jpg and then reading in PDF to attach to the email. Adding the delays in there has gotten my success rate up to around 95% as opposed to 90%.

    Still a wonderful piece of code. ๐Ÿ™‚ I can’t thank you enough!

    Paul

  3. Nope, not multi-threaded. ๐Ÿ™ I usually don’t do that unless the job takes a huge amount of time. As it is, even with the delays I’ve added this job (which only runs once a day off hours) takes less than 2 minutes.

    Paul

  4. Meanwhile there exists a hotfix from Microsoft. Contact your Microsoft Support and you’ll get a solution.

  5. I know I’m too late to this party, but will thow in my 2 cents nevertheless…

    In my wanderings through GDI+, when doing a batch of image generation, I found marked performance improvement if I forcibly called for garbage collection between image instances.

    GC.Collect(); // I think was the code

    I’m fairly new to doing DAX programming. I can see “System.GC” in my X++ intellisense, but, it doesn’t allow me to compile the aforementioned line of code.

    1. Hi,

      Thanks for your comment ๐Ÿ™‚
      Actually now that I come to think of it, all of the Image instances should be disposed along all node paths.
      *edit* this should call the garbage collector.

      By the way I’ve just downloaded the hotfix and this patches the server so this will probably be a much better solution.

      Regards,

      Kevin

  6. Thanks for the post but i don’t solve my problem.
    I’ve search the hotfix but i didn’t found it.
    can you tell me which hotfix is?
    i work with AX 4.0 and you?
    thank, bye

    1. Hello Sara,

      This code is from Ax 2009 SP1 KRU7, I’m guessing it was KB2667355. If you can’t find it you should log a technical support call.

      Kind Regards,

      Kevin

  7. Hi, Can anyone please guide me how can I re-size an image using the same method described above for image processing. Your response will be highly appreciated.

  8. Kevin,

    This was exactly what I was looking for and struggling with for a quite a while. You have saved me a lot of time and effort to get this to work. The hotfix works like a charm.

    Thanks,
    Bob

  9. Can you tell me what this means “companyInfo.BLOGCompanyLogoFile;” .
    I know its a field of table and its data type must be String but what data it should contain ?
    Can you please let me know immediately as i am facing this issue since long time and have not got any solution.

    1. Hi Lalit,

      It’s the path to the image file, why don’t you use the Microsoft hotfix this is a way betters solution. You can find it on partnersource.

      Kind regards,

      Kevin

      1. Which hotfix you are referring to?
        Can you please provide me the link for it to download ?
        Also can you please provide me the steps to install ?

Leave a Reply