|
@@ -4,6 +4,7 @@ using iTextSharp.text.pdf;
|
|
|
using LisPacsDataUpload.Models.Report;
|
|
|
using Newtonsoft.Json;
|
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.Configuration;
|
|
|
using System.Data;
|
|
|
using System.Diagnostics;
|
|
@@ -113,12 +114,10 @@ namespace LisPacsDataUpload.business
|
|
|
// 三方lis
|
|
|
string three_sql = @"select pdfUrl from three_lis_pdf where yzid =" + bbid;
|
|
|
LogHelper.Info("three_sql "+ three_sql);
|
|
|
- DataRow data = SqlServerHelper.ExecuteSingleRowQuery(three_sql);
|
|
|
- if (data!=null)
|
|
|
+ List<string> pdfs = SqlServerHelper.GetPdfUrlList(three_sql);
|
|
|
+ if (pdfs != null && pdfs.Count()>0)
|
|
|
{
|
|
|
- string jpgUrl = data["pdfUrl"].ToString();
|
|
|
- LogHelper.Info("三方原始jpgUrl" + jpgUrl);
|
|
|
- GetPdfFromJpg(jpgUrl, path);
|
|
|
+ GetPdfFromJpgList(pdfs, path);
|
|
|
return path;
|
|
|
}
|
|
|
return "三方lispdf报告获取失败";
|
|
@@ -164,6 +163,53 @@ namespace LisPacsDataUpload.business
|
|
|
LogHelper.Info("JPG 转换为 PDF 成功!");
|
|
|
}
|
|
|
|
|
|
+ public static void GetPdfFromJpgList(List<string> jpgUrls, string pdfUrl)
|
|
|
+ {
|
|
|
+ LogHelper.Info("开始从jpg列表转换pdf");
|
|
|
+ using (FileStream fs = new FileStream(pdfUrl, FileMode.Create))
|
|
|
+ {
|
|
|
+ // 创建一个文档对象
|
|
|
+ Document document = new Document();
|
|
|
+ // 创建一个 PDF 写入器,将文档写入文件流
|
|
|
+ PdfWriter writer = PdfWriter.GetInstance(document, fs);
|
|
|
+ document.Open();
|
|
|
+ foreach (string jpgUrl in jpgUrls)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ LogHelper.Info("三方pdfUrl="+ jpgUrl);
|
|
|
+ // 创建一个图像对象并加载 JPG 文件
|
|
|
+ Image image = Image.GetInstance(jpgUrl);
|
|
|
+ // 设置图像在 PDF 中的尺寸(可以根据需要调整)
|
|
|
+ // 这里为了保持图片比例,我们先获取图片的原始尺寸
|
|
|
+ float imgWidth = image.ScaledWidth;
|
|
|
+ float imgHeight = image.ScaledHeight;
|
|
|
+
|
|
|
+ // 根据需要调整图片大小,这里以A4纸大小减去边距为例
|
|
|
+ float pdfWidth = document.PageSize.Width - 20;
|
|
|
+ float pdfHeight = document.PageSize.Height - 20;
|
|
|
+
|
|
|
+ // 根据宽度或高度调整图片大小,保持比例
|
|
|
+ float scaleFactor = Math.Min(pdfWidth / imgWidth, pdfHeight / imgHeight);
|
|
|
+ image.ScaleAbsolute(imgWidth * scaleFactor, imgHeight * scaleFactor);
|
|
|
+
|
|
|
+ // 将图像添加到 PDF 文档中
|
|
|
+ document.Add(image);
|
|
|
+ // 添加一个空行以分隔图片(可选)
|
|
|
+ document.Add(new Paragraph(string.Empty));
|
|
|
+ document.NewPage(); // 如果需要在每张图片后添加新页,则使用此行
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.Error(ex ,"无法加载图片"+jpgUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ document.Close();
|
|
|
+ }
|
|
|
+ LogHelper.Info("JPG 列表转换为 PDF 成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static string GeneratePdf(int lisVersion, string reportNumber, string bbid, string yzid)
|
|
|
{
|
|
|
string pdfUrl = getPdfParamByLisVersion(lisVersion, reportNumber, bbid, yzid);
|