Jump to content

Decoding PDF from hex


This topic is 2278 days old. Please don't post here. Open a new topic instead.

Recommended Posts

 A post on the FileMaker community posed a question about getting back to a PDF file from what had been stored in an SQL table after a sync with MirrorSync from FileMaker

original question here..https://community.filemaker.com/thread/155073

The saved data is a hex string in this case... so at the risk of giving away the keys to a magic kingdom, the answer is quite easy.

// PDFfromHex ( fm_hex )
// 16_04_02 JR
// v1.0
// converted HEX back to a pdf file
// requires Apache Commons jar

import org.apache.commons.codec.binary.Hex

try{
	decoded = Hex.decodeHex(fm_hex.toCharArray())
	PDFfile = new File('/Path/to/my/saved.pdf')
	fos = new FileOutputStream(PDFfile)
	fos.write(decoded)
	fos.close()
} catch (e) {
	return e
}
return true

 

Link to comment
Share on other sites

Great contribution, as always!

This should work for any binary hex, right? Including the HEX-encoded SVG objects in FileMaker layout object clipboard data?

I assume you have a function to encode in binary hex as well? If so, would you mind posting it? If you don't have it handy, I should be able to put it together myself. My idea would be to be able to programmatically create layout objects using SVG icons, without having to use the painfully manual interface FileMaker gives us for adding new SVG icons.

I'm not quite sure yet if this can be actually useful or simply plain fun - but let me think about that.

 

Link to comment
Share on other sites

David

It does indeed work. Just change the file to save.svg
Copy a single button bar segment and look for 
BE_XPath ( $clipboardContent ; "/fmxmlsnippet/Layout/Object/ButtonBarObj/Object/ButtonObj/Stream[3]/HexData" ; "" ; True )

My other method to get the svg it is more FileMaker less Groovy... take the hex, loop over it 2 bits at a time and convert to numbers -  it will give you a series of ascii codes which then need turning into characters with Char()

And as you can tell, I have already done it, and it works... was part of my presentation at the recent Pause in Cleveland. And the automatic adding button bar objects (with some Applescript)

 

Clue to going the other way:
The opposite function is Hex.encodeHex() and is best fed with a byte array.

 

Link to comment
Share on other sites

OK, great ideas - glad you already did it so I don't have to! I couldn't go to Pause unfortunately since I had something else planned at that time. Hadn't checked the schedule lately - I see now that you did something on icons - too bad I missed that! Are you coming to dotFMP this year? 

An "SVG icon injector" for FileMaker could be handy when you want to add a whole set of icons - did you already do one?

Link to comment
Share on other sites

This topic is 2278 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.