|
Rank: Newbie Groups: Member
Joined: 3/2/2012 Posts: 9
|
to all -
have a quick question. We have a bunch of pdf documents on a server that are indexed. The user can retrieve all the PDF dcouments via a search engine. The results are displayed in a gridview with a checkbox that allows the user to select the documents to merge into one pdf file for viewing. I can process the checkboxes in asp.net/vb using a for each row section. but i need to create the PDF object each iteration thru the loop. The example i found on the website seems to have each document already defined - but i need to dynamically add the pdf's via the loop.
Is this possible? Here is a code snippit of what i am trying to do:
For Each row As GridViewRow In gridviewDocuments.Rows If (CType(row.FindControl("check_AddToBundleCart"), CheckBox).Checked = True) Then strDocumentID = CType(row.FindControl("DocID"), TextBox).Text results.Text = strDocumentID & " " strSQL = "select [DocPath], [DocFileName] from [DocIndex] where DocID = " & strDocumentID
cmd = New SqlCommand(strSQL, Conn) cmd.CommandType = CommandType.Text
Dim MyAdapter As New SqlDataAdapter() Dim ds_Order As New DataSet
MyAdapter.SelectCommand = cmd MyAdapter.Fill(ds_Order, "MyTable_Order") pdfFileName = "d:\folder\data\" & ds_Order.Tables(0).Rows(0).Item("DocPath") & "\" & ds_Order.Tables(0).Rows(0).Item("DocFileName") doc = "doc" & intCounter
'''' here is where i would create the NEXT document object .... Dim doc(intCounter) As New PdfDocument(pdfFileName)
MyAdapter.Dispose() intCounter += 1
End If Next row
'Merge them into a single PdfDocument Dim mergedDoc As PdfDocument = PdfDocument.Merge(doc(intCounter), doc(intCounter+1), doc(intCounter+2) .... and so on)
any help would be appreciated.
Thanks,
Emil
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, I am not exactly sure if I understand your question correctly. If you are just looking to merge a list of PdfDocument objects, you can do it like this:
Code: Visual Basic.NET
Dim docList As New ArrayList()
'Add some documents into the list. You will need to change
'the following code into a loop
docList.Add(New PdfDocument(fileName1))
docList.Add(New PdfDocument(fileName2))
'Merge them
Dim mergedDoc As PdfDocument = PdfDocument.Merge(docList.ToArray())
The key is when you call PdfDocument.Merge, you can pass an array instead of passing each one of them as a separate argument. Hope this helps. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 3/2/2012 Posts: 9
|
thanks for the update - yes - you gave me exactly what i need. here is my code behind now:
Dim docList As New ArrayList()
For Each row As GridViewRow In gridviewDocuments.Rows If (CType(row.FindControl("check_AddToBundleCart"), CheckBox).Checked = True) Then strDocumentID = CType(row.FindControl("DocID"), TextBox).Text
strSQL = "select [DocPath], [DocFileName] from [DocIndex] where DocID = " & strDocumentID
cmd = New SqlCommand(strSQL, Conn) cmd.CommandType = CommandType.Text
Dim MyAdapter As New SqlDataAdapter() Dim ds_Order As New DataSet
MyAdapter.SelectCommand = cmd MyAdapter.Fill(ds_Order, "MyTable_Order") pdfFileName = "d:\national\data\" & ds_Order.Tables(0).Rows(0).Item("DocPath") & "\" & ds_Order.Tables(0).Rows(0).Item("DocFileName")
docList.Add(New PdfDocument(pdfFileName)) pdfFileName = "" MyAdapter.Dispose()
End If Next row
Dim mergedDoc As PdfDocument = PdfDocument.Merge(docList.ToArray())
'HttpResponse(Response = HttpContext.Current.Response) Response.Clear() Response.ClearHeaders() Response.ContentType = "application/pdf"
mergedDoc.Save(Response.OutputStream)
however, when i run the web app - i receive this error:
BC30311: Value of type '1-dimensional array of Object' cannot be converted to 'EO.Pdf.PdfDocument'.
Do I need a newer version of EO? i believe i have 2012.2.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, I am sorry. Please use List<PdfDocument> instead of ArrayList. So it will be something like this:
Code: Visual Basic.NET
Dim docList As New List(Of PdfDocument)()
The rest are the same. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 3/2/2012 Posts: 9
|
one last question - and i do appreciate the help. been working on this for days! when i process the list i receive this error:
Exception Details: System.Exception: An fill-in form field must have a Name.
Source Error:
Line 100: Next row Line 101: Line 102: Dim mergedDoc As PdfDocument = PdfDocument.Merge(docList.ToArray()) Line 103:
i do not want to save it ... just output the stream like this to the browser window:
Response.Clear() Response.ClearHeaders() Response.ContentType = "application/pdf"
mergedDoc.Save(Response.OutputStream)
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
Please try with the latest build. Our early versions requires that each PDF form field to have a name. However the latest version no longer requires it. So the latest version should fix the problem for you.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 3/2/2012 Posts: 9
|
hello - upgraded to the latest build and everything works perfectly. thanks for the help.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Glad to hear that and thank you very much for your business! Please feel free to let us know if there is anything else.
|
|