lightpdf-aipdf-mcp 0.1.58__py3-none-any.whl → 0.1.60__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,7 @@ class EditType(str, Enum):
20
20
  DECRYPT = "unlock" # 解密PDF
21
21
  ADD_WATERMARK = "watermark" # 添加水印
22
22
  REMOVE_MARGIN = "edit" # 去除白边
23
+ EXTRACT_IMAGE = "extract" # 提取图片
23
24
 
24
25
  @dataclass
25
26
  class EditResult(BaseResult):
@@ -381,6 +382,41 @@ class Editor(BaseApiClient):
381
382
  # 调用edit_pdf方法处理API请求
382
383
  return await self.edit_pdf(file_path, EditType.REMOVE_MARGIN, extra_params, password, original_name)
383
384
 
385
+ async def extract_images(self, file_path: str, format: str = "png", password: Optional[str] = None, original_name: Optional[str] = None) -> EditResult:
386
+ """从PDF文件中提取图片
387
+
388
+ Args:
389
+ file_path: 要提取图片的PDF文件路径
390
+ format: 提取的图片格式,可选值为"bmp"/"png"/"gif"/"tif"/"jpg",默认为"png"
391
+ password: 文档密码,如果文档受密码保护,则需要提供(可选)
392
+ original_name: 原始文件名(可选)
393
+
394
+ Returns:
395
+ EditResult: 提取结果
396
+ """
397
+ # 验证输入文件是否为PDF
398
+ if not await self._validate_pdf_file(file_path):
399
+ return EditResult(success=False, file_path=file_path, error_message="非PDF文件", original_name=original_name)
400
+
401
+ # 验证图片格式
402
+ valid_formats = {"bmp", "png", "gif", "tif", "jpg"}
403
+ if format not in valid_formats:
404
+ error_msg = f"无效的图片格式: {format}。有效值为: bmp, png, gif, tif, jpg"
405
+ await self.logger.error(error_msg)
406
+ return EditResult(success=False, file_path=file_path, error_message=error_msg, original_name=original_name)
407
+
408
+ # 构建API参数
409
+ extra_params = {
410
+ "extract_type": "image",
411
+ "format": format
412
+ }
413
+
414
+ # 记录操作描述
415
+ await self._log_operation("从PDF提取图片", f"格式: {format}")
416
+
417
+ # 调用edit_pdf方法处理API请求
418
+ return await self.edit_pdf(file_path, EditType.EXTRACT_IMAGE, extra_params, password, original_name)
419
+
384
420
  async def edit_pdf(self, file_path: str, edit_type: EditType, extra_params: Dict[str, Any] = None, password: Optional[str] = None, original_name: Optional[str] = None) -> EditResult:
385
421
  """编辑PDF文件
386
422
 
@@ -139,6 +139,17 @@ async def process_conversion_file(
139
139
  original_name
140
140
  )
141
141
  else:
142
+ # 处理extra_params
143
+ if extra_params is None:
144
+ extra_params = {}
145
+
146
+ # 处理is_long_image参数,如果需要转换为长图,则添加merge_all=1参数
147
+ if extra_params.get("is_long_image") and format in ["jpg", "jpeg", "png"]:
148
+ extra_params["merge_all"] = 1
149
+ # 从extra_params中移除is_long_image,因为API不需要这个参数
150
+ if "is_long_image" in extra_params:
151
+ del extra_params["is_long_image"]
152
+
142
153
  # 对于其他操作,使用convert_file方法
143
154
  return await converter.convert_file(file_path, format, extra_params, password, original_name)
144
155
 
@@ -232,6 +243,14 @@ async def process_edit_file(
232
243
  password=password,
233
244
  original_name=original_name
234
245
  )
246
+ elif edit_type == "extract_image":
247
+ # 调用extract_images方法提取图片
248
+ return await editor.extract_images(
249
+ file_path=file_path,
250
+ format=extra_params.get("format", "png"),
251
+ password=password,
252
+ original_name=original_name
253
+ )
235
254
  else:
236
255
  return EditResult(
237
256
  success=False,
@@ -345,7 +364,7 @@ async def handle_list_tools() -> list[types.Tool]:
345
364
  return [
346
365
  types.Tool(
347
366
  name="convert_document",
348
- description="文档格式转换工具。\n\nPDF可转换为:DOCX/XLSX/PPTX/图片/HTML/TXT;\n其他格式可转换为PDF:DOCX/XLSX/PPTX/图片/CAD/CAJ/OFD",
367
+ description="文档格式转换工具。\n\nPDF可转换为:DOCX/XLSX/PPTX/图片(长图)/HTML/TXT;\n其他格式可转换为PDF:DOCX/XLSX/PPTX/图片/CAD/CAJ/OFD",
349
368
  inputSchema={
350
369
  "type": "object",
351
370
  "properties": {
@@ -375,6 +394,11 @@ async def handle_list_tools() -> list[types.Tool]:
375
394
  "type": "string",
376
395
  "description": "目标格式",
377
396
  "enum": ["pdf", "docx", "xlsx", "pptx", "jpg", "jpeg", "png", "html", "txt"]
397
+ },
398
+ "is_long_image": {
399
+ "type": "boolean",
400
+ "description": "是否需要转换为长图。仅当format为jpg/jpeg/png时有效",
401
+ "default": False
378
402
  }
379
403
  },
380
404
  "required": ["files", "format"]
@@ -776,7 +800,7 @@ async def handle_list_tools() -> list[types.Tool]:
776
800
  ),
777
801
  types.Tool(
778
802
  name="remove_margin",
779
- description="去除PDF文件的白边(页边距)。",
803
+ description="去除PDF文件的白边(裁剪去掉页面边距)。",
780
804
  inputSchema={
781
805
  "type": "object",
782
806
  "properties": {
@@ -805,6 +829,44 @@ async def handle_list_tools() -> list[types.Tool]:
805
829
  },
806
830
  "required": ["files"]
807
831
  }
832
+ ),
833
+ types.Tool(
834
+ name="extract_images",
835
+ description="从PDF文件中提取图片资源。",
836
+ inputSchema={
837
+ "type": "object",
838
+ "properties": {
839
+ "files": {
840
+ "type": "array",
841
+ "items": {
842
+ "type": "object",
843
+ "properties": {
844
+ "path": {
845
+ "type": "string",
846
+ "description": "需要提取图片的PDF文件路径或URL"
847
+ },
848
+ "password": {
849
+ "type": "string",
850
+ "description": "PDF文档密码,如果文档受密码保护,则需要提供此参数"
851
+ },
852
+ "name": {
853
+ "type": "string",
854
+ "description": "文件的原始文件名"
855
+ }
856
+ },
857
+ "required": ["path"]
858
+ },
859
+ "description": "需要提取图片的PDF文件列表,每个文件包含路径和可选的密码"
860
+ },
861
+ "format": {
862
+ "type": "string",
863
+ "description": "提取的图片格式",
864
+ "enum": ["bmp", "png", "gif", "tif", "jpg"],
865
+ "default": "png"
866
+ }
867
+ },
868
+ "required": ["files"]
869
+ }
808
870
  )
809
871
  ]
810
872
 
@@ -871,6 +933,11 @@ async def handle_call_tool(name: str, arguments: dict | None) -> list[types.Text
871
933
  "remove_margin": {
872
934
  "edit_type": "remove_margin", # 编辑类型
873
935
  "is_edit_operation": True, # 标记为编辑操作
936
+ },
937
+ "extract_images": {
938
+ "edit_type": "extract_image", # 编辑类型
939
+ "is_edit_operation": True, # 标记为编辑操作
940
+ "param_keys": ["format"] # 需要从arguments获取的参数
874
941
  }
875
942
  }
876
943
 
@@ -886,7 +953,8 @@ async def handle_call_tool(name: str, arguments: dict | None) -> list[types.Text
886
953
  "split_type": "page",
887
954
  "merge_all": 1,
888
955
  "angle": 90,
889
- "pages": "all" # 更新默认值为"all"
956
+ "pages": "all", # 更新默认值为"all"
957
+ "format": "png" # 提取图片的默认格式
890
958
  }
891
959
 
892
960
  if name in TOOL_CONFIG:
@@ -932,6 +1000,12 @@ async def handle_call_tool(name: str, arguments: dict | None) -> list[types.Text
932
1000
  if name == "protect_pdf" and "password" in arguments:
933
1001
  operation_config["extra_params"]["password"] = arguments.get("password")
934
1002
 
1003
+ # 处理convert_document工具的is_long_image参数
1004
+ if name == "convert_document" and "is_long_image" in arguments:
1005
+ if operation_config.get("extra_params") is None:
1006
+ operation_config["extra_params"] = {}
1007
+ operation_config["extra_params"]["is_long_image"] = arguments.get("is_long_image", False)
1008
+
935
1009
  # 特殊处理merge_pdfs工具
936
1010
  if name == "merge_pdfs":
937
1011
  # 创建编辑器
@@ -1058,4 +1132,4 @@ def cli_main():
1058
1132
  sys.exit(1)
1059
1133
 
1060
1134
  if __name__ == "__main__":
1061
- cli_main()
1135
+ cli_main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lightpdf-aipdf-mcp
3
- Version: 0.1.58
3
+ Version: 0.1.60
4
4
  Summary: MCP Server for LightPDF AI-PDF
5
5
  Author: LightPDF Team
6
6
  License: Proprietary
@@ -0,0 +1,9 @@
1
+ lightpdf_aipdf_mcp/__init__.py,sha256=PPnAgpvJLYLVOTxnHDmJAulFnHJD6wuTwS6tRGjqq6s,141
2
+ lightpdf_aipdf_mcp/common.py,sha256=-7LU6gm-As_F8Ly68ssy15Vc9Zt_eNSnvDLEtVZDwlI,6633
3
+ lightpdf_aipdf_mcp/converter.py,sha256=d90pNUT8pQn93u1fJSlu4f2KyLDzhOdTrqyBkSTRFBE,14450
4
+ lightpdf_aipdf_mcp/editor.py,sha256=Dsgp_WUCj4Ke17KCm3RzltiTnQmg8u5LVEuhz_kNCRo,26426
5
+ lightpdf_aipdf_mcp/server.py,sha256=uC08VViQGFYumPS9uvH1rGX-4YZ1leGNrgC4WKa2gDg,46912
6
+ lightpdf_aipdf_mcp-0.1.60.dist-info/METADATA,sha256=BQOwhWIVRCwa7oATdteJy7mL4xO1aK9i9RKYJxc-k58,7826
7
+ lightpdf_aipdf_mcp-0.1.60.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ lightpdf_aipdf_mcp-0.1.60.dist-info/entry_points.txt,sha256=X7TGUe52N4sYH-tYt0YUGApeJgw-efQlZA6uAZmlmr4,63
9
+ lightpdf_aipdf_mcp-0.1.60.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- lightpdf_aipdf_mcp/__init__.py,sha256=PPnAgpvJLYLVOTxnHDmJAulFnHJD6wuTwS6tRGjqq6s,141
2
- lightpdf_aipdf_mcp/common.py,sha256=-7LU6gm-As_F8Ly68ssy15Vc9Zt_eNSnvDLEtVZDwlI,6633
3
- lightpdf_aipdf_mcp/converter.py,sha256=d90pNUT8pQn93u1fJSlu4f2KyLDzhOdTrqyBkSTRFBE,14450
4
- lightpdf_aipdf_mcp/editor.py,sha256=fGzIiAp48uTXBBKWWlHcGT0nwgZQBpjvrsxSf6Ockk4,24730
5
- lightpdf_aipdf_mcp/server.py,sha256=E9F2aE52R2ZPdLyFdZJ02-dXrmE_VpAHk64J6qSd8KI,43447
6
- lightpdf_aipdf_mcp-0.1.58.dist-info/METADATA,sha256=EyhD4kqvzK_a8S1fjB2_9r37U4dmAXcXlQizuYbXs3k,7826
7
- lightpdf_aipdf_mcp-0.1.58.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- lightpdf_aipdf_mcp-0.1.58.dist-info/entry_points.txt,sha256=X7TGUe52N4sYH-tYt0YUGApeJgw-efQlZA6uAZmlmr4,63
9
- lightpdf_aipdf_mcp-0.1.58.dist-info/RECORD,,