Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-21-2018, 11:52 PM   #1
peskywinnets
Newly Registered User
 
Join Date: Feb 2014
Location: London, UK
Posts: 492
Thanks: 259
Thanked 4 Times in 4 Posts
peskywinnets is on a distinguished road
How do I get Access to print GIF (or HTMLImage) data

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:
<GraphicImage>895UIGJ89XCASDVIGFUISDFNKLFSDANUI43UIT34IONSDFK
HG89GUKGJNGKDJFKDJDGKJDKFSDU089REUTDRKJOEIOUTERIJREIKGRJIGOWEJIEJIEGJ
GRIOEJGRIGJIODJGFIODFJSIOUDFIOGDFUGDF890ERUTRIOGTJRDIOOGJGIOSDFJGIOJGIOJ
IOGFUGJIOGU90E8T9TRFIRWEU90WERU90WU90WTU90WUT09WEUTWRJGKSDFJGIOSDFJ
GOISDFJGIOSJSD</GraphicImage>

<HTMLImage>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 by peskywinnets; 06-22-2018 at 12:11 AM.
peskywinnets is offline   Reply With Quote
Old 06-22-2018, 02:07 AM   #2
June7
Newly Registered User
 
Join Date: Mar 2014
Posts: 588
Thanks: 0
Thanked 136 Times in 136 Posts
June7 will become famous soon enough
Re: How do I get Access to print GIF (or HTMLImage) data

Have to save to file then embed onto report or on Excel sheet.

Or open file in a viewer app and manually print.
June7 is offline   Reply With Quote
The Following User Says Thank You to June7 For This Useful Post:
peskywinnets (06-22-2018)
Old 06-22-2018, 02:48 AM   #3
peskywinnets
Newly Registered User
 
Join Date: Feb 2014
Location: London, UK
Posts: 492
Thanks: 259
Thanked 4 Times in 4 Posts
peskywinnets is on a distinguished road
Re: How do I get Access to print GIF (or HTMLImage) data

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

peskywinnets is offline   Reply With Quote
Old 06-22-2018, 03:14 AM   #4
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 11,535
Thanks: 54
Thanked 1,871 Times in 1,821 Posts
jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice
Re: How do I get Access to print GIF (or HTMLImage) data

Pesky,
Are you a UPS customer--link.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
The Following User Says Thank You to jdraw For This Useful Post:
peskywinnets (06-22-2018)
Old 06-22-2018, 03:30 AM   #5
jleach
Newly Registered User
 
jleach's Avatar
 
Join Date: Jan 2012
Location: New York, NY
Posts: 298
Thanks: 16
Thanked 68 Times in 68 Posts
jleach will become famous soon enough
Re: How do I get Access to print GIF (or HTMLImage) data

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?
__________________
- Jack D. Leach

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Microsoft MVP 2012-2016
jleach is offline   Reply With Quote
The Following User Says Thank You to jleach For This Useful Post:
peskywinnets (06-22-2018)
Old 06-22-2018, 03:48 AM   #6
peskywinnets
Newly Registered User
 
Join Date: Feb 2014
Location: London, UK
Posts: 492
Thanks: 259
Thanked 4 Times in 4 Posts
peskywinnets is on a distinguished road
Re: How do I get Access to print GIF (or HTMLImage) data

Quote:
Originally Posted by jdraw View Post
Pesky,
Are you a UPS customer--link.
yes I am.

Quote:
Originally Posted by jleach View Post
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)


Quote:
Originally Posted by jleach View Post
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-co...pers-Guide.pdf
peskywinnets is offline   Reply With Quote
Old 06-22-2018, 04:06 AM   #7
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 11,535
Thanks: 54
Thanked 1,871 Times in 1,821 Posts
jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice
Re: How do I get Access to print GIF (or HTMLImage) data

Top of page 28
Quote:
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.

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
The Following User Says Thank You to jdraw For This Useful Post:
peskywinnets (06-22-2018)
Old 06-22-2018, 05:04 AM   #8
peskywinnets
Newly Registered User
 
Join Date: Feb 2014
Location: London, UK
Posts: 492
Thanks: 259
Thanked 4 Times in 4 Posts
peskywinnets is on a distinguished road
Re: How do I get Access to print GIF (or HTMLImage) data

Quote:
Originally Posted by jdraw View Post
Top of page 28


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

Good luck.
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 by peskywinnets; 06-22-2018 at 05:26 AM.
peskywinnets is offline   Reply With Quote
Old 06-22-2018, 05:37 AM   #9
jleach
Newly Registered User
 
jleach's Avatar
 
Join Date: Jan 2012
Location: New York, NY
Posts: 298
Thanks: 16
Thanked 68 Times in 68 Posts
jleach will become famous soon enough
Re: How do I get Access to print GIF (or HTMLImage) data

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?)
__________________
- Jack D. Leach

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Microsoft MVP 2012-2016
jleach is offline   Reply With Quote
Old 06-22-2018, 05:46 AM   #10
jleach
Newly Registered User
 
jleach's Avatar
 
Join Date: Jan 2012
Location: New York, NY
Posts: 298
Thanks: 16
Thanked 68 Times in 68 Posts
jleach will become famous soon enough
Re: How do I get Access to print GIF (or HTMLImage) data

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/lib...(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/?Acces...ontrols#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.
__________________
- Jack D. Leach

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Microsoft MVP 2012-2016
jleach is offline   Reply With Quote
The Following User Says Thank You to jleach For This Useful Post:
peskywinnets (06-22-2018)
Old 06-22-2018, 06:18 AM   #11
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 11,535
Thanks: 54
Thanked 1,871 Times in 1,821 Posts
jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice
Re: How do I get Access to print GIF (or HTMLImage) data

There's a function from Daniel Pineault (Devhut) to rotate an image.

' Procedure : WIA_RotateImage
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Rotate an image by a designated number of degrees using WIA


Good luck.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by jdraw; 06-22-2018 at 06:28 AM.
jdraw is offline   Reply With Quote
The Following User Says Thank You to jdraw For This Useful Post:
peskywinnets (06-22-2018)
Old 06-22-2018, 07:27 AM   #12
jleach
Newly Registered User
 
jleach's Avatar
 
Join Date: Jan 2012
Location: New York, NY
Posts: 298
Thanks: 16
Thanked 68 Times in 68 Posts
jleach will become famous soon enough
Re: How do I get Access to print GIF (or HTMLImage) data

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,
__________________
- Jack D. Leach

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Microsoft MVP 2012-2016
jleach is offline   Reply With Quote
Old 06-22-2018, 11:28 AM   #13
peskywinnets
Newly Registered User
 
Join Date: Feb 2014
Location: London, UK
Posts: 492
Thanks: 259
Thanked 4 Times in 4 Posts
peskywinnets is on a distinguished road
Re: How do I get Access to print GIF (or HTMLImage) data

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 is offline   Reply With Quote
Old 06-22-2018, 11:49 AM   #14
jleach
Newly Registered User
 
jleach's Avatar
 
Join Date: Jan 2012
Location: New York, NY
Posts: 298
Thanks: 16
Thanked 68 Times in 68 Posts
jleach will become famous soon enough
Re: How do I get Access to print GIF (or HTMLImage) data

A search for "WIA Crop Image" seems promising... for example, post #5 in this thread: http://www.vbforums.com/showthread.p...and-save-image
__________________
- Jack D. Leach

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Microsoft MVP 2012-2016
jleach is offline   Reply With Quote
The Following User Says Thank You to jleach For This Useful Post:
peskywinnets (06-22-2018)
Old 06-22-2018, 12:37 PM   #15
peskywinnets
Newly Registered User
 
Join Date: Feb 2014
Location: London, UK
Posts: 492
Thanks: 259
Thanked 4 Times in 4 Posts
peskywinnets is on a distinguished road
Re: How do I get Access to print GIF (or HTMLImage) data

Quote:
Originally Posted by jleach View Post
A search for "WIA Crop Image" seems promising... for example, post #5 in this thread: http://www.vbforums.com/showthread.p...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 ;-)

peskywinnets is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to automatically check data every 10 seconds and print if any data is there dzirkelb Modules & VBA 12 08-01-2016 05:46 AM
Access button to print report instead of opening it in print preview vvangogh Modules & VBA 2 07-01-2011 10:45 AM
Print Report from Data Access Page ze_colmeia Reports 0 11-20-2006 09:46 AM
Print a report directly from a data access page. selvsagt Reports 0 06-29-2006 04:15 AM
Need to print all subreports, must print NONE if there is no data Laftrip Reports 8 04-27-2004 03:55 AM




All times are GMT -8. The time now is 05:36 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World