ASP.NET - PDFLib dll not working in .net4.0

Asked By gopal krish on 23-Jan-12 06:26 AM
hi..

i was converted my .net2.0 project into .net4.0.

now i could not use pdflib.dll.
i recieved the below error.

"Declaration referenced in a method implementation cannot be a final method.  Type: 'PDFLibNet.xPDFBinaryReader'.  Assembly: 'PDFLibNet, Version=1.0.6.6, Culture=neutral, PublicKeyToken=26d87f7d66fb2aee'."


in .net2.0 and net3.5 it is worked for me. but not in .net4.0.


how to handle this..

need ur suggestions with examples.

regards
gopal.s
dipa ahuja replied to gopal krish on 23-Jan-12 06:28 AM
Use iTextSharp

This is the simple example
 
Try this way:
 
Download the dll of itextSharp.dll
 
http://sourceforge.net/projects/itextsharp/
 
and try this code
 
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
 
private void btnExport_Click(object sender, EventArgs e)
{
   Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
   PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("d:\\Test.pdf", FileMode.Create));
 
   doc.Open();//Open Document to write
 
 
   Paragraph paragraph = new Paragraph("data Exported From DataGridview!");
 
   doc.Add(paragraph);
   doc.Add(t1);
   doc.Close(); //Close document
   //
   MessageBox.Show("PDF Created!");
}
 
 
 
 
 

gopal krish replied to gopal krish on 23-Jan-12 06:32 AM
HI DIPA..

for me i have used lot of conversions using pdflib.
so i have to use the pdflib in .net4.0. is it possible?
so is it any possible way to use pdflib dll in .net 4.0.

regards
gopal.s
kalpana aparnathi replied to gopal krish on 23-Jan-12 01:37 PM
The 2.0 hosting application just uses them as COM objects and has no idea whether they are native, 2.0, 4.0 or whatever. COM is the common interface that both runtime versions have to implement identically.

The new in-process SxS support in 4.0 means that when the 4.0-based COM object is loaded, it pulls in the required runtime instead of trying to run on the 2.0, so both runtimes are present in the process managing their own objects. Although you can't directly pass CLR objects between them, you can pass COM interfaces, and the CLR transparently wraps your objects in COM interfaces for you.

I don't know if you can make a single interop assembly for both versions to work from. But clearly you could write an interop assembly in C# in 2.0, export it to a .tlb, and then import it into an assembly in 4.0. That gives you two matching interop assemblies describing identical COM interfaces. (Or just build the same C# source in each version's assembly project).