Welcome Guest Search | Active Topics | Sign In | Register

Saving then Opening PDF with Process Options
Tyler
Posted: Friday, August 9, 2013 6:01:17 PM
Rank: Member
Groups: Member

Joined: 7/11/2013
Posts: 11
I have a PDF document that is created by merging many other documents together. After it is created it needs to be opened. Currently my method for this is as shown below:

Code: C#
doc.Save("C:\\Forms.pdf");

            Process process = new Process();
            process.StartInfo.UseShellExecute = true;
            process.StartInfo.FileName = "C:\\Forms.pdf";
            process.Start();


I think the PDF is being opened by the process before doc.Save() finishes but after the PDF has actually been saved so I am getting an IOException which says "The process cannot access the file 'C:\Forms.pdf' because it is being used by another process." Is there a way I can make it wait before I open the PDF or is there a different method I could use? I noticed I could use a stream argument as well for PdfDocument.Save() but I don't know much about streams. Opening as a download in the browser would be an option too but again I don't know a lot about how to do that either. Any help would be appreciated. Thanks in advance!
eo_support
Posted: Friday, August 9, 2013 6:09:45 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

You probably got it backwards. PdfDocument.Save closes the file before it returns. So there is no problem when you run the code for the first time.

However, if you run the code for once, leaving Adobe Reader open, then try to run the same code again, then PdfDocument.Save will not be able to open the same file to write (because it's open by Adobe Reader) and you will get the above problem.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.