【发布时间】:2018-07-08 14:54:59
【问题描述】:
所以我正在为我的客户制作软件,当我向他展示输出 (PDF) 时,输出中出现了奇怪的黑色条纹而不是图像。 它让我感到惊讶,因为它在我的电脑和笔记本电脑上运行良好,没有任何问题。所以我在虚拟机上试了一下,同样的问题发生了。
页眉和页脚始终保持不变,只有内容在页面之间切换。
我通过截取屏幕截图并切换内容然后将图像放入 PDF 来创建 PDF。 (输出总是打印出来的,所以没关系)。
- 主格式为 595 x 835
- 标题为 595 x 65
- 内容为 595 x 705
- 页脚为 595 x 65
制作 PDF 的部分代码
FileStream PDFfile = new FileStream(PDFpath + "//" + filename + "_" + i + ".pdf", FileMode.Create);
Document Document = new Document(PageSize.A4, 25, 25, 25, 25);
PdfWriter Writer = PdfWriter.GetInstance(Document, PDFfile);
Document.AddAuthor("Clientela garde");
Document.AddCreator("http://www.icsharp.eu");
Document.AddKeywords("Výpis do PDF");
Document.AddSubject("Výpis informací pro klienta");
Document.AddTitle("Finanční gramotnost");
// Výpis do stránky
Document.Open();
try
{
Page1.Hide();
Page2.Hide();
Page3.Hide();
Page4.Hide();
Page5.Hide();
Page1.Show();
System.Drawing.Rectangle bounds = this.Bounds;
using (Bitmap bitmap = new Bitmap(595, 835))
{
System.Drawing.Rectangle rct = new System.Drawing.Rectangle(new Point(bounds.Left - EcoTron.PDFCreator.ActiveForm.Location.X, bounds.Top - EcoTron.PDFCreator.ActiveForm.Location.Y), bounds.Size);
EcoTron.PDFCreator.ActiveForm.DrawToBitmap(bitmap, rct);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bitmap, System.Drawing.Imaging.ImageFormat.Bmp);
bitmap.SetResolution(1190, 1684);
PdfPTable HeaderTable = new PdfPTable(1);
HeaderTable.DefaultCell.Border = 0;
HeaderTable.WidthPercentage = 100;
PdfPCell ImageCell = new PdfPCell();
ImageCell.Border = 0;
img.ScaleAbsolute(595 - 50, 835 - 50);
ImageCell.AddElement(img);
HeaderTable.AddCell(ImageCell);
Document.Add(HeaderTable);
}
【问题讨论】:
-
我通过截取屏幕截图来创建 PDF 听起来好像该部分与机器/屏幕无关。由于我们没有看到它,我们只能猜测。图表是来自 excel 还是 MSChart 还是什么?
-
您没有显示代码,也没有共享 PDF...您希望我们如何提供帮助?
-
@mkl 抱歉,伙计们添加了信息。 TaW 图表只是图像。
-
该屏幕截图是否带有黑色边框,还是仅在 PDF 中出现?如果是由于您复制屏幕的方法,那么这个问题不是关于“PDF”部分,而只是关于如何更正您的屏幕复制。
-
@usr2564301 所以我做了测试,真正的问题是屏幕独立。如果我将虚拟计算机分辨率提高到 1600x1200(1280x1024 甚至我的 1920x1080 在 PC 上运行良好),它会显示在 IMAGE 和 PDF 上。你们有什么修复技巧吗?