PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 4:01 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Wed Jul 07, 2010 11:51 am 
Offline

Joined: Wed Jul 07, 2010 11:17 am
Posts: 9
Hi all,

I'm new to PDFSharp & MigraDoc. After playing with it for the past couple of weeks I find it to be one of the strongest .NET PDF libraries (open source) out there! It totally rocks!!!

Now for business...

We are using the WPF versions of the PDFSharp & MigraDoc assemblies (not the GDI+ ones).

We have a requirement to export PDF pages as images (full size, thumbnails etc.), JPEG format is preferred. I know that PDFSharp & MigraDoc do not have this ability (opening a PDF file and saving the pages as images), but I've seen the GhostScript example, compiled it successfully and ran it. I, of course, added the file 'gsdll32.dll' to the working directory of the example (bin\Debug or bin\Release).

The Demo failed (and still fails) with the following exception (the error is coming from within the 'gsdll32.dll' file):

Code:
{System.InvalidOperationException: Ghostscript failed with error code -100.
   at PdfSharp.Ghostscript.GS.PdfToPng(String filename, Int32 page, Int32 resolution) in C:\Users\omri\Documents\Visual Studio 2010\PDFsharp\code\PdfSharp.Ghostscript\Ghostscript\GS.cs:line 212
   at UseGhostscript.Program.Main()
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()}



We did not find and solution to it during the past days.
We initially thought it's related to the WPF build, but the GDI+ build results in the same exception.

We are using Windows 7 & Windows server 2K8.

If anyone encountered the same issue and resolved it - please share.

Thanks,


Omri


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 07, 2010 12:14 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Maybe this thread will help:
viewtopic.php?p=523&sid=7a69f20b8d17f6ab53fefb3c1da8dcce#p523

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 07, 2010 12:46 pm 
Offline

Joined: Wed Jul 07, 2010 11:17 am
Posts: 9
Thanks Thomas,

I've read that thread already, but it did not solve the problem.
I installed GhostScript on the PC (version: 8.71), copied the dll file to the working directory of the project (otherwise, the DllNotFound exception is thrown) but still, the following call returns -100 (minus 100):
Code:
Api.gsapi_init_with_args(GS.instance, args.Count, (string[])args.ToArray(typeof(string)))


I'm sure that I'm doing something wrong here, but I just cannot find what it is.

Any additional help?

Omri


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 07, 2010 3:53 pm 
Offline

Joined: Wed Jul 07, 2010 11:17 am
Posts: 9
Attached is the screenshot of Visual Studio 2008 with the exception.


Attachments:
Untitled.jpg
Untitled.jpg [ 218.29 KiB | Viewed 10798 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 07, 2010 5:26 pm 
Offline
Supporter
User avatar

Joined: Thu May 27, 2010 7:40 pm
Posts: 59
Location: New Hampshire, USA
Can you supply the full stack trace? That may provide better clues. Click on the "Copy exception details to the clipboard" to get that...


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 07, 2010 6:58 pm 
Offline

Joined: Wed Jul 07, 2010 11:17 am
Posts: 9
This is the (managed) StackTrace.

Code:
System.InvalidOperationException was unhandled
  Message="Ghostscript failed with error code -100."
  Source="PdfSharp.Ghostscript"
  StackTrace:
       at PdfSharp.Ghostscript.GS.PdfToPng(String filename, Int32 page, Int32 resolution) in C:\Users\OMRI\Desktop\PDFsharp\code\PdfSharp.Ghostscript\Ghostscript\GS.cs:line 214
       at UseGhostscript.Program.Main() in C:\Users\OMRI\Desktop\PDFsharp\dev\PdfSharp.Ghostscript.Demo\Program.cs:line 57
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: <<none>>


This is the native stack (Taken from DebugDiag, crash rule). I did not have the PDB file of the GS dll file... But, you can see that the managed exception is 'System.BadImageFormatException':
Code:
Thread 0 - System ID 2140
Entry point   UseGhostscript!COM+_Entry_Point (UseGhostscript+0x3fee)
Create time   7/7/2010 21:48:10
Time spent in user mode   0 Days 0:0:0.15
Time spent in kernel mode   0 Days 0:0:0.15



Function     Arg 1     Arg 2     Arg 3   Source
KERNELBASE!RaiseException+58     e0434f4d     00000001     00000001   
mscorwks!RaiseTheExceptionInternalOnly+2a8     02476c64     00000000     00000000   
mscorwks!UnwindAndContinueRethrowHelperAfterCatch+70     003aefc8     0047a0f8     91d66dae   
mscorwks!PreStubWorker+160     003aefc8     90e1074f     00000000   
0x0025083e     0000000e     003af034     00000000   
mscorwks!ThreadNative::Sleep+45     67fe1b6c     00000000     02476c44   
0x006300c3     003af0ac     00000000     003af0f0   
mscorwks!CallDescrWorker+33     003af140     00000000     003af110   
mscorwks!CallDescrWorkerWithHandler+a3     003af140     00000000     003af110   
mscorwks!MethodDesc::CallDescr+19c     0018c030     003af2f4     003af2c0   
mscorwks!MethodDesc::CallTargetWorker+1f     0018c030     003af2f4     003af2c0   
mscorwks!MethodDescCallSite::CallWithValueTypes_RetArgSlot+1a     003af2c0     91d671f6     00000000   
mscorwks!ClassLoader::RunMain+223     001832cc     00000001     003af3fc   
mscorwks!Assembly::ExecuteMainMethod+a6     00000000     91d678ce     00000001   
mscorwks!SystemDomain::ExecuteMainMethod+456     10600000     00000000     91d6797e   
mscorwks!ExecuteEXE+59     10600000     91d679a6     00000000   
mscorwks!_CorExeMain+15c     68071137     003afbac     73cc7f16   
mscoreei!_CorExeMain+38     00000000     70b80000     003afbc0   
mscoree!ShellShim__CorExeMain+99     00000000     77453677     7efde000   
mscoree!_CorExeMain_Exported+8     7efde000     003afc00     77e29d42   
kernel32!BaseThreadInitThunk+e     7efde000     76d859f1     00000000   
ntdll!__RtlUserThreadStart+70     73cc4ddb     7efde000     00000000   
ntdll!_RtlUserThreadStart+1b     73cc4ddb     7efde000     00000000   




In UseGhostscript__PID__1948__Date__07_07_2010__Time_09_49_10PM__816__Second_Chance_Exception_E0434F4D.dmp the assembly instruction at KERNELBASE!RaiseException+58 in C:\Windows\SysWOW64\KERNELBASE.dll from Microsoft Corporation has caused a CLR Exception of type (System.BadImageFormatException) on thread 0




Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 08, 2010 1:02 pm 
Offline

Joined: Wed Jul 07, 2010 11:17 am
Posts: 9
After sitting all day on this, I still couldn't make it work.
The -100 return value still exists.

I've tried the following, nothing worked:
1) Specific OS: WinXP, Win server 2003 & 2008, 32bit & 64bit build.
2) Tried building the Dlls with Visual Studio 2008 & 2005, also 2010. GDI+ & WPF builds.
3) Tried building GS from source code.

Can someone please help here?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 09, 2010 4:28 pm 
Offline
Supporter
User avatar

Joined: Thu May 27, 2010 7:40 pm
Posts: 59
Location: New Hampshire, USA
Omri,

Yes, I imagine this is frustrating. In the Project settings for this project (in the Debug tab), try unchecking the "Enable the visual studio hosting process".
That should change the call stack some, and maybe offer some different clues?

Also is there possibly any issue with the assembly signing? (this is an off-the-cuff remark, haven't thought this one through)

I could try this myself, but I don't have the Ghostscript dll handy right now and am not sure offhand what's involved in getting to the point where you are.

-Jeff

PS: One more thought here. Since you have the GS source, maybe instead of referencing the dll you built, try including and referencing the GS project. Then maybe you can step into that call and see more details about what's failing. BTW, since you have the GS source, maybe you can look at where this
"-100" failure is originating?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 12, 2010 11:18 am 
Offline

Joined: Wed Jul 07, 2010 11:17 am
Posts: 9
Hi,

Thanks for trying.

I tried to debug the GS code with the source, with no luck. Breakpoints are not being called. The Debug build of GS does not work at all (the Dll is not loaded - an error occurs with an access violation).

I'm so frustrated... I've been working of more than a week just to make the GS example work, but still the GS function returns -100.

I'm starting to believe that PDFSharp, although it's fantastic API, is just too immature... Hope I'll be wrong.

Does anyone know of other Open source projects which can create an image from a PDF page?

Omri


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 12, 2010 1:18 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
omrisela wrote:
I'm starting to believe that PDFSharp, although it's fantastic API, is just too immature... Hope I'll be wrong.

PDFsharp does not render PDF, it never did - and most likely it never will.
Calling GS works for us. And we include sample code that calls this 3rd party component.

I have no clue why it doesn't work for you.

Have you tried a different GS version?
Newer isn't always better and maybe it helps to use an older version.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 12, 2010 2:13 pm 
Offline
Supporter
User avatar

Joined: Thu May 27, 2010 7:40 pm
Posts: 59
Location: New Hampshire, USA
If you wanted to zip up the folder tree containing the PdfSharp/MigraDoc/GS source code AND the solution file you're using to test this, I'll look at it for you.

Usually when your breakpoints aren't being hit, this is an indication that the DLL is being loaded from the GAC or elsewhere and not the one you built.

-Jeff


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 13, 2010 11:45 am 
Offline

Joined: Wed Jul 07, 2010 11:17 am
Posts: 9
Thomas Hoevel wrote:
omrisela wrote:
I'm starting to believe that PDFSharp, although it's fantastic API, is just too immature... Hope I'll be wrong.

PDFsharp does not render PDF, it never did - and most likely it never will.
Calling GS works for us. And we include sample code that calls this 3rd party component.

I have no clue why it doesn't work for you.

Have you tried a different GS version?
Newer isn't always better and maybe it helps to use an older version.



I know that PDFSharp is not able to (and was not or will not be able to) render PDF pages, but I do expect for a Demo to work, even if it uses a 3Party library.

I tried the 5 last GS version, with no success.

I decided to leave this, it already consumed close to 90% of my time and only made me even more frustrated.

I'm sure, with time, I'll get back to it.

Thanks!

Omri


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 19, 2010 1:12 am 
Offline

Joined: Mon Oct 18, 2010 11:50 pm
Posts: 1
i had the same error; gs wasn't finding the pdf file...

mark


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 390 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group