lightpdf-aipdf-mcp 0.1.59__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
 
@@ -243,6 +243,14 @@ async def process_edit_file(
243
243
  password=password,
244
244
  original_name=original_name
245
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
+ )
246
254
  else:
247
255
  return EditResult(
248
256
  success=False,
@@ -821,6 +829,44 @@ async def handle_list_tools() -> list[types.Tool]:
821
829
  },
822
830
  "required": ["files"]
823
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
+ }
824
870
  )
825
871
  ]
826
872
 
@@ -887,6 +933,11 @@ async def handle_call_tool(name: str, arguments: dict | None) -> list[types.Text
887
933
  "remove_margin": {
888
934
  "edit_type": "remove_margin", # 编辑类型
889
935
  "is_edit_operation": True, # 标记为编辑操作
936
+ },
937
+ "extract_images": {
938
+ "edit_type": "extract_image", # 编辑类型
939
+ "is_edit_operation": True, # 标记为编辑操作
940
+ "param_keys": ["format"] # 需要从arguments获取的参数
890
941
  }
891
942
  }
892
943
 
@@ -902,7 +953,8 @@ async def handle_call_tool(name: str, arguments: dict | None) -> list[types.Text
902
953
  "split_type": "page",
903
954
  "merge_all": 1,
904
955
  "angle": 90,
905
- "pages": "all" # 更新默认值为"all"
956
+ "pages": "all", # 更新默认值为"all"
957
+ "format": "png" # 提取图片的默认格式
906
958
  }
907
959
 
908
960
  if name in TOOL_CONFIG:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lightpdf-aipdf-mcp
3
- Version: 0.1.59
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=0FcdFUQLdINscScE8_tDeA41hC1TqvJWoNcfLhxqTfo,44612
6
- lightpdf_aipdf_mcp-0.1.59.dist-info/METADATA,sha256=syXcd6G9JRqGJAqWvKfVad6VnVI1dWfkxzJxZDQBB4U,7826
7
- lightpdf_aipdf_mcp-0.1.59.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- lightpdf_aipdf_mcp-0.1.59.dist-info/entry_points.txt,sha256=X7TGUe52N4sYH-tYt0YUGApeJgw-efQlZA6uAZmlmr4,63
9
- lightpdf_aipdf_mcp-0.1.59.dist-info/RECORD,,