How do I get Access to print GIF (or HTMLImage) data (1 Viewer)

peskywinnets

Registered User.
Local time
Today, 12:26
Joined
Feb 4, 2014
Messages
576
So I'm using UPS's API to create a shipping label...quite an ordeal, but I'm at the last stage now.

Ultimately, they return the shipping label to be printed in the following format (GIF or HTML Image) via XML...

Code:
<[B]GraphicImage[/B]>895UIGJ89XCASDVIGFUISDFNKLFSDANUI43UIT34IONSDFK
HG89GUKGJNGKDJFKDJDGKJDKFSDU089REUTDRKJOEIOUTERIJREIKGRJIGOWEJIEJIEGJ
GRIOEJGRIGJIODJGFIODFJSIOUDFIOGDFUGDF890ERUTRIOGTJRDIOOGJGIOSDFJGIOJGIOJ
IOGFUGJIOGU90E8T9TRFIRWEU90WERU90WU90WTU90WUT09WEUTWRJGKSDFJGIOSDFJ
GOISDFJGIOSJSD</GraphicImage>

<[B]HTMLImage[/B]>JDFSKAATRIOERHIOEGHNVIXCUIFGJMFDGMAN8Y89H54JM
N1MK345H8SDHFDHGJKGHFDJKGHDGKSFJAH893YTUITNGDFJSGH8935Y5RTHDDFJKHT89
HTJETHWER8934Y89534KGNDFOJKKH893RYETFIHTRUIOEY89TY34IHDFUIHGRU9T38934UI
THDIUJTHEQW89RY8WIERHT9RI</HTMLImage>

...what would be the mechanism here to get that data to automatically print! (I know how to extract the GIF data from the XML - so my line of questioning is more to do with what options I have to act upon the GIF data)

Do I save the data to a file first (e.g. label.gif) & then use some VBA to open the gif file in a browser (where I can manually print)...or is there some way I can automatically print? (preferred!)

Many thanks.
 
Last edited:

June7

AWF VIP
Local time
Today, 03:26
Joined
Mar 9, 2014
Messages
5,463
Have to save to file then embed onto report or on Excel sheet.

Or open file in a viewer app and manually print.
 

peskywinnets

Registered User.
Local time
Today, 12:26
Joined
Feb 4, 2014
Messages
576
Thanks...ok, I pulled the data out of the XML & piped it into a gif file but windows can't open the file - therefore my attention now goes back to the type of gif data UPS are supplying me with embedded the XML
 

jdraw

Super Moderator
Staff member
Local time
Today, 07:26
Joined
Jan 23, 2006
Messages
15,379
Pesky,
Are you a UPS customer--link.
 

jleach

Registered User.
Local time
Today, 07:26
Joined
Jan 4, 2012
Messages
308
You would have to know what kind of format that data is in. I would have first guessed Base64, but it doesn't quite look like it.

If it were base64, you would run a procedure to turn the string contents into a bytearray then write the bytes to a file, which essentially converts the text-based data to binary data that a gif format would expect (after which you can open it and do whatever with it as per normal image file management).

Does your API doc say anywhere what format the data is?
 

peskywinnets

Registered User.
Local time
Today, 12:26
Joined
Feb 4, 2014
Messages
576
Pesky,
Are you a UPS customer--link.

yes I am.

You would have to know what kind of format that data is in. I would have first guessed Base64, but it doesn't quite look like it.
If it were base64, you would run a procedure to turn the string contents into a bytearray then write the bytes to a file, which essentially converts the text-based data to binary data that a gif format would expect (after which you can open it and do whatever with it as per normal image file management).

Aaah ..this sounds interesting (& would explain why I can't simply dump their returned shipping label print data to a file & open it as a gif)


Does your API doc say anywhere what format the data is?

it's a very long document....too much info/detail in places (!) but I certainly couldn't locate anything that allowed me to progress, but in the light of what you've said about converting their data, I'll have another delve

http://idaho-dental-studio.com/wp-content/uploads/2012/11/Shipping-Package-XML-Developers-Guide.pdf
 

jdraw

Super Moderator
Staff member
Local time
Today, 07:26
Joined
Jan 23, 2006
Messages
15,379
Top of page 28
To include this data in an XML message, UPS converts it from binary to
text format using an algorithm known as
Base64 encoding
. The "The Base16, Base32, and
Base64 Data Encodings" standard, also known as RFC 3548
, defines that algorithm.

https://tools.ietf.org/html/rfc3548

Good luck.
 

peskywinnets

Registered User.
Local time
Today, 12:26
Joined
Feb 4, 2014
Messages
576

Bingo :)

Found this...

https://www.motobit.com/tips/detpg_base64/

got me a label now - chuffed to bits...thanks for your moral support & input!

So I'm figuring the simplest way for me to get Access to print out a GIF file, would be to create a report with the GIF file embedded within?

also, the decoded GIF file has the wrong orientation, this is what I see when I preview the decoded GIF file...



it's showing it 6" x 4" ...whereas my thermal printer paper in is 4" x 6" ...I can't find any option to rotate the image when embedding in MS access (nor anything in page setup printer properties!) - any ideas
 
Last edited:

jleach

Registered User.
Local time
Today, 07:26
Joined
Jan 4, 2012
Messages
308
For future reference, Base64 is the cheapo-defacto-standard way to move binary data through character-based mediums, so it's likely to be something you'll run into often (Base64 data is usually recognizable as such in that it's not limited to the hex ascii code set, and often ends in = or == (which is why I couldn't quite tell if your original post was Base64 data or not).

This is especially true in emails, particularly for embedded graphics, but pretty much anything that travels over HTTP is apt to have something in the format. It's also handy for storing in a database as text (for example, you could load that into a data field easily in Access/SQL Server, but beware as the strings can become rather large).

The format itself isn't that great, but it's like taking a taxi cab: easy enough to use and might smell a bit, but gets the job done.

In any case, glad you got it working. No suggestions regarding rotating for printing (there's third party tools that can do it, but not ideal... maybe look up some GDIPlus API calls?)
 

jleach

Registered User.
Local time
Today, 07:26
Joined
Jan 4, 2012
Messages
308
Looks like GDIPlus does have a rotate/flip method, but whether it's worth it try to and access that via VBA might be a different story:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms535401(v=vs.85).aspx

(for other reference, you can find some nice GDIPlus API code from here: http://www.activevb.de/tipps/vb6tipps/tipp0644.html http://www.accessribbon.de/en/?Acce...ed_Icons___Pictures_In_Ribbon_Controls#basGDI )

With that said, might just be a lot easier to find some third party tool that has a commandline option to do so which you could shell out from your app (I'd probably go this route if it's an internal application that's relatively.. informal)

Ideally you'd be able to do something like:

Code:
Function RotateImage(FilePath As String)
  Dim cmd As String
  cmd = "WhateverToolYouFound.exe """ & FilePath & """ /rotate /cw"
  Shell cmd
  DoEvents:   DoEvents:   DoEvents: 'or check if file locked for more robust
End Function


And finally, one more thought: the API might have some parameter to designate orientation of the image.
 

jleach

Registered User.
Local time
Today, 07:26
Joined
Jan 4, 2012
Messages
308
Good find, WIA is a great library (hadn't thought of it), built-in, no external dependencies, etc. Sounds like the way to go were it me doing this.

Cheers,
 

peskywinnets

Registered User.
Local time
Today, 12:26
Joined
Feb 4, 2014
Messages
576
That's the rotation sorted - thanks :)

But I've still not 100% put this to bed yet (already, I've spent about a day spent on this topic alone!)

it transpires that - for some unexplained reason...the downloaded UPS gif resolution is 1400 x 800 ..bearing in mind the most thermal label dimensions are 4" x 6" ...there's therefore 200 pixels of white space at the bottom of the downloaded label gif - what were they thinking.

the problem he is that the downloaded gif doesn't scale to fit the thermal printer - so now I need to search for a tool that will crop the downloaded gif to 1200 x 800 - you can't make this stuff up!
 

peskywinnets

Registered User.
Local time
Today, 12:26
Joined
Feb 4, 2014
Messages
576
A search for "WIA Crop Image" seems promising... for example, post #5 in this thread: http://www.vbforums.com/showthread.php?804921-crop-resize-zoom-and-save-image


Indeed it was, the code below crops 200 pixels off the bottom of my gif...

Code:
Public Sub CropPicture()
Dim Img 'As ImageFile
Dim IP 'As ImageProcess

Set Img = CreateObject("WIA.ImageFile")
Set IP = CreateObject("WIA.ImageProcess")

Img.LoadFile "C:\AccessData\UPS\UPSShippingLabel.gif"

IP.filters.Add IP.FilterInfos("Crop").FilterID
IP.filters(1).Properties("Bottom") = 200
Set Img = IP.Apply(Img)
Img.SaveFile "C:\AccessData\UPS\UPSShippingLabel_crop.gif"
End Sub

Many thanks once again for the pointers/heads up - it was just the shove I needed ;-)
 

jdraw

Super Moderator
Staff member
Local time
Today, 07:26
Joined
Jan 23, 2006
Messages
15,379
See this function by Emilio Sancha to redimension an image.


I've used this function several times.
I modified the intro comments to show some English
'---------------------------------------------------------------------------------------
' Procedure : Redimensionar
' Author : mellon from http://www.utteraccess.com/forum/index.php?showtopic=2035296&hl=
' Date : 03/03/2016
' Purpose :'* Resize
'* Rescaled last image as a parameter 'by Emilio Sancha Spanish MVP
'***** Must include a reference to Microsoft Windows Image Acquisition Library vX.X
'***** /
'*****Not required for Vista and newer. + **********************************************
'***** \
'* Arguments: strArchivo => file path to resize
'* LngAlto => height in pixels to apply
'* LngAncho => width in pixels to apply
'* Usage: Resize "C: \ Temp \ test.png"
'* ESH 16/08/09
'* If you use this code, respects the authorship and credits
 

Users who are viewing this thread

Top Bottom