如何在服务器中指定转换后的 pdf 的下载位置?
当我在服务器中运行时,我想将 pdf 保存在服务器文件中,但我不知道如何操作内存流或如何操作。
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
using System.IO;
using Microsoft.AspNetCore.Hosting;
namespace HospitalQR.Web.Controllers
{
public class FormController : Controller
{
private readonly IHostingEnvironment _hostingEnvironment;
public FormController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public IActionResult Index()
{
return View("PreForm");
}
public IActionResult PdfConverter()
{
HtmlToPdfConverter converter = new HtmlToPdfConverter();
WebKitConverterSettings settings = new WebKitConverterSettings();
settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesWindows");
converter.ConverterSettings = settings;
PdfDocument document = converter.Convert("https://localhost:44334/form");
MemoryStream ms = new MemoryStream();
document.Save(ms);
document.Close(true);
ms.Position = 0;
FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
fileStreamResult.FileDownloadName = "PreForm.pdf";
return fileStreamResult;
}
}
}