{"id":53735,"date":"2025-02-16T09:32:06","date_gmt":"2025-02-16T01:32:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53735\/"},"modified":"2025-02-16T09:32:06","modified_gmt":"2025-02-16T01:32:06","slug":"3%e4%b8%aa%e6%9c%80%e6%9c%89%e6%95%88%e7%9a%84%e8%a1%a8%e6%a0%bc%e6%8f%90%e5%8f%96sdk","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53735\/","title":{"rendered":"3\u4e2a\u6700\u6709\u6548\u7684\u8868\u683c\u63d0\u53d6SDK"},"content":{"rendered":"<p>\u672c\u6587\u6df1\u5165\u63a2\u8ba8\u4e86\u4ece\u8868\u683c\u4e2d\u63d0\u53d6\u6570\u636e\u7684\u5fae\u5999\u4e16\u754c\uff0c\u8fd9\u9879\u4efb\u52a1\u6bd4\u63d0\u53d6\u7eaf\u6587\u672c\u8981\u590d\u6742\u5f97\u591a\u3002\u8fd9\u79cd\u590d\u6742\u6027\u6e90\u4e8e\u8868\u683c\u4e2d\u7ecf\u5e38\u51fa\u73b0\u7684\u975e\u5e38\u89c4\u7ed3\u6784\uff0c\u5c24\u5176\u662f\u5728\u7814\u7a76\u8bba\u6587\u4e2d\u3002\u4e0e\u6807\u51c6\u8868\u683c\u4e0d\u540c\uff0c\u8fd9\u4e9b\u8868\u683c\u53ef\u80fd\u6ca1\u6709\u6e05\u6670\u7684\u754c\u5b9a\uff0c\u6216\u8005\u5217\u6807\u9898\u548c\u5185\u5bb9\u4e4b\u95f4\u53ef\u80fd\u5b58\u5728\u9519\u4f4d\u3002\u8fd9\u79cd\u534a\u7ed3\u6784\u5316\u8868\u683c\u5bf9\u4f20\u7edf\u7684\u63d0\u53d6\u65b9\u6cd5\u63d0\u51fa\u4e86\u6311\u6218\uff0c\u9700\u8981\u66f4\u9ad8\u7ea7\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u672c\u6587\u91cd\u70b9\u4ecb\u7ecd\u65e8\u5728\u6709\u6548\u5e94\u5bf9\u8fd9\u4e9b\u6311\u6218\u7684\u514d\u8d39\u5f00\u6e90\u5de5\u5177\u548c\u6280\u672f\u3002\u5b83\u63a2\u8ba8\u4e86\u5904\u7406\u975e\u6807\u51c6\u8868\u683c\u683c\u5f0f\u7684\u5404\u79cd\u7b56\u7565\uff0c\u63d0\u4f9b\u4e86\u6709\u6548\u63d0\u53d6\u6570\u636e\u7684\u89c1\u89e3\uff0c\u5373\u4f7f\u662f\u4ece\u683c\u5f0f\u6700\u4e0d\u89c4\u5219\u7684\u8868\u683c\u4e2d\u4e5f\u662f\u5982\u6b64\u3002\u91cd\u70b9\u662f\u63d0\u4f9b\u5b9e\u7528\u3001\u53ef\u8bbf\u95ee\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u8fd9\u4e9b\u89e3\u51b3\u65b9\u6848\u53ef\u4ee5\u5904\u7406\u8868\u683c\u6570\u636e\u63d0\u53d6\u7684\u590d\u6742\u6027\uff0c\u800c\u65e0\u9700\u627f\u62c5\u9ad8\u6602\u7684\u6210\u672c\u3002\u901a\u8fc7\u8fd9\u79cd\u63a2\u7d22\uff0c\u672c\u6587\u65e8\u5728\u8ba9\u8bfb\u8005\u638c\u63e1\u5728\u4f20\u7edf\u65b9\u6cd5\u65e0\u6cd5\u6ee1\u8db3\u9700\u6c42\u7684\u4e16\u754c\u4e2d\u5e94\u5bf9\u8868\u683c\u6570\u636e\u63d0\u53d6\u7684\u77e5\u8bc6\u3002<\/p>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u7814\u7a76\u7528\u4e8e\u8868\u683c\u6570\u636e\u63d0\u53d6\u7684\u5404\u79cd\u5de5\u5177\u548c\u6280\u672f\uff0c\u5e76\u5c06\u6307\u5bfc\u4f60\u5b8c\u6210\u6709\u6548\u5b9e\u65bd\u8fd9\u4e9b\u89e3\u51b3\u65b9\u6848\u6240\u9700\u7684 Python \u4ee3\u7801\u3002<\/p>\n<h2>1\u3001PDF \u5230\u56fe\u50cf\u8f6c\u6362\uff08\u7528\u4e8e OCR \u5de5\u5177\uff09<\/h2>\n<p>\u6211\u4eec\u63a2\u7d22\u4e00\u79cd\u57fa\u4e8e Python \u7684\u65b9\u6cd5\uff0c\u7528\u4e8e\u5c06 PDF \u6587\u6863\u8f6c\u6362\u4e3a\u56fe\u50cf\uff0c\u8fd9\u662f\u4f7f\u7528 OCR\uff08\u5149\u5b66\u5b57\u7b26\u8bc6\u522b\uff09\u5de5\u5177\u7684\u5173\u952e\u6b65\u9aa4\u3002\u6b64\u8fc7\u7a0b\u6d89\u53ca PyMuPDF \u5e93\uff08\u79f0\u4e3a fitz\uff09\u548c Python \u56fe\u50cf\u5e93 (PIL)\u3002\u63d0\u4f9b\u7684\u811a\u672c\u5c06\u6bcf\u4e2a PDF \u9875\u9762\u8f6c\u6362\u4e3a PNG \u56fe\u50cf\uff0c\u4f7f\u5176\u53ef\u4f9b OCR \u8f6f\u4ef6\u8bfb\u53d6\u3002\u8be5\u65b9\u6cd5\u4fdd\u7559 PDF \u7684\u539f\u59cb\u5e03\u5c40\u548c\u5185\u5bb9\uff0c\u786e\u4fdd\u51c6\u786e\u7684 OCR \u7ed3\u679c\u3002\u8fd9\u79cd\u9ad8\u6548\u7684\u6280\u672f\u5bf9\u4e8e\u4ece\u57fa\u4e8e\u56fe\u50cf\u7684\u6587\u6863\u4e2d\u63d0\u53d6\u6587\u672c\u6570\u636e\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p>\u8fd9\u662f\u4e0a\u8ff0\u4efb\u52a1\u7684\u793a\u4f8b Python \u811a\u672c\uff1a<\/p>\n<pre><code>import fitz  # PyMuPDF\nfrom PIL import Image\n\ndef pdf_to_png(pdf_path, output_folder):\n    pdf_document = fitz.open(pdf_path)\n\n    for page_number in range(pdf_document.page_count):\n        page = pdf_document.load_page(page_number)\n\n        pixmap = page.get_pixmap()\n\n        image = Image.frombytes(\"RGB\", [pixmap.width, pixmap.height], pixmap.samples)\n\n        image.save(f\"{output_folder}\/page_{page_number + 1}.png\")\n\n    pdf_document.close()\n\npdf_path = \"doc1.pdf\"\noutput_folder = \"doc1\"\n\npdf_to_png(pdf_path, output_folder)<\/code><\/pre>\n<h2>2\u3001Azure \u6587\u6863\u667a\u80fd\u5e03\u5c40\u6a21\u578b<\/h2>\n<p>\u6211\u4eec\u4e13\u6ce8\u4e8e\u5229\u7528 Azure \u7684\u529f\u80fd\u8fdb\u884c\u8868\u683c\u6570\u636e\u63d0\u53d6\u3002\u867d\u7136 Azure \u5141\u8bb8\u76f4\u63a5\u8f93\u5165 PDF\uff0c\u4f46\u514d\u8d39\u7248\u672c\u9650\u5236\u6bcf\u4e2a\u4e8b\u52a1\u4e24\u9875\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u5efa\u8bae\u5c06 PDF \u8f6c\u6362\u4e3a\u56fe\u50cf\u3002\u6b64\u8fc7\u7a0b\u5fc5\u4e0d\u53ef\u5c11\u7684\u662f Azure API \u5bc6\u94a5\u548c Endpoint \u5bc6\u94a5\uff1b\u6709\u5173\u83b7\u53d6\u8fd9\u4e9b\u5185\u5bb9\u7684\u8be6\u7ec6\u8bf4\u660e\uff0c\u8bf7\u53c2\u9605 \u3002\u6211\u4eec\u7684\u65b9\u6cd5\u91c7\u7528\u4e86 Azure \u5e03\u5c40\u6a21\u578b\u548c Python SDK\uff0c\u4e3a\u5206\u6790\u6587\u6863\u7ed3\u6784\u548c\u9ad8\u6548\u63d0\u53d6\u8868\u683c\u6570\u636e\uff08\u5373\u4f7f\u662f\u4ece\u590d\u6742\u7684\u5e03\u5c40\u4e2d\uff09\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>\u8fd9\u662f\u4e0a\u8ff0\u4efb\u52a1\u7684\u793a\u4f8b Python \u811a\u672c\uff1a<\/p>\n<pre><code>import os\nfrom azure.ai.formrecognizer import DocumentAnalysisClient\nfrom azure.core.credentials import AzureKeyCredential\nimport pandas as pd\n\n# Azure API and Endpoint keys\nAPI_KEY = \"your_api_key\"\nENDPOINT = \"your_endpoint_url\"\n\n# Assigning your Azure key and endpoint to variables\nkey = API_KEY\nendpoint = ENDPOINT\n\n# Function to analyze layout of the document\ndef analyze_layout(local_file_path):\n    # Initializing the Document Analysis Client with endpoint and key\n    document_analysis_client = DocumentAnalysisClient(\n        endpoint=endpoint, credential=AzureKeyCredential(key)\n    )\n\n    # Opening the file and analyzing the layout\n    with open(local_file_path, \"rb\") as f:\n        poller = document_analysis_client.begin_analyze_document(\n            \"prebuilt-layout\", document=f\n        )\n        result = poller.result()\n    return result\n\n# Function to extract table data from the result\ndef extract_table_data(result):\n    tables = []\n    for table in result.tables:\n        rows = []\n        for cell in table.cells:\n            while len(rows) &lt;= cell.row_index:\n                rows.append([])\n            rows[cell.row_index].append(cell.content)\n        tables.append(rows)\n    return tables\n\n# Convert the extracted tables into pandas dataframes\ndef tables_to_dataframes(tables):\n    dataframes = [pd.DataFrame(table) for table in tables]\n    return dataframes\n\n# Function to save the tables in CSV and Excel format\ndef save_tables(dataframes, base_filename):\n    for i, df in enumerate(dataframes):\n        csv_filename = f\"outputs\/{base_filename}_table_{i}.csv\"\n        xlsx_filename = f\"outputs\/{base_filename}_table_{i}.xlsx\"\n        df.to_csv(csv_filename, index=False)\n        df.to_excel(xlsx_filename, index=False)\n\n# Main execution block\nif __name__ == \"__main__\":\n    directory_path = \"inputs\" # Input directory\n\n    # Loop through each file in the directory\n    for filename in os.listdir(directory_path):\n        if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.pdf')):\n            file_path = os.path.join(directory_path, filename)\n            print(f\"Analyzing {filename}...\")\n            result = analyze_layout(file_path)\n\n            tables = extract_table_data(result)\n            dataframes = tables_to_dataframes(tables)\n            save_tables(dataframes, os.path.splitext(filename)[0])\n\n            print(f\"Completed analysis for {filename}\")<\/code><\/pre>\n<p>\u5728\u53ef\u7528\u7684\u8868\u683c\u63d0\u53d6\u5de5\u5177\u4e2d\uff0cAzure \u5e03\u5c40\u6a21\u578b\u901a\u5e38\u63d0\u4f9b\u6700\u51c6\u786e\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u8fd9\u662f\u4f7f\u7528 Azure document AI \u63d0\u53d6\u534a\u7ed3\u6784\u5316\u8868\u683c\u7684\u539f\u56fe\u548c\u7ed3\u679c\uff1a<\/p>\n<p> \u8868\u683c\u539f\u56fe \u63d0\u53d6\u7ed3\u679c <\/p>\n<p>\u5982\u4f60\u6240\u89c1\uff0c\u63d0\u53d6\u8fc7\u7a0b\u4e2d\u5b58\u5728\u4e00\u4e9b\u4e0d\u4e00\u81f4\u4e4b\u5904\u3002\u4f46\u662f\uff0c\u5927\u591a\u6570\u63d0\u53d6\u90fd\u662f\u51c6\u786e\u7684\uff0c\u4e0e\u5176\u4ed6\u65b9\u6cd5\u76f8\u6bd4\uff0c\u8fd9\u4e9b\u7ed3\u679c\u8fbe\u5230\u4e86\u53ef\u63a5\u53d7\u7684\u6c34\u5e73\u3002\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0cAzure Document AI \u53ef\u7528\u4e8e\u5e7f\u6cdb\u7684 OCR \u76f8\u5173\u4efb\u52a1\uff0c\u6211\u7a0d\u540e\u4f1a\u5199\u53e6\u4e00\u7bc7\u6587\u7ae0\uff0c\u4ecb\u7ecd\u4f7f\u7528\u53d1\u7968\u6a21\u578b\u548c\u81ea\u5b9a\u4e49\u6a21\u578b\u63d0\u53d6\u8d26\u5355\u548c\u53d1\u7968\u6570\u636e\u3002<\/p>\n<h2>3\u3001PaddleOCR<\/h2>\n<p>PaddleOCR \u662f\u4e00\u6b3e\u5b8c\u5168\u514d\u8d39\u7684\u5f00\u6e90\u5de5\u5177\u5305\uff0c\u5728\u8868\u683c\u6570\u636e\u63d0\u53d6\u65b9\u9762\u8131\u9896\u800c\u51fa\u3002\u5b83\u63d0\u4f9b\u4e86\u5e7f\u6cdb\u7684\u9884\u8bad\u7ec3\u6a21\u578b\uff0c\u4f7f\u5176\u9002\u7528\u4e8e\u82f1\u8bed\u548c\u4e2d\u6587\u8bed\u8a00\u63d0\u53d6\u3002\u867d\u7136\u5b83\u7684\u51c6\u786e\u6027\u4e00\u822c\u662f\u53ef\u4ee5\u63a5\u53d7\u7684\uff0c\u4f46\u5b83\u53ef\u80fd\u4e0d\u5982 Azure \u7684\u5de5\u5177\u90a3\u4e48\u7cbe\u786e\u3002\u5176\u529f\u80fd\u7684\u6838\u5fc3\u662f PP-Structure \u7ec4\u4ef6\uff0c\u8d1f\u8d23\u5e03\u5c40\u5206\u6790\u3001\u8868\u683c\u68c0\u6d4b\u548c\u5185\u5bb9\u63d0\u53d6\u3002\u8fd9\u4f7f\u5f97 PaddleOCR \u6210\u4e3a\u5404\u79cd\u57fa\u4e8e\u6587\u6863\u548c\u56fe\u50cf\u7684\u6587\u672c\u63d0\u53d6\u7684\u5b9e\u7528\u4e14\u6613\u4e8e\u8bbf\u95ee\u7684\u9009\u62e9\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u9700\u8981\u5177\u6709\u8bed\u8a00\u7075\u6d3b\u6027\u7684\u7ecf\u6d4e\u9ad8\u6548\u89e3\u51b3\u65b9\u6848\u7684\u7528\u6237\u3002<\/p>\n<p>\u8fd9\u662f\u4e0a\u8ff0\u4efb\u52a1\u7684\u793a\u4f8b Python \u811a\u672c\uff1a<\/p>\n<pre><code>import cv2\nimport pandas as pd\nfrom paddleocr import PPStructure\nfrom openpyxl import load_workbook, Workbook\nfrom openpyxl.drawing.image import Image as XLImage\n\n# Initialize PPStructure for table extraction with recovery and OCR results\ntable_engine = PPStructure(recovery=True, return_ocr_result_in_table=True)\n\n# Create and save an Excel workbook to store the results\noutput = '\/content\/output.xlsx'\nWorkbook().save(output)\nbook = load_workbook(output)\nwriter = pd.ExcelWriter(output, engine='openpyxl')\nwriter.book = book\n\n# Process images in a loop\nfor n in range(1, 5):\n    print('image', n)\n    img_path = f'\/content\/{n} (1).png'\n    img = cv2.imread(img_path)\n    result = table_engine(img)\n\n    # Create an image object for openpyxl\n    xlimg = XLImage(img_path)\n\n    i = 1\n    for line in result:\n        # Remove the 'img' key from the result\n        line.pop('img')\n        # Check if the line is a table\n        if line.get(\"type\") == \"table\":\n            # Extract HTML table and convert to DataFrame\n            html_table = line.get(\"res\").get(\"html\")\n            html_data = pd.read_html(html_table)\n            df = pd.DataFrame(html_data[0])\n\n            # Write DataFrame to Excel and add the image to the sheet\n            df.to_excel(writer, sheet_name=f\"image {n} table {i}\", index=1)\n            book[f\"image {n} table {i}\"].add_image(xlimg, 'A100')\n            i += 1\n\n# Save the Excel workbook\nwriter.save()<\/code><\/pre>\n<p>\u8fd9\u662f\u4f7f\u7528 PaddleOCR \u63d0\u53d6\u534a\u7ed3\u6784\u5316\u8868\u683c\u7684\u539f\u56fe\u548c\u7ed3\u679c\uff1a<\/p>\n<p> \u8868\u683c\u539f\u56fe \u8868\u683c\u63d0\u53d6\u7ed3\u679c <\/p>\n<p>\u5728\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u7ed3\u679c\u4e0d\u5982 Azure AI \u5e03\u5c40\u6a21\u578b\u51c6\u786e\u3002\u4f46\u6587\u672c\u63d0\u53d6\u548c\u8fb9\u754c\u6846\u63d0\u53d6\u5df2\u6b63\u786e\u5b8c\u6210\u3002<\/p>\n<h2>4\u3001PyMuPDF<\/h2>\n<p>PyMuPDF \u662f\u4e00\u6b3e\u514d\u8d39\u7684\u5f00\u6e90\u5de5\u5177\uff0c\u64c5\u957f\u4ece PDF \u4e2d\u7ed3\u6784\u826f\u597d\u7684\u8868\u683c\u4e2d\u63d0\u53d6\u6570\u636e\u3002\u5b83\u7684\u4f18\u52bf\u5728\u4e8e\u5904\u7406\u5177\u6709\u4f20\u7edf\u8868\u683c\u5e03\u5c40\u7684\u6587\u6863\uff0c\u4f7f\u5176\u6210\u4e3a\u6807\u51c6\u6570\u636e\u63d0\u53d6\u4efb\u52a1\u7684\u76f4\u63a5\u9009\u62e9\u3002\u7136\u800c\uff0cPyMuPDF \u7684\u6027\u80fd\u53ef\u80fd\u4f1a\u56e0\u7814\u7a76\u8bba\u6587\u4e2d\u7ecf\u5e38\u9047\u5230\u7684\u534a\u7ed3\u6784\u5316\u6216\u975e\u5e38\u89c4\u8868\u683c\u800c\u4e0b\u964d\u3002\u8fd9\u4e9b\u8868\u683c\u683c\u5f0f\u4e0d\u89c4\u5219\uff0c\u5bf9 PyMuPDF \u7684\u4f20\u7edf\u65b9\u6cd5\u6784\u6210\u4e86\u6311\u6218\u3002\u5bf9\u4e8e\u8fd9\u79cd\u590d\u6742\u7684\u60c5\u51b5\uff0c\u4f7f\u7528\u5177\u6709\u6df1\u5ea6\u5b66\u4e60\u529f\u80fd\u7684\u5de5\u5177\u53ef\u80fd\u4f1a\u66f4\u6709\u6548\u3002\u5b83\u4eec\u7ecf\u8fc7\u8bad\u7ec3\u53ef\u4ee5\u5904\u7406\u66f4\u5e7f\u6cdb\u7684\u8868\u683c\u683c\u5f0f\uff0c\u63d0\u4f9b\u4e3a\u5404\u79cd\u6570\u636e\u63d0\u53d6\u9700\u6c42\u63d0\u4f9b\u66f4\u901a\u7528\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>\u8fd9\u662f\u4f7f\u7528 PyMuPDF \u8fdb\u884c\u8868\u683c\u6570\u636e\u63d0\u53d6\u7684\u793a\u4f8b Python \u811a\u672c\uff1a<\/p>\n<pre><code>import fitz  # PyMuPDF\nimport pandas as pd\n\ndef extract_tables_to_csv(pdf_path, output_folder):\n    doc = fitz.open(pdf_path)\n\n    for page_number in range(len(doc)):\n        page = doc[page_number]\n        tables = page.find_tables()  # detect the tables on the current page\n\n        for i, table in enumerate(tables):\n            try:\n                df = table.to_pandas()  # attempt to convert the table to a pandas DataFrame\n                csv_filename = f\"{output_folder}\/page_{page_number}_table_{i}.csv\"\n                df.to_csv(csv_filename, index=False)  # save the DataFrame as a CSV\n            except IndexError as e:\n                print(f\"Error converting table on page {page_number}, table {i}: {e}\")\n\n    doc.close()\n\npdf_path = \"test.pdf\"\noutput_folder = \"output\"\nextract_tables_to_csv(pdf_path, output_folder)<\/code><\/pre>\n<p>\u8fd9\u662f\u4f7f\u7528 PyMuPDF \u63d0\u53d6\u7ed3\u6784\u826f\u597d\u7684\u8868\u683c\u7684\u539f\u56fe\u548c\u7ed3\u679c\uff1a<\/p>\n<p> \u8868\u683c\u539f\u56fe \u63d0\u53d6\u7ed3\u679c <\/p>\n<h2>5\u3001\u7ed3\u675f\u8bed<\/h2>\n<p>\u672c\u6587\u91cd\u70b9\u4ecb\u7ecd\u4e86\u4e00\u7cfb\u5217\u7528\u4e8e\u8868\u683c\u6570\u636e\u63d0\u53d6\u7684\u514d\u8d39\u548c\u5f00\u6e90\u5de5\u5177\uff0c\u4f8b\u5982 PyMuPDF\u3001PaddleOCR \u548c Azure Document Intelligence\uff0c\u6bcf\u4e2a\u5de5\u5177\u90fd\u6709\u5176\u4f18\u70b9\u548c\u5c40\u9650\u6027\u3002<\/p>\n<p>\u91cd\u8981\u7684\u662f\u8981\u8bb0\u4f4f\uff0c\u8868\u683c\u6570\u636e\u63d0\u53d6\u65e2\u662f\u4e00\u9879\u6df1\u5ea6\u5b66\u4e60\u6311\u6218\uff0c\u4e5f\u662f\u4e00\u4e2a\u6d3b\u8dc3\u7684\u7814\u7a76\u9886\u57df\uff0c\u968f\u7740\u65b0\u7684\u53d1\u5c55\u4e0d\u65ad\u53d1\u5c55\u3002 \u5f53\u524d\u7684\u89e3\u51b3\u65b9\u6848\u63d0\u4f9b\u4e86\u575a\u5b9e\u7684\u57fa\u7840\uff0c\u4f46\u8981\u83b7\u5f97\u5c16\u7aef\u7684\u51c6\u786e\u6027\u548c\u591a\u529f\u80fd\u6027\uff0c\u7d27\u8ddf\u6700\u65b0\u7684\u6df1\u5ea6\u5b66\u4e60\u8fdb\u6b65\u662f\u5173\u952e\u3002<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6df1\u5165\u63a2\u8ba8\u4e86\u4ece\u8868\u683c\u4e2d\u63d0\u53d6\u6570\u636e\u7684\u5fae\u5999\u4e16\u754c\uff0c\u8fd9\u9879\u4efb\u52a1\u6bd4\u63d0\u53d6\u7eaf\u6587\u672c\u8981\u590d\u6742\u5f97\u591a\u3002\u8fd9\u79cd\u590d\u6742\u6027\u6e90\u4e8e\u8868\u683c\u4e2d\u7ecf\u5e38\u51fa\u73b0\u7684\u975e\u5e38\u89c4\u7ed3\u6784\uff0c\u5c24\u5176\u662f\u5728\u7814\u7a76\u8bba\u6587\u4e2d\u3002\u4e0e\u6807\u51c6\u8868\u683c\u4e0d\u540c\uff0c\u8fd9\u4e9b\u8868\u683c\u53ef\u80fd\u6ca1\u6709\u6e05\u6670\u7684\u754c\u5b9a\uff0c\u6216\u8005\u5217\u6807\u9898\u548c\u5185\u5bb9\u4e4b\u95f4\u53ef\u80fd\u5b58\u5728\u9519\u4f4d\u3002\u8fd9\u79cd\u534a\u7ed3\u6784\u5316\u8868\u683c\u5bf9\u4f20\u7edf\u7684\u63d0\u53d6\u65b9\u6cd5\u63d0\u51fa\u4e86\u6311\u6218\uff0c\u9700\u8981\u66f4\u9ad8\u7ea7\u7684\u65b9\u6cd5\u3002 \u672c\u6587\u91cd\u70b9\u4ecb\u7ecd\u65e8\u5728\u6709\u6548\u5e94\u5bf9\u8fd9\u4e9b\u6311\u6218\u7684\u514d\u8d39\u5f00\u6e90\u5de5\u5177\u548c\u6280\u672f\u3002\u5b83\u63a2\u8ba8\u4e86\u5904\u7406\u975e\u6807\u51c6\u8868\u683c\u683c\u5f0f\u7684\u5404\u79cd\u7b56\u7565\uff0c\u63d0\u4f9b\u4e86\u6709\u6548\u63d0\u53d6\u6570\u636e\u7684\u89c1\u89e3\uff0c\u5373\u4f7f\u662f\u4ece\u683c\u5f0f\u6700\u4e0d\u89c4\u5219\u7684\u8868\u683c\u4e2d\u4e5f\u662f\u5982\u6b64\u3002\u91cd\u70b9\u662f\u63d0\u4f9b\u5b9e\u7528\u3001\u53ef\u8bbf\u95ee\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u8fd9\u4e9b\u89e3\u51b3\u65b9\u6848\u53ef\u4ee5\u5904\u7406\u8868\u683c\u6570\u636e\u63d0\u53d6\u7684\u590d\u6742\u6027\uff0c\u800c\u65e0\u9700\u627f\u62c5\u9ad8\u6602\u7684\u6210\u672c\u3002\u901a\u8fc7\u8fd9\u79cd\u63a2\u7d22\uff0c\u672c\u6587\u65e8\u5728\u8ba9\u8bfb\u8005\u638c\u63e1\u5728\u4f20\u7edf\u65b9\u6cd5\u65e0\u6cd5\u6ee1\u8db3\u9700\u6c42\u7684\u4e16\u754c\u4e2d\u5e94\u5bf9\u8868\u683c\u6570\u636e\u63d0\u53d6\u7684\u77e5\u8bc6\u3002 \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u7814\u7a76\u7528\u4e8e\u8868\u683c\u6570\u636e\u63d0\u53d6\u7684\u5404\u79cd\u5de5\u5177\u548c\u6280\u672f\uff0c\u5e76\u5c06\u6307\u5bfc\u4f60\u5b8c\u6210\u6709\u6548\u5b9e\u65bd\u8fd9\u4e9b\u89e3\u51b3\u65b9\u6848\u6240\u9700\u7684 Python \u4ee3\u7801\u3002 1\u3001PDF \u5230\u56fe\u50cf\u8f6c\u6362\uff08\u7528\u4e8e OCR \u5de5\u5177\uff09 \u6211\u4eec\u63a2\u7d22\u4e00\u79cd\u57fa\u4e8e Python \u7684\u65b9\u6cd5\uff0c\u7528\u4e8e\u5c06 PDF \u6587\u6863\u8f6c\u6362\u4e3a\u56fe\u50cf\uff0c\u8fd9\u662f\u4f7f\u7528 OCR\uff08\u5149\u5b66\u5b57\u7b26\u8bc6\u522b\uff09\u5de5\u5177\u7684\u5173\u952e\u6b65\u9aa4\u3002\u6b64\u8fc7\u7a0b\u6d89\u53ca PyMuPDF \u5e93\uff08\u79f0\u4e3a fitz\uff09\u548c Python \u56fe\u50cf\u5e93 (PIL)\u3002\u63d0\u4f9b\u7684\u811a\u672c\u5c06\u6bcf\u4e2a PDF \u9875\u9762\u8f6c\u6362\u4e3a PNG \u56fe\u50cf\uff0c\u4f7f\u5176\u53ef\u4f9b OCR \u8f6f\u4ef6\u8bfb\u53d6\u3002\u8be5\u65b9\u6cd5\u4fdd\u7559 PDF \u7684\u539f\u59cb\u5e03\u5c40\u548c\u5185\u5bb9\uff0c\u786e\u4fdd\u51c6\u786e\u7684 OCR \u7ed3\u679c\u3002\u8fd9\u79cd\u9ad8\u6548\u7684\u6280\u672f\u5bf9\u4e8e\u4ece\u57fa\u4e8e\u56fe\u50cf\u7684\u6587\u6863\u4e2d\u63d0\u53d6\u6587\u672c\u6570\u636e\u81f3\u5173\u91cd\u8981\u3002 \u8fd9\u662f\u4e0a\u8ff0\u4efb\u52a1\u7684\u793a\u4f8b Python \u811a\u672c\uff1a import fitz # PyMuPDF from PIL import Image def pdf_to_png(pdf_path, output_folder): pdf_document = fitz.open(pdf_path) for page_number in range(pdf_document.page_count): page = pdf_document.load_page(page_number) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-53735","post","type-post","status-publish","format-standard","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=53735"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53735\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}