Need help on PDF split and merge

16 posts, 1 answers
  1. tchuat
    tchuat avatar
    5 posts
    Member since:
    Oct 2014

    Posted 22 Oct 2014 Link to this post

    I am tryping to split pages from original pdf and save it as an individual pdf. No luck with the following code
    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
     














  2. Pedro
    Pedro avatar
    2 posts
    Member since:
    Oct 2014

    Posted 23 Oct 2014 Link to this post

    Can you add a screenshot?
    _______________
    mobile game hack
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Deyan
    Admin
    Deyan avatar
    135 posts

    Posted 27 Oct 2014 Link to this post

    Hello,

    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
  5. tchuat
    tchuat avatar
    5 posts
    Member since:
    Oct 2014

    Posted 27 Oct 2014 in reply to Deyan Link to this post

    Thanks for your prompt reply.
    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)
    So I change to the following code and it work
    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

  6. Deyan
    Admin
    Deyan avatar
    135 posts

    Posted 28 Oct 2014 Link to this post

    Hello,

    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.
    As for the import errors that you have mentioned - they may be caused by the specific PDF document you are importing. Could you please send us the document you are importing so that we can further investigate the issue causing the exception?

    I am looking forward to contacting you again.

    Regards,
    Deyan
    the Telerik team
  7. tchuat
    tchuat avatar
    5 posts
    Member since:
    Oct 2014

    Posted 29 Oct 2014 in reply to Deyan Link to this post

    Thanks for your prompt reply. The attach files does not allow me to attach pdf, so I had uploaded to https://www.sendspace.com/file/01cxvb
  8. Deyan
    Admin
    Deyan avatar
    135 posts

    Posted 29 Oct 2014 Link to this post

    Hello,

    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
  9. tchuat
    tchuat avatar
    5 posts
    Member since:
    Oct 2014

    Posted 29 Oct 2014 in reply to Deyan Link to this post

    Does this mean current version of the pdf library in telerik is not support to split (or open) my pdf?
  10. Answer
    Deyan
    Admin
    Deyan avatar
    135 posts

    Posted 30 Oct 2014 Link to this post

    Hello,

    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
  11. tchuat
    tchuat avatar
    5 posts
    Member since:
    Oct 2014

    Posted 30 Oct 2014 in reply to Deyan Link to this post

    Thanks. Looking forward for the new release.
  12. Brian
    Brian avatar
    6 posts
    Member since:
    Apr 2016

    Posted 05 May Link to this post

    Hello, I was having similar issues and wondered if this will be fixed in the next release that is coming soon.

    Thanks!

  13. Deyan
    Admin
    Deyan avatar
    135 posts

    Posted 10 May Link to this post

    Hello Brian,

    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
  14. Alexander
    Alexander avatar
    14 posts
    Member since:
    Oct 2007

    Posted 06 Jun in reply to Deyan Link to this post

    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

  15. Alexander
    Alexander avatar
    14 posts
    Member since:
    Oct 2007

    Posted 06 Jun in reply to Deyan Link to this post

    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
  16. Deyan
    Admin
    Deyan avatar
    135 posts

    Posted 07 Jun Link to this post

    Hello Alexander,

    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
  17. Alexander
    Alexander avatar
    14 posts
    Member since:
    Oct 2007

    Posted 07 Jun in reply to Deyan Link to this post

    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

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017