Handling adobeDCView.previewFile Exception

Community Beginner ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Hi, 

My embed api is working fine. Now I want to know if there is any way to handle exeption occure in adobeDCView.previewFile() function, like 404 etc.

I donot find anything in documents. If I give wrong pdf url this function print code: "PREVIEW_RENDERING_FAILED" , but I do not know how to handle it.

Views

100

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

I assume you are using location.url with a path to your PDF. My suggestion is to fetch the PDF first so you can handle the exceptions yourself and then when you know you have the file, pass the PDF content as a Promise that resolves to a ByteArray. I have a working example at this CodePen. The example also shows how to delay the creation of the embedded view until you have the PDF and then to delay displaying it until the PDF is rendered.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Thank you for reply. Is there any way to handle exception when we pass location.url. SDK is printing PREVIEW_RENDERING_FAILED, so there should be any callback or anything else to detect if there is any error in rendering, like APP_RENDERING_DONE.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

You can use the PREVIEW_RENDERING_FAILED event to detect a failure to render (as it implies) but you have no idea as to why it failed. The file may not have been located or it may just have been bad or it might have not been a PDF at all.

While not documented as such, I consider it a best practice to fetch the PDF first, check the mime-type of the fetched file, and if it is a PDF, load the viewer. That way you are in full control of the error processing.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 09, 2021 Mar 09, 2021

Copy link to clipboard

Copied

I have tried to add PREVIEW_RENDERING_FAILED  event but it looks never fire.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 10, 2021 Mar 10, 2021

Copy link to clipboard

Copied

LATEST

As I stated, I consider it a best practice to fetch the PDF first. That's how to work around these issues.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines