Commit 45d2345f authored by 黄奎's avatar 黄奎

页面修改

parent 30650435
...@@ -35,14 +35,14 @@ namespace Edu.WebApi.Controllers.User ...@@ -35,14 +35,14 @@ namespace Edu.WebApi.Controllers.User
public FileContentResult DownloadFileForPdf(int configId, string url) public FileContentResult DownloadFileForPdf(int configId, string url)
{ {
DateTime start = DateTime.Now; 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()); Common.Plugin.LogHelper.WriteInfo(Common.Plugin.NetFileHelper.WNetAddConnection(@"fast-001\administrator", "Vt@2023..", @"\\172.16.103.126\WebFile", "Z:").ToString());
} }
else 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")); Console.WriteLine("{0} DownloadFileForPdf生成pdf....", start.ToString("yyyy-MM-dd HH:mm:ss fff"));
try try
...@@ -73,19 +73,48 @@ namespace Edu.WebApi.Controllers.User ...@@ -73,19 +73,48 @@ namespace Edu.WebApi.Controllers.User
var chromePath = Common.Config.ReadConfigKey("chromePath"); var chromePath = Common.Config.ReadConfigKey("chromePath");
string featurePath = Common.Config.ReadConfigKey("FeaturePath"); string featurePath = Common.Config.ReadConfigKey("FeaturePath");
string IsDownLoadChrome = Common.Config.ReadConfigKey("IsDownLoadChrome"); string IsDownLoadChrome = Common.Config.ReadConfigKey("IsDownLoadChrome");
List<string> argsList = new List<string>();
string headerFile = string.Format(@"{0}\\{1}_\\header_1.png", featurePath, configId);
//是否下载Chrome string footerFile = string.Format(@"{0}\\{1}_\\footer_1.png", featurePath, configId);
if (IsDownLoadChrome == "1") 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 var browserOptions = new LaunchOptions
{ {
Headless = true, Headless = true,
Args = argsList.ToArray(), 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; byte[] pdfBytes = null;
using (var browser = await Puppeteer.LaunchAsync(browserOptions)) using (var browser = await Puppeteer.LaunchAsync(browserOptions))
{ {
...@@ -93,23 +122,7 @@ namespace Edu.WebApi.Controllers.User ...@@ -93,23 +122,7 @@ namespace Edu.WebApi.Controllers.User
{ {
await page.GoToAsync(url); await page.GoToAsync(url);
await page.WaitForTimeoutAsync(10 * 1000); 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() pdfBytes = await page.PdfDataAsync(new PdfOptions()
{ {
PrintBackground = true, PrintBackground = true,
......
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<NoWarn>$(NoWarn);NETSDK1138</NoWarn> <NoWarn>$(NoWarn);NETSDK1138</NoWarn>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" /> <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.Azure.Containers.Tools.Targets" Version="1.10.9" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" /> <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" /> <PackageReference Include="Spire.Doc" Version="8.12.14" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -130,5 +130,5 @@ ...@@ -130,5 +130,5 @@
//行程头部底部图片 //行程头部底部图片
"FeaturePath": "E:\\WebFile\\Feature\\", "FeaturePath": "E:\\WebFile\\Feature\\",
//1-下载Chrome,0-不下载Chrome //1-下载Chrome,0-不下载Chrome
"IsDownLoadChrome": "1" "IsDownLoadChrome": "0"
} }
\ No newline at end of file
@echo off @echo off
echo ASPNETCORE_ENVIRONMENT=Development echo ASPNETCORE_ENVIRONMENT=Development
dotnet build 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 exit
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment