Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
I have made a Windows desktop application(in C#) where I use the AxAcroPDF control to display a pdf-file on a form when user give the path of the pdf and click a button. Pdf-file is located in one network shared file folder where multiple users can access it.
(I use the LoadFile() Method of the object AxAcroPDFLib.AxAcroPDF)

This is working fine. But when the same pdf file which my applications try to open is already opened using Adobe Reader then my application can’t open the same pdf file.

If the PC my application installed has Adobe reader 7 then application throw the error message as "System.ApplicationException Failed Loading PDF Template" and application freeze.

And if the application running PC’s having Adobe Reader X installed then no error will appear but the loading screen appears for ever.

But opening the same pdf simultaneously in two or more PC using my application works perfect.

Can someone help me out on this issue?
Posted
Updated 17-Jul-12 19:18pm
v3
Comments
[no name] 17-Jul-12 11:35am    
Do you think that possibly the errors that you are getting and the code that you are using to perform this action is sort of, kind of, need to know information in order for someone that can't see your screen or read your mind to help you? That is if you were really serious about getting help.

I couldn't find a proper solution as I was expecting to find. But to avoid the program get crash, I put a check before loading the pdf.

C#
bool PDFAvailable = axAcroPDF1.LoadFile(PDFPath.ToString());


If the Boolean variable 'PDFAvailable' return true I'll load the PDF like below. Else a proper message is thrown.

C#
bool PDFAvailable = axAcroPDF1.LoadFile(PDFPath.ToString());
                       
                       if (PDFAvailable == true)
                       {
                           axAcroPDF1.LoadFile(PDFPath.ToString());
                           axAcroPDF1.setShowToolbar(false); //disable pdf toolbar.
                           axAcroPDF1.Enabled = true;
                           
                       }
                       else
                       {
                           MessageBox.Show("Selected PDF Template Is Locked By Another Application.", ""Test Application"", MessageBoxButtons.OK, MessageBoxIcon.Information);
                           
                       }
 
Share this answer
 
Comments
mbov 9-Dec-20 2:38am    
One note:
The initialization of the axAcroPDF1 has to be completed before the PDFAvailable check, otherwise you'll get a COM Error. If you need to open PDF directly after initialization, End it manually with axAcroPDF1.EndInit()

If you don't check PDFAvailable before actually loading, EndInit() is not needed.
I found a workaround in this post
Rather than LoadFile() we can use the "src" property of the control.
 
Share this answer
 
using src property to define the path can also generate an error if path is too long.
One solution is to copy file to a shorter path file and then modify src with this new path.

File.Copy(iRec.Path, "C:\\temp\\a.pdf",true);
Thread.Sleep(500);
axAcroPDF1.src = "C:\\temp\\a.pdf";

Any other solution?
 
Share this answer
 

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