diff --git a/src/Html2Pdf.php b/src/Html2Pdf.php
index <HASH>..<HASH> 100755
--- a/src/Html2Pdf.php
+++ b/src/Html2Pdf.php
@@ -523,9 +523,6 @@ class Html2Pdf
      */
     public function output($name = 'document.pdf', $dest = 'I')
     {
-        // close the pdf and clean up
-        $this->clean();
-
         // if on debug mode
         if (!is_null($this->debug)) {
             $this->debug->stop();
@@ -556,7 +553,12 @@ class Html2Pdf
         }
 
         // call the output of TCPDF
-        return $this->pdf->Output($name, $dest);
+        $output = $this->pdf->Output($name, $dest);
+        
+        // close the pdf and clean up
+        $this->clean();
+
+        return $output;
     }
 
     /**
Closes #<I>

Clean locale before PDF generation