【发布时间】:2014-12-19 06:40:28
【问题描述】:
我正在使用 iTextSharp 在 ASP.NET C# Windows 控制台应用程序中创建 PDF 文件。
我有这段代码。如果站点是“LMH”,我会得到一个很好的 PDF,我可以用 Adobe Reader 打开。如果没有,我会收到错误:处理页面时出错。阅读此文档时出现问题 (114)。
这是我的代码:
string ApplicationPath = System.IO.Directory.GetCurrentDirectory();
PdfPTable table = new PdfPTable(4) { TotalWidth = 800.0F, LockedWidth = true };
float[] widths = new[] { 80.0F, 80.0F, 500.0F, 140.0F };
table.SetWidths(widths);
table.HorizontalAlignment = 0;
table.DefaultCell.Border = 0;
if (ActiveProfile.Site == "LMH")
{
Image hmsImage = Image.GetInstance(ApplicationPath + "\\" + "HMS Logo.png");
hmsImage.ScaleToFit(80.0F, 40.0F);
PdfPCell hmslogo = new PdfPCell(hmsImage);
hmslogo.Border = 0;
hmslogo.FixedHeight = 60;
table.AddCell(hmslogo);
}
else
{
Image blankImage = Image.GetInstance(ApplicationPath + "\\" + "emptyLogo.png");
blankImage.ScaleToFit(80.0F, 40.0F);
PdfPCell emptyCell = new PdfPCell(blankImage);
emptyCell.Border = 0;
emptyCell.FixedHeight = 60;
table.AddCell(emptyCell);
}
还有主干:
System.IO.FileStream file = new System.IO.FileStream(("C:/") + keyPropertyId + ".pdf", System.IO.FileMode.OpenOrCreate);
Document document = new Document(PageSize.A4.Rotate () , 20, 20, 6, 4);
PdfWriter writer = PdfWriter.GetInstance(document, file );
document.AddTitle(_title);
document.Open();
addHeader(document);
addGeneralInfo(document, keyPropertyId);
addAppliances(document, _LGSRobj);
addFaults(document, _LGSRobj);
addAlarms(document, _LGSRobj);
addFinalCheck(document, _LGSRobj);
addSignatures(document, _LGSRobj);
addFooter(document, writer);
document.Close();
writer .Close ();
file.Close();
所有改变的只是一个标志。两个徽标文件具有相同的尺寸。什么可能是错的?顺便提一句。使用 Foxit 可以正常打开文件,但这不是可接受的解决方案。
这是我无法使用 Adobe Reader 打开的 PDF:https://dl.dropboxusercontent.com/u/20086858/1003443.pdf
这是 emptyLogo.png 文件:https://dl.dropboxusercontent.com/u/20086858/emptylogo.png
这是有效的标志:https://dl.dropboxusercontent.com/u/20086858/HMS%20Logo.png
这是 pdf 的“好”版本,带有有效的徽标:https://dl.dropboxusercontent.com/u/20086858/1003443-good.pdf
【问题讨论】:
-
您能分享有问题的损坏的 PDF 吗?
-
不知道该怎么做。
-
你能把两张图片都发上来吗?
-
如何共享 PDF 和图像?
-
Dropbox 是您的朋友,或任何其他文件共享服务。
标签: c# asp.net pdf adobe itextsharp