我正在尝试让 IronPDF 参与我的 ASP.NET Core 3.1 应用服务部署。我没有使用 Azure Functions 来实现这些目的,而只是使用 Azure 应用服务上的常规端点 - 当用户调用它时,该服务会生成并返回生成的 PDF 文档。
在本地主机上运行端点时,它可以完美地工作 - 从传递到方法中的 HTML 生成报告。但是,一旦我将其部署到 Azure Web App Service,我就会收到502 - Bad Gateway错误,如附件所示(为了整洁起见,在 Swagger 中显示)。
控制器:
[HttpPost]
[Route("[action]")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> AgencyDownload([FromBody] AgencyReportSubmissionDto filters)
{
var user = await _userService.GetUserByIdAsync(HttpContext.User.GetUserId());
// Generate the PDF
var content = await _agencyReport.Generate(user, null, filters.FilterDate, filters.Content, filters.Type);
// Return the PDF to the browser
return new FileContentResult(content.BinaryData, "application/pdf") { FileDownloadName = "report.pdf" };
}
Run Code Online (Sandbox Code Playgroud)
服务:
public …Run Code Online (Sandbox Code Playgroud) 截至编写最新 IronPdf Linux NuGet 包之日

当我在 Docker Linux Container 下运行 .NET 6 Web API 时,当我点击 IronPdf 中的第一个方法时,应用程序会自行关闭this.pdfRenderer.RenderHtmlAsPdfAsync。没有错误或进入catch块,只是应用程序停止,我必须再次运行它。
我正在关注 IronPdf 提供的官方文档:https ://ironpdf.com/docs/questions/docker-linux/
这是我的用例以及我如何使用 IronPdf 库:
[HttpGet]
[Route("Reporting/PDF/{reportItemId:int}"]
public async Task<IActionResult> GenerateReport(int reportItemId)
{
try
{
IronPdf.Logging.Logger.EnableDebugging = true;
IronPdf.Logging.Logger.LogFilePath = "Default.log"; //May be set to a directory name or full file
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;
Installation.LinuxAndDockerDependenciesAutoConfig = false; …Run Code Online (Sandbox Code Playgroud) 我们正在使用ironPDF将我们的文档转换为PDF,它运行良好,并且在本地主机中将我们的文档(HTML)无缝转换为PDF,在确认所有内容后,我们购买了1年的许可证并将代码上传到生产。
一旦我们在生产中上传代码,就会收到错误:对路径“IronPdf.ChromeRenderingEngine.dll”的访问被拒绝。
这是我们正在使用的代码
string file = $"{Guid.NewGuid().ToString().Replace("-", "")}.pdf";
IronPdf.License.LicenseKey = ConfigurationManager.AppSettings["IronPdf.LicenseKey"];
IronPdf.Installation.TempFolderPath = ironPdf;
var pdfPrintOptions = new PdfPrintOptions()
{
InputEncoding = Encoding.UTF8,
PaperOrientation = PdfPrintOptions.PdfPaperOrientation.Portrait,
MarginTop = 10,
MarginBottom = 10,
MarginLeft = 10,
MarginRight = 10,
Footer = new SimpleHeaderFooter()
{
RightText = "Page {page} of {total-pages}",
DrawDividerLine = true,
FontSize = 10,
FontFamily = "Open Sans"
},
CssMediaType = PdfPrintOptions.PdfCssMediaType.Print
};
var Renderer = new HtmlToPdf(pdfPrintOptions);
var PDF = Renderer.RenderHtmlAsPdf(htmlContent.ToString());
PDF.SaveAs($"{sourceUrl}{file}");
PDF.Dispose();
Run Code Online (Sandbox Code Playgroud) 我正在使用 IronPDF 作为我们的 PDF 渲染引擎编写的 Azure Web 应用程序中成功生成 PDF 文档。\xc2\xa0 用例是用 C# 生成财务报表和发票的 PDF,作为更广泛的封闭业务应用程序的一部分。
\n本地开发中的一切都运行良好,HTML 到 PDF 文档生成器功能正是我们所需要的。将 PDF 生成器投入使用后,我们注意到渲染时间很慢。
\n\xc2\xa0这些有时会级联到请求队列中积压的 PDF,当等待时间超过 30 秒时,可能会导致 Web 请求超时。我们的代码并不罕见,并且仔细遵循 Ironpdf C# PDF 创建教程中的步骤:https ://ironpdf.com/tutorials/html-to-pdf/
\nPM> Install-Package IronPdf
var Renderer = new IronPdf.HtmlToPdf();\nRenderer.RenderHtmlAsPdf(templateHTML);\nRun Code Online (Sandbox Code Playgroud)\ntemplateHTML对于每个渲染都是唯一的,并且包含 CSS 和图像的链接。
\n我们的开发人员如何增强 PDF 渲染性能并为 IronPdf.HtmlToPdf PDF 生成器类启用多线程?
\n在 .NET 中的 Azure 上使用 IronPdf 在 C# 中生成 PDF 文件是否存在已知限制?
\n需要明确的是,我并不是在征求有关其他第 3 方 C# PDF 库的建议,只是征求如何最好地实施和优化我们选择的解决方案。
\n为了在明确的背景下澄清问题:
\n我目前正在与样式问题作斗争。我正在使用 IronPDF 创建一个 PDF 并从 HTML 生成新的 PDF。
我有一个实例,我的字体被覆盖。样式如下:
.bbBlankPage {
font-size: 20px; /*14 pt*/
text-align: center;
font-family: Arial !important;
font-weight: bold;
padding-top: 55%;
text-indent: 40px;
}
Run Code Online (Sandbox Code Playgroud)
当 HTML 生成并输出到 PDF 中时,PDF 将字体显示为 ArialBold。这导致字体与原始字体相比看起来更小和皱缩的问题。我试图通过扩大字体大小来过度补偿,但字体系列的变化让我很难过。如果我删除 font-weight,它会变成 ArialRegular,这也不对。我只想要普通的 Arial 字体。
我正在尝试使用 IronPDFs HTML 到 PDF 功能并行生成多个 PDF。但从 ASP.NET 启动时似乎陷入僵局:(
我在这里重新创建了问题:https ://github.com/snebjorn/ironpdf-threading-issue-aspnet
这是包含基本部分的片段。
打电话GetSequential()有效。但不是并行执行。
GetSimple()并行运行但出现死锁。
public class TestController : Controller
{
[HttpGet]
[Route("simple")]
public async Task<IActionResult> GetSimple()
{
var tasks = Enumerable
.Range(1, 10)
.Select(i => HtmlToDocumentAsync("hello", i));
var pdfs = await Task.WhenAll(tasks);
using var pdf = PdfDocument.Merge(pdfs);
pdf.SaveAs("output.pdf");
return Ok();
}
[HttpGet]
[Route("seq")]
public async Task<IActionResult> GetSequential()
{
var pdfs = new List<PdfDocument>();
foreach (var i in Enumerable.Range(1, 10))
{
pdfs.Add(await HtmlToDocumentAsync("hello", i));
}
using var …Run Code Online (Sandbox Code Playgroud) 我尝试使用IronPdf从 html打印 pdf ,但结果留下了边框。有没有办法在我的 PrintDocument 中设置“适合页面”?
这是我的代码:
public static void PrintDocument(string printer, bool landscape, PdfDocument pdfDocument, Duplexing duplex)
{
var printDocument = pdfDocument.GetPrintDocument();
printDocument.PrinterSettings.PrinterName = printer;
printDocument.DefaultPageSettings.Landscape = landscape;
printDocument.PrinterSettings.Duplex = DuplexMapping(duplex);
printDocument.PrinterSettings.DefaultPageSettings.PaperSize.RawKind = (int)PaperKind.A4;
printDocument.Print();
}
Run Code Online (Sandbox Code Playgroud) 我在思考如何正确包装我正在使用的名为 .pdf 的 PDF 库时遇到了一个问题IronPDF。
IronPDF有一个PdfDocument对象。
我的想法是创建一个IronPdfDocument如下所示的对象:
public class IronPdfDocument : PdfDocument, IPdfDocument
{
public IronPdfDocument(string filePath) : base(filePath) { }
public IronPdfDocument(Stream stream) : base(stream) { }
public IronPdfDocument(byte[] data) : base(data) { }
public Stream GetSTream() => base.Stream;
}
Run Code Online (Sandbox Code Playgroud)
IronPDF还有一个被调用的渲染对象HtmlToPdf,我的想法是创建一个IronPdfRenderer如下所示的渲染对象:
public class IronPdfRenderer : HtmlToPdf, IPdfRenderer
{
public IronPdfRenderer() : base() { }
public IPdfDocument RenderHtmlAsPdf(string html)
=> (IronPdfDocument)base.RenderHtmlAsPdf(html);
}
Run Code Online (Sandbox Code Playgroud)
然后在代码中使用接口对象,如下所示:
public IPdfDocument Execute()
{
IPdfRenderer …Run Code Online (Sandbox Code Playgroud) ironpdf ×8
c# ×7
asp.net-core ×2
azure ×2
pdf ×2
.net ×1
.net-6.0 ×1
asp.net ×1
async-await ×1
css ×1
docker ×1
html-to-pdf ×1
inheritance ×1
printing ×1
styling ×1