Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

Merge branch 'master' of github.com:papayalove/Magic-PDF

liukaiwenfe58649bbb37
diff --cc magic_pdf/io/DiskReaderWriter.py
index 87d59d4b,76d63efd..0bc037ab
--- a/magic_pdf/io/DiskReaderWriter.py
+++ b/magic_pdf/io/DiskReaderWriter.py
@@@ -33,11 -35,8 +35,11 @@@ class DiskReaderWriter(AbsReaderWriter)
abspath = path
else:
abspath = os.path.join(self.path, path)
+ if not os.path.exists(abspath):
+ directory_path = os.path.dirname(abspath)
+ os.makedirs(directory_path)
if mode == MODE_TXT:
- with open(abspath, 'w', encoding=self.encoding) as f:
+ with open(abspath, "w", encoding=self.encoding) as f:
f.write(content)
logger.info(f"内容已成功写入 {abspath}")
@@@ -48,12 -47,13 +50,13 @@@
else:
raise ValueError("Invalid mode. Use 'text' or 'binary'.")
- def read_jsonl(self, path: str, byte_start=0, byte_end=None, encoding='utf-8'):
+ def read_jsonl(self, path: str, byte_start=0, byte_end=None, encoding="utf-8"):
return self.read(path)
+
# 使用示例
if __name__ == "__main__":
- file_path = "io/example.txt"
+ file_path = "io/test/example.txt"
drw = DiskReaderWriter("D:\projects\papayfork\Magic-PDF\magic_pdf")
# 写入内容到文件