Export an image in Go as a []byte

Product:
PDFTron Go SDK
Product Version:
v1.1.0

Export an image in Go as a []byte

I have built an image extractor based on the sample code in the GO SDK samples and it output the images to file but I need them as []byte so that I can upload them to a Google Storage Bucket. Following some other similar questions in other languages, I have the following code but I am stuck trying to get that last step to get the data in a []byte.

                    image = pdftron.NewImage(obj)

		mf := pdftron.NewMemoryFilter(0, false)
		fw := pdftron.NewFilterWriter(mf)
		image.Export(fw)
		mf.SetAsInputFilter()
		fr := pdftron.NewFilterReader(mf)

The answer to a similar question in the forum said to use a FilterReader to output it in the format needed but I can’t find any function of Filter Reader that give me the Byte data.

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi Bill,

You don’t need the FilterReader, just need the MemoryFilter.

You can write the filter to memory using the following two API:
https://www.pdftron.com/api/PDFTronSDK/cpp/classpdftron_1_1_filters_1_1_memory_filter.html#a4dd86549003e02786ffdf1acd7bc80c4
https://www.pdftron.com/api/PDFTronSDK/cpp/classpdftron_1_1_filters_1_1_filter.html#a388deb25cfe67701902e2d284a82b099

Using the above gives you access to the in memory data.

image.Export(fw)

Note that Export returns one of the three file types. To know the filetype you got, check the return value. You may also use the ExportAs methods to specifically export as a PNG or TIF.
https://www.pdftron.com/api/PDFTronSDK/cpp/classpdftron_1_1_p_d_f_1_1_image.html#aed5d5dba1bd277e6ac98125100ab6e14