/// <summary> /// 从S3下载并加上水印并返回下载地址 /// </summary> /// <param name="keyName">S3文件名</param> /// <param name="waterMarkName">水印文本名</param> public static string ConverPDFByS3Download(string keyName, string waterMarkName) { var fileSuffix = Path.GetExtension(keyName); var download = new AWSS3().DownloadObjectAsync(keyName); var s3File = download.Result; download.Wait(); string outPath = Path.Combine(Directory.GetCurrentDirectory(), @"temp"); if (!Directory.Exists(outPath)) { Directory.CreateDirectory(outPath); } string outFilePath = Path.Combine(outPath, string.Format("{0}{1}.{2}", waterMarkName, Guid.NewGuid().ToString(), fileSuffix)); string domainPath = string.Format("{0}/temp/{1}{2}.{3}", Constants.domain, waterMarkName, Guid.NewGuid().ToString(), fileSuffix); if (fileSuffix == ".pdf") { ConvertPDF.SetWatermark(s3File, outFilePath, waterMarkName); } else { StreamToFile(s3File, outFilePath); } return(domainPath); }
/// <summary> /// 从S3下载并加上水印并返回流 /// </summary> /// <param name="keyName">S3文件名</param> /// <param name="waterMarkName">水印文本名</param> public static Stream ConverPDFByStream(string keyName, string waterMarkName) { var fileSuffix = Path.GetExtension(keyName); var download = new AWSS3().DownloadObjectAsync(keyName); var s3File = download.Result; download.Wait(); if (fileSuffix == ".pdf") { return(ConvertPDF.SetWatermark(s3File, waterMarkName)); } return(null); }