我正在尝试将多个PDF组合成一个PDF.PDF来自SSRS,来自我处理的一些LocalReports.我正在使用PDFSharp,因为它已经在整个项目中使用.但是,outputDocument.addPage(page)方法抛出InvalidOperationException("无法更改文档.")异常.我尝试了许多不同的方法,但我无法让它工作......
这是我的方法,其中已经检查了所有输入:
private static void saveFile(string fileName, params byte[][] bytes)
{
try
{
PdfDocument outputDocument = new PdfDocument();
for (int i = 0; i < bytes.Length; i++)
{
using (MemoryStream stream = new MemoryStream(bytes[i]))
{
PdfDocument inputDocument = PdfReader.Open(stream, PdfDocumentOpenMode.Import);
foreach (PdfPage page in inputDocument.Pages)
{
outputDocument.AddPage(page); //throws the exception !!!
}
}
}
outputDocument.Save(fileName);
}
catch (Exception ex)
{
throw new Exception("Erreur lors de l'enregistrement du fichier", ex);
}
}
Run Code Online (Sandbox Code Playgroud)
从我在网上看到的例子来看,这似乎是这样做的正确方法......我对合并我的PDF的其他建议持开放态度,但我宁愿不使用其他第三方库,比如ITextSharp,因为PDFSharp是已经在项目中使用过.
如果重要,我在Win7机器上使用VS2010 Pro.
编辑:从异常调用堆栈:
在PdfSharp.Pdf.PdfObject.set_Document(PdfDocument值)
在PdfSharp.Pdf.PdfObject.ImportClosure(PdfImportedObjectTable importedObjectTable,PdfDocument老板,PdfObject externalObject)
在PdfSharp.Pdf.PdfPages.CloneElement(PdfPage页, …
我正在尝试创建一个适用于类型化数据表的通用扩展方法:
public static class Extensions
{
public static TableType DoSomething<TableType, RowType>(this TableType table, param Expression<Func<RowType, bool>>[] predicates)
where TableType : TypedTableBase<RowType>
where RowType : DataRow
{
// do something to each row of the table where the row matches the predicates
return table;
}
[STAThread]
public static void main()
{
MyTypedDataSet.MyTypedDataTable table = getDefaultTable();
}
public static MyTypedDataSet.MyTypedDataTable getDefaultTable()
{
// this line compiles fine and does what I want:
return new MyTypedDataSet.MyTypedDataTable().DoSomething<MyTypedDataSet.MyTypedDataTable, MyTypedDataSet.MyTypedRow>(row => row.Field1 == "foo");
// this …Run Code Online (Sandbox Code Playgroud) 我有这个数据库,不是我的设计,但我必须使用它,它包含一个像这样的表:
id | Name | status | ... -----+------------+----------+------ 1 | Product1 | 2 | ... 2 | Product2 | 2 | ... 3 | Product3 | 3 | ... ... | ... | ... | ...
status属性是指枚举所在的位置
0 = Invalid 1 = Dev 2 = Activ 3 = Old
当我在只读数据网格视图中显示它时,我希望用户看到枚举的名称(Dev,Activ,...)或描述而不是数值.datagridview绑定到来自DAL的数据表,同样不属于我的设计,因此我无法真正更改数据表.我发现如何做到这一点的唯一方法是通过监听datagridview.CellFormating事件,我把这个代码:
private void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 3) // column of the enum
{
try
{
e.Value = getEnumStringValue(e.Value);
}
catch (Exception ex)
{
e.Value = …Run Code Online (Sandbox Code Playgroud)