0

I used QWebEngineView in pyqt5. trying to use an HTML file to export a PDF in QWebEnginView. when I run the file in VS Code the pdf exports and works fine but when I convert this python file to exe with this command in cmd

pyinstaller --onefile mycode.py

and run the mycode.exe I get this error: Couldn't mmap icu data file

Here is my whole code in pyqt5:

import sys
from PyQt5.QtWidgets import (QHBoxLayout, QPushButton, QWidget, 
QApplication, QVBoxLayout, QMessageBox)
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView


class Example(QWidget):

  def __init__(self):
    super().__init__()

    self.initUI()

  def initUI(self):

    vbox = QVBoxLayout(self)
    hbox = QHBoxLayout()

    self.webEngineView = QWebEngineView()
    self.loadPage()

    expBtn = QPushButton('Export', self)
    expBtn.clicked.connect(self.onClicked)

    hbox.addWidget(expBtn)

    vbox.addWidget(self.webEngineView)
    vbox.addLayout(hbox)
    self.setLayout(vbox)

    self.setGeometry(300, 300, 350, 250)
    self.setWindowTitle('QWebEngineView')
    self.show()

  def onClicked(self):

    self.webEngineView.page().printToPdf('myfile.pdf')
    QMessageBox.information(self, 'info', 'page exported')

  def loadPage(self):

    with open('html.html', encoding="utf8") as f:

        html = f.read()
        self.webEngineView.setHtml(html)

def main():

   app = QApplication(sys.argv)
   ex = Example()
   sys.exit(app.exec_())


if __name__ == '__main__':
   main()

and this is my HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  
    <style>
        th, td {
          border-bottom:1px solid black;
          border-right:1px solid black;
          text-align : center;
          padding : 3px;
        }
        * {
        direction: rtl;
        }     
        
        .img{
            border-bottom:1px solid black;
          border-right:1px solid black;
          text-align : center;
          
        }
        .center {
            
            margin-left: auto;
            margin-right: auto;
            width:95%;
            border:1px solid black;
            
            }
        </style>
        
    </head>
<body style="font-family: Arial">
    
      <div style="border: 4px double black;">
        <h3 style="text-align:center; font-size: 30px;">فاکتور خرید</h3>
        <h3 style="text-align:center ;font-size: 30px;">شرکت برنا نوآوران پویا</h3>
        <img src="icon.jpg" alt="Paris" style="width: 5%;">
    </div>
    <div style="border-bottom: 1px dashed black; border-left: 4px double black; border-right: 4px double black;border-top: 1px double black;">

        <p style="text-align:right; font-size: 20px; padding-right: 30px;"> تاریخ : </p>
        <p style="text-align:right; font-size: 20px; padding-right: 30px;">زمان :</p>
    </div>
    <div style="border-bottom: 4px double black; border-left: 4px double black; border-right: 4px double black;border-top: 1px dashed black;">
        <br></br>
        
        <table class = "center">
            <tr >
              <th>شماره بارنامه</th>
              <th>تاریخ ورود محموله</th>
              <th>نرخ دلار</th>
              <th>نرخ پوند</th>
              <th>نرخ یورو</th>
              <th>وزن کل</th>
              <th>هزینه گمرک</th>
              <th>هزینه حمل</th>
              <th>هزینه خرید</th>
              <th>هزینه کارمزد</th>
              <th>مجموع هزینه کل</th>
              <th>تعداد کل کالا</th>
              
            </tr>
            <tr>
              <td>3333</td>
              <td>345</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              
              
            </tr>
           
          </table>
          <br></br>
        <br></br>
        
          <table class = "center">
            <tr >
              <th>اسم کالا</th>
              <th>تعداد تکی</th>
              <th>قمیت خرید نهایی</th>
              <th>وزن نهایی به گرم</th>
              <th>قیمت کل</th>
              
            </tr>
            <tr>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td> 
            </tr>

            <tr>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td> 
              </tr>

              <tr>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td> 
              </tr>
              <tr>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td> 
              </tr>
           
          </table>
          
          <br></br>


        <p style="border-bottom: 1px solid black;border-right: 1px solid black; border-radius: 2px; text-align:right; font-size: 20px; margin-right:30px; width: 50%; height: 40px;">
          <span style="display: inline-block; margin-right: 5px; margin-bottom: 7px; margin-top: 7px;">مجموع قیمت کل :</span>
        <span style="display: inline-block; margin-right: 3px; margin-bottom: 7px; margin-top: 7px;">34343</span>
        </p>
        
          <p style="border-bottom: 1px dashed"></p>
          <br></br>
          <table class = "center">
            <tr >
              <th>فاکتور خرید</th>
              <th>بارنامه</th>
              
              
              
            </tr>
            
              <td class = "img">
                <img src="run.jpg" style="width: 90%;">
              </td>
              <td class = "img">
                <img src="run.jpg" style="width: 90%;">
              </td>
            </tr>

          </table>

          <br></br>
        <br></br>
        
          <table class = "center">
            <tr >
              <th>رسید خرید ۱</th>
              <th>رسید خرید ۲</th>             
              
            </tr>
            
              <td class = "img">
                <img src="run.jpg" style="width: 90%;">
              </td>
              <td class = "img">
                <img src="run.jpg" style="width: 90%;">
              </td>
            </tr>

          </table>

          <br></br>
        <br></br>
        <p style="text-align:right; font-size: 20px; padding-right: 30px;">سرمایه گذاران :</p>
        <br></br>
        <br></br>
        <br></br>
        <p style="text-align:right; font-size: 20px; padding-right: 30px;"></p>

        <p style="text-align:right; font-size: 20px; padding-right: 30px;">توضیحات تکمیلی :</p>
        <br></br>
        <br></br>
        <br></br>
        <p style="text-align:right; font-size: 20px; padding-right: 30px;"></p>

        <p style="text-align:right; font-size: 20px; padding-right: 30px;">نام کاربر :</p>
        <br></br>
        <br></br>
        <br></br>
        <p style="text-align:right; font-size: 20px; padding-right: 30px;"></p>

        


    </div>
</body>

</html>

Does anyone know how can I fix this error when I convert the python file to exe?

sana sm
  • 1
  • 1

1 Answers1

0

I found a solution on a Chinese website. I had to put some files in myapp.exe. here is the link: Visit https://cxyzjd.com/article/meimeieee/115024971

sana sm
  • 1
  • 1