diff --git a/Edu.WebApi/Controllers/User/HomeController.cs b/Edu.WebApi/Controllers/User/HomeController.cs index 7e89aa2688c50c16a4e63a20cd39ec33d3295f9f..1dbb80a7c0ca4ccdbf475eed3bf5b4e486491cf8 100644 --- a/Edu.WebApi/Controllers/User/HomeController.cs +++ b/Edu.WebApi/Controllers/User/HomeController.cs @@ -35,14 +35,14 @@ namespace Edu.WebApi.Controllers.User public FileContentResult DownloadFileForPdf(int configId, string url) { DateTime start = DateTime.Now; - if (Common.Config.IsLocal == 0 && !Directory.Exists("Z:")) + if (Common.Config.IsLocal == 0 && Directory.Exists("Z:")) { - Console.WriteLine("AA___Not:Z:"); + Console.WriteLine("AA___Yes:Z:"); Common.Plugin.LogHelper.WriteInfo(Common.Plugin.NetFileHelper.WNetAddConnection(@"fast-001\administrator", "Vt@2023..", @"\\172.16.103.126\WebFile", "Z:").ToString()); } else { - Console.WriteLine("BB__Yes:Z:"); + Console.WriteLine("BB__No:Z:"); } Console.WriteLine("{0} DownloadFileForPdf生æˆpdf....", start.ToString("yyyy-MM-dd HH:mm:ss fff")); try @@ -73,19 +73,48 @@ namespace Edu.WebApi.Controllers.User var chromePath = Common.Config.ReadConfigKey("chromePath"); string featurePath = Common.Config.ReadConfigKey("FeaturePath"); string IsDownLoadChrome = Common.Config.ReadConfigKey("IsDownLoadChrome"); - List<string> argsList = new List<string>(); - - //是å¦ä¸‹è½½Chrome - if (IsDownLoadChrome == "1") + + string headerFile = string.Format(@"{0}\\{1}_\\header_1.png", featurePath, configId); + string footerFile = string.Format(@"{0}\\{1}_\\footer_1.png", featurePath, configId); + string headerContent = ""; + string top = "0px"; + string bottom = "0px"; + Console.WriteLine("headerFile::Path__" + headerFile); + if (System.IO.File.Exists(headerFile)) { - var result = await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision); + headerContent = string.Format(@"<img src='data:image/png;base64,{0}' style='width:100%;'></img>", ConvertImageToBase64(headerFile)); + top = "92px"; + Console.WriteLine("Exists___Header" + configId); } + string footerContent = ""; + if (System.IO.File.Exists(footerFile)) + { + footerContent = string.Format(@"<img src='data:image/png;base64,{0}' style='width:100%;height:auto;'></img>", ConvertImageToBase64(footerFile)); + bottom = "50px"; + Console.WriteLine("Exists___Footer___"+configId); + } + + List<string> argsList = new List<string>(); var browserOptions = new LaunchOptions { Headless = true, Args = argsList.ToArray(), }; - // ExecutablePath = chromePath, + //是å¦ä¸‹è½½Chrome + if (IsDownLoadChrome == "1") + { + var result = await new BrowserFetcher().DownloadAsync(); + } + else + { + //string path= Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ".local-chromium", "Win64-970485", "chrome-win", "UserData").Replace(@"\", @"\\"); + //Console.WriteLine("path::" + path); + //browserOptions.UserDataDir = path; + //string newPath= Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ".local-chromium", "Win64-970485", "chrome-win", "chrome.exe").Replace(@"\", @"\\"); + //Console.WriteLine("newPath::" + newPath); + //browserOptions.ExecutablePath = newPath; + //browserOptions.ExecutablePath = chromePath; + } byte[] pdfBytes = null; using (var browser = await Puppeteer.LaunchAsync(browserOptions)) { @@ -93,23 +122,7 @@ namespace Edu.WebApi.Controllers.User { await page.GoToAsync(url); await page.WaitForTimeoutAsync(10 * 1000); - string headerFile = string.Format(@"{0}\\{1}_\\header_1.png", featurePath, configId); - string footerFile = string.Format(@"{0}\\{1}_\\footer_1.png", featurePath, configId); - string headerContent = ""; - string top = "0px"; - string bottom = "0px"; - - if (System.IO.File.Exists(headerFile)) - { - headerContent = string.Format(@"<img src='data:image/png;base64,{0}' style='width:100%;'></img>", ConvertImageToBase64(headerFile)); - top = "92px"; - } - string footerContent = ""; - if (System.IO.File.Exists(footerFile)) - { - footerContent = string.Format(@"<img src='data:image/png;base64,{0}' style='width:100%;height:auto;'></img>", ConvertImageToBase64(footerFile)); - bottom = "50px"; - } + pdfBytes = await page.PdfDataAsync(new PdfOptions() { PrintBackground = true, diff --git a/Edu.WebApi/Edu.WebApi.csproj b/Edu.WebApi/Edu.WebApi.csproj index 08baec85130a4f5eeee00547ead2c05d892cbc72..d09f1fc9a84d4e667f9c401ca29025e86f794089 100644 --- a/Edu.WebApi/Edu.WebApi.csproj +++ b/Edu.WebApi/Edu.WebApi.csproj @@ -1,7 +1,7 @@ <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> - <TargetFramework>netcoreapp3.0</TargetFramework> + <TargetFramework>netcoreapp3.1</TargetFramework> <NoWarn>$(NoWarn);NETSDK1138</NoWarn> </PropertyGroup> <PropertyGroup> @@ -30,7 +30,7 @@ <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" /> - <PackageReference Include="PuppeteerSharp" Version="7.1.0" /> + <PackageReference Include="PuppeteerSharp" Version="11.0.2" /> <PackageReference Include="Spire.Doc" Version="8.12.14" /> </ItemGroup> <ItemGroup> diff --git a/Edu.WebApi/appsettings.json b/Edu.WebApi/appsettings.json index 90941dae1640bf586ec7ce6c28d701d6282bc927..ab860c5c3d2ad26d1ccf0bc7c35d127b50ba41e5 100644 --- a/Edu.WebApi/appsettings.json +++ b/Edu.WebApi/appsettings.json @@ -130,5 +130,5 @@ //ÐгÌÍ·²¿µ×²¿Í¼Æ¬ "FeaturePath": "E:\\WebFile\\Feature\\", //1-ÏÂÔØChrome,0-²»ÏÂÔØChrome - "IsDownLoadChrome": "1" + "IsDownLoadChrome": "0" } \ No newline at end of file diff --git a/Edu.WebApi/run_5001.cmd b/Edu.WebApi/run_5001.cmd index a083b65acf7f01740d5f41e85f202241a5c816de..1bfd885407d6791618ae5da16cf7a8a9794535c0 100644 --- a/Edu.WebApi/run_5001.cmd +++ b/Edu.WebApi/run_5001.cmd @@ -1,5 +1,5 @@ @echo off ¡¡¡¡echo ASPNETCORE_ENVIRONMENT=Development ¡¡¡¡dotnet build -¡¡¡¡start "Edu.WebApi" dotnet bin\Debug\netcoreapp3.0\Edu.WebApi.dll --urls http://0.0.0.0:5001 --ip="127.0.0.1" --port=5001 +¡¡¡¡start "Edu.WebApi" dotnet bin\Debug\netcoreapp3.1\Edu.WebApi.dll --urls http://0.0.0.0:5001 --ip="127.0.0.1" --port=5001 exit \ No newline at end of file