Skip to main content
Solved

download PDF from an API in a button

  • Jun 6, 2023 10:08 AM UTC
  • 4 replies
  • 299 views
  • Translate All

abdallaahmed61
Varsity III
Forum|alt.badge.img+1

I have an API that returns a PDF file in the content 

is there a way that i can make a button that consumes this api and return the file in the browser to be downloaded ?

the PDF file is big so i will need to await it

Best answer by abdallaahmed61

i solved the problem by using Task.Run and Task.Wait
and used the 
throw new PXRedirectToFileException(new FileInfo("downloaded.pdf", null, memoryStream.ToArray()), true);
that zfebert56 mentioned

View original

4 replies

Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+4

If you downloaded the file into a MemoryStream, you can use this code:

throw new PXRedirectToFileException(new FileInfo("downloaded.pdf", null, memoryStream.ToArray()), true);

 

Translate

abdallaahmed61
Varsity III
Forum|alt.badge.img+1

If you downloaded the file into a MemoryStream, you can use this code:

throw new PXRedirectToFileException(new FileInfo("downloaded.pdf", null, memoryStream.ToArray()), true);

 

this may solve the second problem 
but i still need to fix the first problem which is, i cant make the button async to wait the api call.

Translate

abdallaahmed61
Varsity III
Forum|alt.badge.img+1
  • Author
  • Varsity III
  • Answer
  • Jun 7, 2023 10:05 AM UTC

i solved the problem by using Task.Run and Task.Wait
and used the 
throw new PXRedirectToFileException(new FileInfo("downloaded.pdf", null, memoryStream.ToArray()), true);
that zfebert56 mentioned

Translate

Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • Jun 7, 2023 4:46 PM UTC

Thank you for sharing your solution with the community @abdallaahmed61 !

Translate