【发布时间】:2015-04-28 14:52:59
【问题描述】:
美好的一天,
我有一个控制台应用程序,它有一个带有图像的水晶报表。我将使用 exporttostream 运行报告并将导出的报告存储在 sqlserver 2012 的 varbinary 字段中。然后我将选择这些报告的批次并使用 itextsharp 将它们连接成 1 个 pdf 文件。报告上的徽标并非全部显示在某些页面上。任何想法为什么会发生这种情况。运行此应用程序时,我也在使用并行处理(Parallel.For)。 任何想法为什么会发生这种情况?或者让这个图像嵌入报告中始终显示的最佳方法是什么? 我尝试运行相同的代码,但只有 1 个并行进程(即按顺序执行)并且所有图像都出现在 pdf 中。为什么并行处理不能正确渲染图像? 提前致谢
******编辑****** 连接pdf的代码
Document document = null;
for ( int i=1; i <= numbatches;i++)
{
String printer_file_prefix = dll.Print.getPrinterFilePrefix(connectionString, bill_type_id.ToString());
batchnumberpadded = i.ToString();
batchnumberpadded = batchnumberpadded.PadLeft(3, '0');
printerfilename = printer_file_prefix + oneup_number + batch_id + batchnumberpadded;//eg D_G123456CUST001
BatchPrintFilePath = Globals.printer_filelocation_prefix + printerfilename + ".pdf";
document = new Document(PageSize.A4);
PdfCopy copy = new PdfCopy(document, new FileStream(BatchPrintFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite));
document.Open();
using (SqlConnection sconn = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("spGetPrinterFiles", sconn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@batch_num", i);
cmd.Parameters.AddWithValue("@maximumRows",Globals.print_batch);
cmd.Parameters.AddWithValue("@archive_process_instance_no", archive_process_instance_no);
cmd.Parameters.AddWithValue("@batch_id", @batch_id);
sconn.Open();
using (SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.Default))
{
while (dr.Read())
{
copy.AddDocument(new PdfReader((byte[])dr.GetValue(0)));
}
dr.Close();
sconn.Close();
}
sconn.Close();
}
}
if (copy != null)
copy.Close();
if (document.IsOpen())
document.Close();
}//end for
【问题讨论】:
-
请澄清:你是如何连接文件的?有很多非常糟糕的例子使用
Document和PdfWriter(这显然是错误的方式)而不是使用PdfCopy或PdfSmartCopy(这是正确的方式)。如果您不提供更多数据,这个问题将无法回答。 -
抱歉,我编辑了我的问题。我不知道可能导致问题的原因,所以不知道代码的哪些部分会有所帮助
-
首先删除
copy.Close()。如果要保留该行,请在关闭PdfCopy实例之前关闭Document。现在我们可以看到您的代码,但我们仍然不知道出了什么问题。你说的标志在哪里?由于 iText 之外的某些原因,它们可能不会出现在任何地方。有没有办法可以提供SSCCE? -
徽标在水晶报表中。由于公司政策,我认为我无法提供 SSCEE。对不起
-
问题是不是一直没有加logo造成的? iText 没有任何理由删除特定内容。我认为徽标从不存在。
标签: .net crystal-reports itextsharp parallel.foreach