Appreciate anyone can help. Thanks in advance.
Dim provider As New Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider
Using input As System.IO.Stream = System.IO.File.OpenRead("C:\WebSite2\pdf001.pdf")
Dim document As Telerik.Windows.Documents.Fixed.Model.RadFixedDocument = New Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider(input, FormatProviderSettings.ReadOnDemand).Import()
For i As Integer = 0 To document.Pages.Count - 1
Dim exportProvider As New Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider
Using out As System.IO.Stream = System.IO.File.OpenWrite("C:\WebSite2\Page" & i.ToString & ".pdf")
Dim outputDocument As New Telerik.Windows.Documents.Fixed.Model.RadFixedDocument
Dim page As RadFixedPage = New RadFixedPage()
page = document.Pages(i)
outputDocument.Pages.Add(page)
exportProvider.Export(outputDocument, out)
End Using
Next
End Using
Exception:
System.ArgumentException was unhandled by user code
HResult=-2147024809
Message=The document element is associated with another parent.
Parameter name: item
ParamName=item
Source=Telerik.Windows.Documents.Fixed
15 Answers, 1 is accepted
Thank you for contacting us.
There are a few changes I would suggest to the code snippet you have sent:
- When importing a PDF file in PdfProcessing you should be using the constructor shown in this documentation article. You may find more detailed information about the difference in PdfFormatProvider's constructors in this link to Telerik's forums.
- Before adding the RadFixedPage to the new RadFixedDocument instance you should first remove the page from the old document Pages collection. This way you will not get the exception that "The document element is associated with another parent.".
I hope this is helpful. If you have any other questions or concerns please do not hesitate to contact us again.
Regards,
Deyan
the Telerik team
I was first trying to use the sample code but the following code can't read the contain of the pdf, the caret position show object not reference to an object error.
Dim document As Telerik.Windows.Documents.Fixed.Model.RadFixedDocument = provider.Import(input)
Dim document As Telerik.Windows.Documents.Fixed.Model.RadFixedDocument = New Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider(input, FormatProviderSettings.ReadOnDemand).Import()
After i remove the page from the original pdf and attach to the new output document, the new pdf generated show an empty page with This document was generated by a trial version of Telerik RadPdfProcessing.
Below is the modified code
Dim provider As New Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider
Using input As System.IO.Stream = System.IO.File.OpenRead("C:\WebSite2\082.pdf")
'Dim document As Telerik.Windows.Documents.Fixed.Model.RadFixedDocument = provider.Import(input)
Dim document As Telerik.Windows.Documents.Fixed.Model.RadFixedDocument = New Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider(input, FormatProviderSettings.ReadOnDemand).Import() 'provider.Import(input)
Dim j As Integer = 1
For i As Integer = 0 To document.Pages.Count - 1
If i = document.Pages.Count Then
Exit For
End If
Dim exportProvider As New Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider
Using out As System.IO.Stream = System.IO.File.OpenWrite("C:\WebSite2\Page" & j.ToString & ".pdf")
Dim outputDocument As New Telerik.Windows.Documents.Fixed.Model.RadFixedDocument
Dim page As RadFixedPage = document.Pages(i)
document.Pages.Remove(page)
outputDocument.Pages.Add(page)
exportProvider.Export(outputDocument, out)
i -= 1
j += 1
End Using
Next
End Using
I am attaching a sample project that shows how to get the pages from two different PDF files and merge them into a single pdf. A few words about the project:
- The project contains a singe WebForm with a button in it.
- It also contains two PDF files - Ellipses.pdf and Rectangles.pdf.
- When pressing the button the two files are imported with a PdfFormatProvider. The pages from the imported documents are added to a new RadFixedDocument instance. The new document is being exported and downloaded as MergedDocument.pdf.
I am looking forward to contacting you again.
Regards,
Deyan
the Telerik team
Thank you for sending us the sample document.
The received file uses features that are still not supported by RadPdfProcessing. As mentioned in this forum post currently RadPdfViewer and RadPdfProcessing share the same public API, but internally their models are still differing. This is the cause of the different behaviour when using different PdfFormatProvider constructors.
As PdfProcessing is under active development we are planning to unify both models soon, so that RadPdfProcessing supports all features supported by RadPdfViewer.
If you have any further questions do not hesitate to contact us again.
Regards,
Deyan
the Telerik team
That's correct, the current version of RadPdfProcessing cannot open the file you have sent because of still not supported features used in the PDF document. We are working on extending the features for our next couple of releases.
Regards,
Deyan
the Telerik team
Hello, I was having similar issues and wondered if this will be fixed in the next release that is coming soon.
Thanks!
We are working on improving RadPdfProcessing import and we have already implemented a lot of new functionalities. However, it still has missing functionalities compared to RadPdfViewer. Could you send us the PDF document you are testing with, so that we can investigate the concrete issue you are facing?
Regards,
Deyan
the Telerik team
Hi
I have a VB.Net 4.5 solution and I'm having trouble using this code. As far as I can tell the import statement
Imports Telerik.Windows.Documents.Fixed.FormatProviders.Pdf
Imports Telerik.Windows.Documents.Fixed.Model
does not work because the 4.5 dll's does not contain the same code as the 4.0 ones that this example uses.
Reference to Telerik.Windows.Documents.Fixed, .Zip and .Core are ok.
Can you confirm this?
Is this a bug or by design? How should this be done in 4.5?
regards
Alexander Moan
I have a VB.Net 4.5 solution and I'm having trouble using this code. As far as I can tell the import statement
Imports Telerik.Windows.Documents.Fixed.FormatProviders.Pdf
Imports Telerik.Windows.Documents.Fixed.Model
does not work because the 4.5 dll's does not contain the same code as the 4.0 ones that this example uses.
Reference to Telerik.Windows.Documents.Fixed, .Zip and .Core are ok.
Can you confirm this?
Is this a bug or by design? How should this be done in 4.5?
regards
Alexander Moan
I have tried to reproduce the issue by using Telerik binaries for .Net 4.5 and by changing the previosly sent demo target framework to .Net 4.5. By doing this the application is running correctly without any compile errors. Could you please check in your Visual Studio Project that when you right click and select "Properties" -> "Application" -> "Target framework" the value is ".NET Framework 4.5"?
If you still experience any issues do not hesitate to write again.
Regards,
Deyan
the Telerik team
Hi Deyan,
I had problems making the demo run yesterday, but today I got it working and were able to reproduce that it works for .Net 4.5.
After a bit of searching I found out that I had missed a reference, even if I said I did not. As usual it was my own fault....
Thanks for Your time and for kicking me in the right direction.
regards
Alexander