Problem in open PDF file and extract PDF

 Hi,

My problem is I need to open a PDF file (10 Pages) in new window when the user clicks a button from the parent form. User can enter no of pages to extract from PDF (For Example 1-4). then I have to extract 1st 4 pages from that PDF and the PDF window should show only 6 pages because we have extracted 1st 4 pages. I mean we have to refresh the PDF window.Is there any way to do that in ASP.net?

If I am not clear about this issue please let me know that.

Thanks in advance.

0
sarojothi
2/11/2008 1:49:46 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

18 Replies
1364 Views

Similar Articles

[PageSpeed] 53

to view the pdf file in another page :

 

                Response.ClearContent()
                Response.ClearHeaders()
                Response.ContentType = "application/pdf"
                'szFileName = file's path
                Response.WriteFile(szFileName)
                Response.Flush()
                Response.Close()

 but I can't help you with the extract part...this post talk about extracting plain text :

http://www.codeproject.com/KB/cpp/ExtractPDFText.aspx

but, to extract exactly in pdf, I think you'll need a third party (surely, not free)

http://www.cete.com/Products/Dynamic_PDF_Dot_Net_Products.csp

 

regards,


Kotor2000
0
kotor2000
2/11/2008 8:24:27 PM

Hi Kotor2000,

Thank you very much for your reply.
I am using the below code to open PDF file from my code behind

Shell("C:\Program Files\Internet Explorer\iexplore.exe " & PdfPath.PostedFile.FileName, AppWinStyle.NormalFocus)

It opens PDF in another window.

As you said I am using "PDF4NET" for extraction.

I have extracted No of pages from that PDF using PDF4NET depends on user input as I said in my Example.

Now i need to refresh the PDF in the PDF window so that user can see only remaining page.

How do I do that? Please let me know.
Thanks in advance

0
sarojothi
2/14/2008 3:10:52 PM

Hello sarojothi,

               I didn't work with PDF4NET. It was only a suggestion after a search on google. I suppose that, after the extract, you have another pdf file with only the desired pages. Can't you just send back the file to the user with the same code?

Regards,


Kotor2000
0
kotor2000
2/14/2008 3:43:05 PM

Hi Kotor2000,

You mean one more window with the new PDF? I can do it, but I need to close the old one right? How can I do that? Is there any possiblity to close the Old PDF page? If that's case I can almost done. Please let me know regarding that.

Thanks in advance.

Saravanan

 

0
sarojothi
2/15/2008 2:20:15 PM

Well, I would need to see your code to be sure. I don't know the process used to extract pages from the pdf file. I thought this process occured before the user can visualize the pdf file. The javascript Window.Close() put on client-side will close your page, but it will prompt a message to the user asking if he wants your program to close his window. He might answer no and there's nothing you can do about it.

I would suggest to extract the pages from your pdf file before showing anything to the user, but I didn't use this API of yours and I don't even know if it's possible.

May be you could show your pdf file in a IFRAME giving you spaces on your page to put some controls? With this control, you could code some process on server side to show your new pdf in the same IFRAME...

I'm thinking outloud here and didn't test anything of this, so you'll have to do some test from your end.

Well, keep me posted...

Regards,

 


Kotor2000
0
kotor2000
2/15/2008 5:34:26 PM

I am sending the script which is related to the PDF manipulation
Please go thro it and let me know how to fix this problem

There is a fileupload control
<asp:FileUpload ID="PdfPath" runat="server" />
and a aspx button
 <asp:Button ID="btnOpenPdf" runat="server" Text="Open PDF File" CausesValidation="False" />
and a hiddenfield control
  <asp:HiddenField ID="hdnPDFPath" runat="server" Visible="False" />
and a save button
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />

As soon as user click the fileupload control it opens file dialog there user can browse the file to open the PDF. The path will be stored in hdnPDFPath.
Then user has to click the btnOpenPdf button


Protected Sub btnOpenPdf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenPdf.Click
        If PdfPath.FileName <> "" Then
            hdnPDFPath.Value = PdfPath.PostedFile.FileName
            Shell("C:\Program Files\Internet Explorer\iexplore.exe " & PdfPath.PostedFile.FileName, AppWinStyle.NormalFocus)
            lblPDFPath.Text = hdnPDFPath.Value
        Else
            MsgBox("Select PDF to open", MsgBoxStyle.Critical, "Open PDF file")
        End If
    End Sub

In save button click:
I am calling the following function

  Protected Function CallPDFExtract()
        If hdnPDFPath.Value <> "" Then
            If ddlClientCodeAuto.SelectedValue <> "" And ddlSCACCodeAuto.SelectedValue <> "" Or txtProNo.Text <> "" Then
                Dim iNoOfPage As String
                iNoOfPage = InputBox("Extract No of Pages ", "EXTRACT IMAGE")
                If SendPages(hdnPDFPath.Value, iNoOfPage) = 1 Then
                    MsgBox("Invalid entry. Operation cancelled...", MsgBoxStyle.Critical, "ERROR!")
                    Return 1
                Else
                    Return 0
                End If
            Else
                MsgBox("Select Select Client/SCAC/ProNo missing", MsgBoxStyle.Critical, "Select Client/SCAC/ProNo!")
                Return 1
            End If
        Else
            MsgBox("Select PDF File", MsgBoxStyle.Critical, "Select PDF File!")
            Return 1
        End If
    End Function

    Protected Function SendPages(ByVal sPdfPath As String, ByVal sNoOfPages As String)
        Try
            Dim SourceFile As PDFFileEx = PDFFileEx.FromFile(sPdfPath)
            Dim NoOfPage As PDFImportedPage = Nothing
            Dim DestiFile As New O2S.Components.PDF4NET.PDFDocument
            'Dim i As Integer
            'sNoOfPages
            Dim sPages() As String
            sPages = Split(sNoOfPages, "-")
            If UBound(sPages) > 0 Then
                Dim ilop As Long
                For ilop = sPages(0) - 1 To sPages(1) - 1
                    NoOfPage = SourceFile.ExtractPage(ilop)
                    ' add the page to new document
                    DestiFile.AddPage(NoOfPage)
                Next ilop
            Else
                ' extract the page
                If sNoOfPages = "0" Then
                    SourceFile.Close()
                    Return 0
                    Exit Function
                Else
                    NoOfPage = SourceFile.ExtractPage(sNoOfPages)
                    ' add the page to new document
                    DestiFile.AddPage(NoOfPage)
                End If
            End If
            ' save the document
            Dim sPdfFileName As String
            sPdfFileName = ddlClientCodeAuto.SelectedValue & "_" & ddlSCACCodeAuto.SelectedValue & "_" & txtProNo.Text & ".pdf"
            If File.Exists("
\\images$\SCANS\Test\" & sPdfFileName) Then
                sPdfFileName = Mid(sPdfFileName, 1, Len(sPdfFileName) - 4)
                If File.Exists("
\\images$\SCANS\Test\" & sPdfFileName & "_2.pdf") Then
                    If File.Exists("
\\images$\SCANS\Test\" & sPdfFileName & "_3.pdf") Then
                        If File.Exists("
\\images$\SCANS\Test\" & sPdfFileName & "_4.pdf") Then
                            DestiFile.SaveToFile("
\\images$\SCANS\Test\" & sPdfFileName & "_5.pdf")
                        Else
                            DestiFile.SaveToFile("
\\images$\SCANS\Test\" & sPdfFileName & "_4.pdf")
                        End If
                    Else
                        DestiFile.SaveToFile("
\\images$\SCANS\Test\" & sPdfFileName & "_3.pdf")
                    End If
                Else
                    DestiFile.SaveToFile("
\\images$\SCANS\Test\" & sPdfFileName & "_2.pdf")
                End If

            Else
                DestiFile.SaveToFile("
\\images$\SCANS\Test\" & sPdfFileName)
            End If
            'DestiFile.Save("
\\images$\SCANS\Test\Test.pdf")
            SourceFile.Close()
            Return 0
        Catch ex As Exception
            Return 1
        End Try
    End Function

As soon as user extracted the no of pages it should close the old PDF page and open the Remaining Pdf in a new window.

 


 

0
sarojothi
2/15/2008 7:06:08 PM

Just use the code I previously posted above after your last function:

                Response.ClearContent()
                Response.ClearHeaders()
                Response.ContentType = "application/pdf"
                'szFileName = new pdf file's path
                Response.WriteFile(szFileName)
                Response.Flush()
                Response.Close()

 This will open your new file on the same page than the previous one.

Regards,

 


Kotor2000
0
kotor2000
2/18/2008 3:17:03 PM

Hi Kotor2000,

    Thank you very much. I made some adjustment in the coding it is working now. But I have a problem. When try to open PDF files using the above code most of the PDF file are opening fine, but some of the PDF file as soon as i click the button "openPDF" it says "Page cannot be displayed". It is not even stopping in page load event!

I don't know what was wrong in that PDF files.

Please help me out in this regards

Thanks in advance.

Saravanan

0
sarojothi
2/21/2008 4:22:30 PM

Hmm...I never had such a problem opening PDF files. And the users at my office must do this a hundred times per day...It might be because of your extraction...Is it happening always on the same files (same base files, same extractaction) or it isn't a constant error?  Can you trace the error in debug? When this error occurs, are you able to open the file manually on your computer?

Regards,


Kotor2000
0
kotor2000
2/21/2008 7:57:50 PM

Hi Kotor2000,

  Thanks for the response. I could open the PDF file manually. It happens a only few PDF files NOT the Extraced one and It happens all the time with the same PDF files. I couldn't even debug or trace the error. I don't know why

Please help me out..

Thanks,

Saravanan

0
sarojothi
2/22/2008 1:56:18 PM

found someone who got a similar problem and found the solution

http://www.tek-tips.com/viewthread.cfm?qid=1309619

it suggests that you had the folder containing the pdf files in the virtual directory of your IIS...

All my pdf files generated or stored are kept in  a folder at the root of my web application or in another folder on which ASPNET and NETWORK SERVICE users have right to read, write and modify...

could you validate for me that either

A: You pdf files are kept in a folder at the root folder of your application

or

B: If kept elsewhere, that both ASPNET and NETWORK SERVICE have the necessary rights in the folder

 regards,


Kotor2000
0
kotor2000
2/22/2008 3:36:33 PM

Hi Kotor2000,

  I have to tell you this happened while running the application in VS 2005 itself. I didn't move the code in IIS (Config at IIS) at all and I could open many file within the same folder some of the files are causing this problem. I don't think so that user right causes this problem.

I dont know what to do. My request is I have to open all the files in the folder.

Please let me know any solution for this.

Thanks in advance,

Saravanan

 

0
sarojothi
2/25/2008 3:08:39 PM

Hi Kotor2000,

  I found the solution for that. My files are more than 4 MB in size. That's why. We can increase that in web config in your application as

 <system.web>

<httpRuntime executionTimeout="300" maxRequestLength="51200"/>

</system.web>

Thank you very much for your help indeed.

Thanks,

Saravanan

0
sarojothi
2/25/2008 5:46:56 PM

Hey Saravanan,

               Didn't even thought about the size limit. You have huge PDF files! Smile

Just glad we worked this out.

 Regards,


Kotor2000
0
kotor2000
2/25/2008 7:42:56 PM

Hi kotor2000,
I am having problems that I suspect are caused from IIS 6
You know that I am using Shell command to open PDF. right? It is working in Visual Studio 2005. But when I moved the code to IIS it's not working at all. I mean It doesn't lunch Acrobat.exe and doesn't show the pdf file.

I tried with the following code:

Dim psi As New ProcessStartInfo("C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe")

psi.Arguments = PdfPath.PostedFile.FileName

Process.Start(psi)

It is also not working. I don't know why.
Is there anyway I can allow ASP.NET to run these commands?

Thanks for your time.
Saravanan

 

 

0
sarojothi
2/27/2008 5:56:07 PM

Remember that your software is running on the server, so it is the Acrobat.exe of your server that's being started...

In a web application, you have to send the file to the user with the code I sent you previously...

You're way would work on a windows application...

Sorry, I should have mentionned it earlier, but I was sure that you'd change your code to implement mine...

Regards,


Kotor2000
0
kotor2000
2/27/2008 6:05:14 PM

Hi Kotor2000,

  I found this link. This helped my to open the PDF in Acrobat within the system.

http://support.microsoft.com/kb/895967

But I couldn't open a file from the network. I am working on that. If you have any idea abt that please let me know that.

Thanks in advance,

Saravanan

0
sarojothi
2/28/2008 6:37:06 PM

give rights to your network folder to ASPNET and NETWORK SERVICE users.

regards,


Kotor2000
0
kotor2000
2/28/2008 8:01:50 PM
Reply:

Similar Artilces:

CR 9 for VS.NET PDF problems using web forms
Hi all. I am trying to capture patient history data then summarize the data in a one page report using Crystal Report. I would like to use Adobe Plug-in to alllow for printing the report (although printing from the browser will be acceptable). I am using the code straight off of the web site: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myExportOptions As CrystalDecisions.Shared.ExportOptions Dim myDiskFileDestination As CrystalDecisions.Shared.DiskFileDestinationOptions Dim myExportFile...

Problem with PDF web links embedded in PDF
My firm recently ran an online survey, and the survey allowed users to attach documentation of their answers after answering questions. The completed test arrives as a PDF, and the embedded documentation is also a PDF, but is accessed via a link within the master PDF. But those links to the PDFs won't open when Firefox is my default browser: I have to make IE the default. Otherwise, it just tells me that Acrobat Reader can't open the document within the browser. I've tried changing all the Firefox PDF and Adobe settings to refer PDF documents to Acrobat 8 (which ...

problem in opening pdf file
Name: swanand Product: Firefox Summary: problem in opening pdf file Comments: on opening a .pdf file it shows "not responding" or some times it writes on statusbar "stopped". Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

problems opening pdf-files
Name: Product: Firefox Summary: problems opening pdf-files Comments: Since updating to 3.5.4 repeatetly problems opening PDF-files (like tickets). No change after updating from Reader 9.0 to 9.2. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4 (.NET CLR 3.5.30729) From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

problems opening pdf files
Name: J. Newlin Williams Email: newlinwillatyahoodotcom Product: Firefox Summary: problems opening pdf files Comments: There seems to be a problem when trying to open pdf files, at least on the pa department of revenue and the irs web sites...i keep selection the forms/pubs i need and just get another (blank) mozilla window. When i try to open these files in Microsoft windows exploder, there is no problem. This is a problem as i use the internet extensively for business. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.9) Gecko/20061206 Firefox/1...

problem opening pdf files
Name: bhagirath markand Email: bhagirath_markandathotmaildotcom Product: Firefox Summary: problem opening pdf files Comments: to whom it may concer, every time i try to open a link to pdf file , firefox crashes, then a crash reporting window appears, demanding detail of crash every time i write the problem there including my email. but i had't recieved any kind of usefull information which could prevent this crashing of firefox and loss of data. sir i request you to please do something in this regard. i don't know should i call it bug or anything else. i had al the ...

problem with firefox opening pdf file
hi i am tring to open a pdf file in a frame well it is wrokign fine in IE but when i try to open it in firefox i give me error i think back sllash and front slash prob but i don't know hoe to resovle it   thankx anwar khan anwar_khan: hi i am tring to open a pdf file in a frame well it is wrokign fine in IE but when i try to open it in firefox i give me error i think back sllash and front slash prob but i don't know hoe to resovle it Hi anwar khan, Sorry that I am not familiar with this problem. But after search and search, I think this problem most cause of Fir...

Open form dispaying PDF over web...?
I have a vb.net web app that needs to be able to pop up a second browser window and display a PDF file and two buttons, but I don't know how to load the path of the pdf for display. The PDF files will reside on a network inside a firewall, so I'm wondering - do I have to have a copy of the PDF on the web server to be able to display it?? Also, what control should I use to display the PDF, but allow the ability to add a couple buttons at the bottom of the page (one to close the window, and one to print the pdf file). Does anyone know a good way to do this, or links to examples I can ...

fails opening a PDF file problem
Name: Tom Martineau Email: tomdotmartineauattelusdotcom Product: Firefox Summary: fails opening a PDF file problem Comments: this new version (3.0.1) of FF fails in the download of a PDF file where IE passed. The download progress icon stops at less than half way on repeated attempts. http://books.jvcservice.com/Download/98451797/20885IEN.pdf Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 From URL: http://hendrix.mozilla.org/ ...

Problem with opening PDF files in Firefox
Name: Robert Lewis Email: drbob1137atearthlinkdotnet Product: Firefox Summary: Problem with opening PDF files in Firefox Comments: I am using Acrobat Professional 2002 and ver. 16 of Firefox. PDF files will not open in Firefox unless I either open Acrobat first or access the Web site with Internet Explorer first. Can you suggest a fix? Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16 From URL: http://hendrix.mozilla.org/ ...

Problem opening embedded pdf files
Name: Dr. J.H. McCaughey Email: mccaughe_at_post.queensu.ca Product: Firefox Summary: Problem opening embedded pdf files Comments: Are you aware that the program will not open embedded pdf files cleanly. Rather, when opening a pdf, the browser will hang and will eventually have to be closed and restated. Because I have occasion to open such files on a regular basis, the use of Firefox is becoming a hindrance. Is there a setting that I have missed or is this an error in your browser? Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508...

PDF File Not Opening In Web Browser
I'm trying to open a PDF file in my web browser. I get the open/save dialog box and when I click open it just open Adobe Acrobat Reader, it won't display in my browser. If (file.Exists) Then Response.Clear() Response.AddHeader("Content-Disposition", _ "attachment; filename=" + file.Name) Response.AddHeader("Content-Length", file.Length.ToString()) Response.ContentType = "application/pdf" Response.WriteFile(file.FullName) Response.Flush() Response.End() End If Thanks for the help Brandon W. Hi, ...

Problem opening links to pdf files
Name: David Keen Email: daviddotkeen1attalktalkdotnet Product: Firefox Summary: Problem opening links to pdf files Comments: When I click on a link that is to a pdf document quite often there is a long delay, and then a message box appears saying there is a problem, with 3 buttons. The one marked "Switch to" does the trick, and the document opens, but is this normal? It is certainly a nuisance, as often the message box does not appear for a considerable time, and often it does not appear on top of other windows, so I have to go searching for it with Alt-Tab to u...

Open a PDF file in a web screen
Using C#, I am trying to open a PDF file.  I tried to use numerous examples from asp.net but nothing has worked.  Does anyone have any examples of what I might try?  Thanks for the help.  var newWindow;          function OpenDocumentInNewWindow(url)  {         if(newWindow != null) newWindow.close();         newWindow = window.open(url, 'Window' , "width=800, height=550, toolbar=no, scrollbar=yes, resizable=yes");  } make sure to return f...

Web resources about - Problem in open PDF file and extract PDF - asp.net.web-forms

Is–ought problem - Wikipedia, the free encyclopedia
The is–ought problem in meta-ethics as articulated by Scottish philosopher and historian David Hume (1711–76) is that many writers make claims ...

More to Slater & Gordon's problems than just the UK
As Slater &amp; Gordon comes under increasing pressure, questions are being asked when the company's problems actually began.

This one app could solve your most frustrating home Wi-Fi problems
So you've just set up your home Wi-Fi network but for some reason you're having trouble getting your PC to connect to the network. It could very ...

Merkel-Enhanced Migration Problem: Million Refugees Hit Europe, 80% Through Greece by Boat; Turkish Mafia ...
... made their way to Europe this year. Every country is complaining now, even Germany. So why isn't anything concrete being done? Why the Problem ...

This 1-minute visualization on space junk reveals a serious problem
... will completely obliterate a satellite and turn it into hundreds of smaller pieces. As you can imagine, this only exacerbates the problem because, ...

Oakland Airport On Alert; Southwest Flight Encounters Problem
CBS Local Oakland Airport On Alert; Southwest Flight Encounters Problem CBS Local FORT LAUDERDALE, FL - SEPTEMBER 27: A Southwest airplane ...

Southwest flight reports gear problem, burns fuel before landing attempt
Crews at Oakland International Airport are standing by on "yellow alert" for return of Chicago-bound flight

Far from smelling like a Rose, Bulls' problems go deeper than chemistry
There is a lot of chemistry talk circulating about the suddenly floundering Bulls, but Chicago's problems go much deeper than that.

Engine problem sends Virginia-bound plane back to New York
... shortly after takeoff. A spokesman for the FAA says the crew of Commutair Flight 3585 declared an emergency because of an "engine-related problem" ...

IT pros brace for lost devices, access problems, on-call holidays
More than half (56%) of IT pros will be on-call or working during the holidays to troubleshoot tech problems, according to network management ...

Resources last updated: 12/27/2015 1:30:53 AM