46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using ExecPythonPDF;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Web.Http;
|
|
|
|
namespace PDFApi.Controllers
|
|
{
|
|
public class PdfController : ApiController
|
|
{
|
|
[HttpPost]
|
|
[Route("Api/ProcessPDF")] // 自定义路由
|
|
public IHttpActionResult ProcessPDF([FromBody] PDFRequest request)
|
|
{
|
|
JObject rtnJobject = new JObject();
|
|
rtnJobject.Add("success", "false");
|
|
rtnJobject.Add("code", "0");
|
|
rtnJobject.Add("msg", "");
|
|
rtnJobject.Add("data", new JArray());
|
|
try
|
|
{
|
|
if (request != null)
|
|
{
|
|
rtnJobject = PDFConvert.ExecutePdfExtraction(request.FileUrl, request.FileName);
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("空数据");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
rtnJobject["success"] = "false";
|
|
rtnJobject["code"] = "0";
|
|
rtnJobject["msg"] = ex.Message;
|
|
}
|
|
return Ok(rtnJobject);
|
|
}
|
|
// 定义接收参数的实体类
|
|
public class PDFRequest
|
|
{
|
|
public string FileUrl { get; set; }
|
|
public string FileName { get; set; }
|
|
}
|
|
}
|
|
}
|