Export an image in Go as a []byte

Product Version:

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)
		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:


Hi Bill,

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

You can write the filter to memory using the following two API:

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


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.