Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
GELÖST

Want to read the PDF file from the dam folder and convert the pdf data into byte array

Avatar

Level 2

Hi ,

I am able to get the PDF file path as /content/dam/folder1/folder2/pdf.pdf, not I want to read the pdf data and convert it into the byteArray. 

I am not able to read the PDF file from DAM asset as we read it simple from local system. kindly revert.

 

 

Thank You

 

 

Themen

Anhand von Themen werden Community-Inhalte kategorisiert und Sie können so relevanten Inhalt besser finden.

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Community Advisor and Adobe Champion

Hi, 

You could follow the next steps:

- Get the asset rendition

- From the rendition, you get the InputStream

- Then you convert your InputStream to ByteArray

 

Something like this:

Resource rr = resourceResolver.getResource(pathToYourAsset);
Asset asset = rr.adaptTo(Asset.class);
Rendition originalRendition = asset.getOriginal();
InputStream is = originalRendition.getStream();
byte[] bytes = IOUtils.toByteArray(is);

 

Please check these links for more details:

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/dam/api/As...

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/dam/api/Re...

https://stackoverflow.com/questions/1264709/convert-inputstream-to-byte-array-in-java

https://www.baeldung.com/convert-input-stream-to-array-of-bytes 

 

Hope this helps



Esteban Bustamante

Lösung in ursprünglichem Beitrag anzeigen

2 Antworten

Avatar

Korrekte Antwort von
Community Advisor and Adobe Champion

Hi, 

You could follow the next steps:

- Get the asset rendition

- From the rendition, you get the InputStream

- Then you convert your InputStream to ByteArray

 

Something like this:

Resource rr = resourceResolver.getResource(pathToYourAsset);
Asset asset = rr.adaptTo(Asset.class);
Rendition originalRendition = asset.getOriginal();
InputStream is = originalRendition.getStream();
byte[] bytes = IOUtils.toByteArray(is);

 

Please check these links for more details:

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/dam/api/As...

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/dam/api/Re...

https://stackoverflow.com/questions/1264709/convert-inputstream-to-byte-array-in-java

https://www.baeldung.com/convert-input-stream-to-array-of-bytes 

 

Hope this helps



Esteban Bustamante

Avatar

Level 2

Thank You so much , it's working.