【发布时间】:2023-04-01 08:11:02
【问题描述】:
我在移动浏览器上生成 pdf 文件时遇到以下问题。文件在某些移动浏览器上已损坏,而在某些移动浏览器中下载但未显示文本,它仅显示文件中的图像。同时在桌面浏览器上工作时文件生成完美,下载时文件内容完美显示。我不知道背后的真正原因,因为我是开发 Web 应用程序的新手。
我使用的代码如下:
Document pdfDoc = new Document(PageSize.A4, 10, 10, 10, 10);
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
string imageUrl = Server.MapPath("~/logo//bcetlogo.jpg");
iTextSharp.text.Image ImageLogo = iTextSharp.text.Image.GetInstance(imageUrl);
ImageLogo.ScaleToFit(80f, 80f);
pdfDoc.Add(ImageLogo);
Font f = FontFactory.GetFont("Arial", 15);
string title = "HelloWorld";
Paragraph text1 = new Paragraph(title, f);
pdfDoc.Add(text1);
pdfWriter.CloseStream = false;
pdfWriter.Close();
Response.Buffer = true;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=Example.PDF");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
【问题讨论】:
-
亲爱的@AbhinandanKumar,我的回答有问题吗?您是否有机会尝试提出的解决方案?对你有帮助吗?
标签: c# asp.net pdf itextsharp