# Email a file, i.e. generate a PDF then grab it from the PDF Express viewer

**URL:** <https://pdfjs.community/t/email-a-file-i-e-generate-a-pdf-then-grab-it-from-the-pdf-express-viewer/2152>\
**Category:** Technical Support\
**Created:** [November 9, 2022, 11:54pm UTC](https://pdfjs.community/t/email-a-file-i-e-generate-a-pdf-then-grab-it-from-the-pdf-express-viewer/2152 "2022-11-09T23:54:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![momboman4](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/momboman4/32/1059_2.png) [@momboman4](https://pdfjs.community/u/momboman4)\
**Post date:** [November 9, 2022, 11:54pm UTC](https://pdfjs.community/t/email-a-file-i-e-generate-a-pdf-then-grab-it-from-the-pdf-express-viewer/2152/1 "2022-11-09T23:54:34Z")

</div>

**Which product are you using?**

**PDF.js Express Version**

**Detailed description of issue**  
Hi,  
I was trying to figure out how I could generate a pdf then retrieve it from the viewer and send it to a server to be emailed. Bonus: I’m doing this in Blazor so essentially I’m restricted as to what I can do.

**Expected behaviour**  
\_\_\_\_\_\_\_\_\_^^^^^^^^^ Nice Canadian Spelling!!!  
Generate a report and send it in an email.

**Does your issue happen with every document, or just one?**  
Every one.

**Link to document**  
NA

**Code snippet**

> // I’m calling this javascript from a Blazor app to get the displayed PDF. It doesn’t  
> // return the PDF but I think it’s close  
> getPDF: (elementWanted) =\> {  
> const viewerElement = document.getElementById(elementWanted);  
> instance = getInstance(viewerElement);  
> const { documentViewer } = instance.Core;
> 
> ```
> // must wait for the document to be loaded before you can save the file
> documentViewer.addEventListener('documentLoaded', async () => {
> const documentStream = documentViewer.getDocument().getFileData({});
> const documentBlob = new Blob([documentStream], { type: 'data:application/pdf' });
> 
> return(documentBlob);
> })
> }
> 
> ```

Thanks

Craig

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [November 10, 2022, 3:38pm UTC](https://pdfjs.community/t/email-a-file-i-e-generate-a-pdf-then-grab-it-from-the-pdf-express-viewer/2152/3 "2022-11-10T15:38:08Z")

</div>

Hi there,

Thank you for contacting pdf.js express forums,

It looks like you followed this guide to get the blob created from the document:

> **[Saving a document in PDF.js Express | Documentation](https://pdfjs.express/documentation/basic-operations/save-document/blob)**

From there you would need to save that blob to the server.  
I am not an expert on this topic but you will need to setup a SMTP from your end and then send off the blob as an attachment?

> <https://stackoverflow.com/questions/60111792/blazor-c-send-email>

You can also check if that blob is returning the pdf you expect by using loadDocument on the blob:

> **[Open PDF.js Express from Blob | Documentation](https://pdfjs.express/documentation/basic-operations/open-document/blob)**

Best regards,  
Kevin Kim

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)
