# PDFViewer clear active PDF

**URL:** <https://forum.inductiveautomation.com/t/pdfviewer-clear-active-pdf/36489>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [July 8, 2020, 3:09pm UTC](https://forum.inductiveautomation.com/t/pdfviewer-clear-active-pdf/36489 "2020-07-08T15:09:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [July 8, 2020, 3:09pm UTC](https://forum.inductiveautomation.com/t/pdfviewer-clear-active-pdf/36489/1 "2020-07-08T15:09:44Z")

</div>

I’m using the Vision -\> Reporting -\> PDF Viewer to display PDF’s loaded from a SQL Database as bytes.

I can load a PDF without issue, but I’m trying to figure out how to actually then clear out the loaded PDF at runtime.

I’ve tried this:

```auto
emptyPDF = system.file.getTempFile('pdf')
pdfByes = system.file.readFileAsBytes(emptyPDF)
try:
	event.source.parent.getComponent('pdfViewer').loadPDFBytes(pdfByes,'')
except:
	#This will create an error. That's ok.
	pass

```

However I get an ICEpdf error popup that I can’t seem to avoid. I’m fine with it throwing an error, I just don’t want to see it in this instance.

Is there any good way to do clear out the loaded PDF?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 8, 2020, 3:14pm UTC](https://forum.inductiveautomation.com/t/pdfviewer-clear-active-pdf/36489/2 "2020-07-08T15:14:02Z")

</div>

Have you tried using an empty list instead of an empty string?

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [July 8, 2020, 3:24pm UTC](https://forum.inductiveautomation.com/t/pdfviewer-clear-active-pdf/36489/3 "2020-07-08T15:24:45Z")

</div>

Same error. This is what it displays

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/4/b446aaaf81d794bafc03eee2191bd6d49834adcb.png)

Which I get because it’s an empty file. I just don’t want to see the exception when I do this.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 8, 2020, 3:29pm UTC](https://forum.inductiveautomation.com/t/pdfviewer-clear-active-pdf/36489/4 "2020-07-08T15:29:25Z")

</div>

`event.source.parent.controller.closeDocument()`, maybe?

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [July 8, 2020, 3:29pm UTC](https://forum.inductiveautomation.com/t/pdfviewer-clear-active-pdf/36489/5 "2020-07-08T15:29:46Z")

</div>

event.source.parent.getComponent(‘PDF Viewer’).getController().closeDocument()

@paul-griffith was correct first.

His suggestion also works:  
event.source.parent.getComponent(‘PDF Viewer’).controller.closeDocument()

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [July 8, 2020, 3:31pm UTC](https://forum.inductiveautomation.com/t/pdfviewer-clear-active-pdf/36489/6 "2020-07-08T15:31:50Z")

</div>

> [@code\_skin](#):
>
> .getController().closeDocument()

This worked like a charm.

Thanks!

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [April 12, 2024, 8:08pm UTC](https://forum.inductiveautomation.com/t/pdfviewer-clear-active-pdf/36489/7 "2024-04-12T20:08:41Z")

</div>

Was looking for how to do this, and stumbled across this. It would be nice if this was added to the docs site, (plus if there's any other extension functions for controlling the view, that would be helpful as well)
