Files
lishanpi/tools/read_pdf2.py
T
hm fc10ef2e10 Initial commit: LSPi (LiangShanPi) project
GD32F470ZGT6 based project with full peripheral support:
- SDRAM (W9825G6KH) via EXMC
- LCD NT35510 (480x800) via EXMC NOR/PSRAM
- Flash (W25Q64) via SPI
- UART (USART0) debug console
- LED indicators
- CMSIS-DAP debug interface
- CMake + ARM GCC toolchain build system
2026-04-26 16:24:42 +08:00

48 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
import sys
import os
# 尝试用简单方法读取PDF
pdf_path = "LSPi_Project/doc/梁山Pi开发板.pdf"
# 方法1: 尝试使用pdfminer(如果可用)
try:
from pdfminer.high_level import extract_text
text = extract_text(pdf_path)
print("=== PDF内容 (pdfminer) ===")
print(text[:3000])
sys.exit(0)
except ImportError:
print("pdfminer不可用")
# 方法2: 尝试用二进制读取并查找可打印字符
try:
with open(pdf_path, 'rb') as f:
data = f.read()
# 提取可打印ASCII字符
text_chars = []
for byte in data:
if 32 <= byte < 127: # 可打印ASCII
text_chars.append(chr(byte))
elif byte == 10 or byte == 13: # 换行符
text_chars.append('\n')
text = ''.join(text_chars)
# 查找可能有用的部分
lines = text.split('\n')
useful_lines = []
keywords = ['pin', 'gpio', 'uart', 'i2c', 'spi', 'adc', 'timer', 'usart', 'tx', 'rx', 'scl', 'sda', 'miso', 'mosi', 'sck', 'cs']
for line in lines:
line_lower = line.lower()
if any(keyword in line_lower for keyword in keywords):
useful_lines.append(line)
print("=== 提取的有用信息 ===")
for line in useful_lines[:50]:
print(line)
except Exception as e:
print(f"错误: {e}")