Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Aug 06, 2024 8:55 am

"I use VSCode to execute the following code normally, but when I use pyinstaller --onefile --windowed pdf_excel.py to generate an executable file, an error message appears: 'NoneType' object has no attribute 'PdfDocument_Create'. How should I troubleshoot this issue?"

import tkinter as tk
from tkinter import filedialog, messagebox
from spire.pdf.common import *
from spire.pdf import *

def select_pdf_file():
file_path = filedialog.askopenfilename(filetypes=[("PDF files", "*.pdf")])
if file_path:
pdf_path.set(file_path)

def select_save_location():
save_path = filedialog.asksaveasfilename(defaultextension=".xlsx",
filetypes=[("Excel files", "*.xlsx")])
if save_path:
excel_path.set(save_path)

def convert_pdf_to_excel():
try:
pdf_file = pdf_path.get()
excel_file = excel_path.get()
if not pdf_file or not excel_file:
raise ValueError("Please select both PDF file and save location.")

# 創建PDFDocument對象
pdf = PdfDocument()

# 加載PDF文件
pdf.LoadFromFile(pdf_file)

# 創建XlsxLineLayoutOptions對象來指定轉換選項
convertOptions = XlsxLineLayoutOptions(True, True, True, True, False)

# 設置轉換選項
pdf.ConvertOptions.SetPdfToXlsxOptions(convertOptions)

# 將PDF文件保存為EXCEL XLSX格式
pdf.SaveToFile(excel_file, FileFormat.XLSX)
pdf.Close()

messagebox.showinfo("完成!", "PDF檔案已轉為EXCEL!!")
except Exception as e:
messagebox.showerror("Error", str(e))

# 創建主窗口
root = tk.Tk()
root.title("PDF to Excel Converter")

# PDF文件路徑
pdf_path = tk.StringVar()
tk.Label(root, text="選取 PDF 檔案:").grid(row=0, column=0, padx=10, pady=10)
tk.Entry(root, textvariable=pdf_path, width=50).grid(row=0, column=1, padx=10, pady=10)
tk.Button(root, text="瀏覽...", command=select_pdf_file).grid(row=0, column=2, padx=10, pady=10)

# Excel文件保存路徑
excel_path = tk.StringVar()
tk.Label(root, text="Excel 檔案儲存位置:").grid(row=1, column=0, padx=10, pady=10)
tk.Entry(root, textvariable=excel_path, width=50).grid(row=1, column=1, padx=10, pady=10)
tk.Button(root, text="瀏覽...", command=select_save_location).grid(row=1, column=2, padx=10, pady=10)

# 轉換按鈕
tk.Button(root, text="PDF To EXCEL", command=convert_pdf_to_excel).grid(row=2, column=0, columnspan=3, pady=20)

# 運行主循環
root.mainloop()

leotseng0813
 
Posts: 2
Joined: Tue Aug 06, 2024 8:48 am

Tue Aug 06, 2024 10:06 am

Hi,

Thank you for your message.
Please refer to the following command to specify the dll for packaging. Please modify "F:\xxx" to your own Spire.Doc.Base.dll and libSkiaSharp.dll path, and do not modify the ./spire/doc/lib after the colon (:).

pyinstaller --add-binary F:\TestCase\Spire.Doc.Base.dll:./spire/doc/lib --add-binary F:\TestCase\libSkiaSharp.dll:./spire/doc/lib Bug_10314_win.py

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 409
Joined: Mon Nov 07, 2022 8:10 am

Wed Aug 07, 2024 2:16 am

Doris.Liu wrote:Hi,

Thank you for your message.
Please refer to the following command to specify the dll for packaging. Please modify "F:\xxx" to your own Spire.Doc.Base.dll and libSkiaSharp.dll path, and do not modify the ./spire/doc/lib after the colon (:).

pyinstaller --add-binary F:\TestCase\Spire.Doc.Base.dll:./spire/doc/lib --add-binary F:\TestCase\libSkiaSharp.dll:./spire/doc/lib Bug_10314_win.py

Sincerely,
Doris
E-iceblue support team



Thank you for your reply.

Refer to the above solution for processing, but the location of the relevant dll cannot be found... Is there another dll file that can be downloaded?

leotseng0813
 
Posts: 2
Joined: Tue Aug 06, 2024 8:48 am

Wed Aug 07, 2024 8:07 am

Hi,

Thanks for your feedback.
Are you saying that you cannot find the path to the DLLs in your environment? If so, please switch to your Python installation directory and look for the two DLLs in the "\python\Lib\site-packages\spire\pdf\lib" directory. If you encounter any further issues, please feel free to provide feedback at any time.

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 409
Joined: Mon Nov 07, 2022 8:10 am

Return to Spire.PDF