Skip to main content
Level 2
March 8, 2024
解決済み

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

  • March 8, 2024
  • 2 の返信
  • 1159 ビュー

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

 

 

このトピックへの返信は締め切られました。
ベストアンサー EstebanBustamante

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/Asset.html

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/dam/api/Rendition.html#getStream--

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

2 の返信

EstebanBustamante
Adobe Champion and Community Advisor
Adobe Champion and Community Advisor
March 8, 2024

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/Asset.html

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/dam/api/Rendition.html#getStream--

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
Dear_AT作成者
Level 2
March 22, 2024

Thank You so much , it's working.