Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've tried to generate PDF files using PD4ml in C#. It is working properly but sometimes I got the error while opening PDF files in Adobe Reader that : 'Adobe Reader could not open file because either it is not a supported file type or because the file has been damaged.'

I've converted my XHTML file to byteArray and then this byteArray is converted in MemoryStream and atlast this stream id rendered into PDF using PD4ml.render()

What I have tried:

I've used stream.flush(),close() and dispose().
Posted
Updated 3-May-16 14:54pm
Comments
ZurdoDev 3-May-16 7:22am    
How can we help?
Richard MacCutchan 3-May-16 8:51am    
You need to look at the actual content of the rendered file (preferably with a hex editor) to see what is wrong with it.
Member 11949463 3-May-16 9:46am    
Thanks for your concern. But this issue is generating very randomly so how would I know whether the file will open properly or not. Because no exception is catched in catch statement. So please guide me.
Sergey Alexandrovich Kryukov 3-May-16 10:06am    
How anyone else would know then? :-)
Nothing is "generating randomly". If a file is invalid, it's always invalid.
—SA
Richard MacCutchan 3-May-16 10:25am    
So please guide me.

I already did so. You need to look inside the 'bad' files to see what is wrong with them, and then work back into your code to find out why.

1 solution

Why not go to the PD4ml website to look for help?
It is their product after all and they do have a support forum pd4ml.com/support • Index page[^]

Also look at their example page. PD4ML Usage Examples - HTML-to-PDF converter for Java and .NET[^]
Maybe there is something you missed to do.
 
Share this answer
 
Comments
Member 11949463 4-May-16 5:56am    
George,I've posted my question on your given link. But my PDF is opening when I generate it second time. So I think there is no problem in my content,Right? And another thing I'm generating PDF from MemoryStream, So there can be any issue regarding memory stream? Because no exception is there.
George Jonsson 4-May-16 6:05am    
Well, I don't have your code, so I cannot know what you have done.
One thing with memory streams is that you might need to set MemoryStream.Position = 0 before you try to access the data.

That it works the second time you generate the document seems weird.
Do you close your app in between or do you just press the "Generate PDF" button in a UI once more?
Member 11949463 24-May-16 3:27am    
yes, I'm pressing button once again to generate PDF.
George Jonsson 24-May-16 3:52am    
So update your question with the relevant code, the code inside the button event method.
And please, please do not post your code here in the comment section.
And next time try to respond a little faster if you want help, now it took 3 weeks!
I had already forgotten this question.
Member 11949463 25-May-16 3:14am    
I've got the reason for the error. When I render the file using pd4ml.Render and create it it is opened somewhere in system. So when I tried to open it through File.open it gives error. So I've a doubt that when I create a file it is created with a lock or not? If no lock is there then I can open it using FileShare.ReadWrite argument in File.Open if I'm not wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900