There are multiple root elements

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v9)  /  Re: There are multiple root elements

DynamicPDF CoreSuite for .NET (v9) Forum

 Apr 05 2018 7:56 AM
Hello,

i appended multiple PDFs to a merge document and while executing the draw function i get the error message:

There are multiple root elements. Line 2, position 2.

What does that mean and how can i avoid this error, or how can i find out which of the PDFs is causing this problem?
 Apr 05 2018 12:26 PM
Posted by a ceTe Software moderator
Hello,

Please send over the following details to support@cete.com so we can look into it further?

1.        Source/input PDFs used for merging.
2.        Code sample which uses static data to recreate the error.
3.        Full error message along with stack trace.
4.        Exact version and build number of the DynamicPDF DLL file. You can get this information by right clicking on the DynamicPDF DLL file>>Properties> Details tab. You can also send over the screenshot showing all the information on Details tab.

In order to find out the problematic PDF, you will need to append PDFs one by one and run the application until you get the error.

Thanks,
ceTe Software Support Team.
 May 08 2019 11:05 AM
Is there an update to this issue?  I'm running into this same error in v10.10:

System.Xml.XmlException: There are multiple root elements. Line 2, position 2.
   at zz93.cb.a(String A_0, XmlException A_1)
   at zz93.cb.Draw(DocumentWriter writer)
   at ceTe.DynamicPDF.IO.DocumentResourceList.a(DocumentWriter A_0)
   at zz93.b1.Draw()
   at ceTe.DynamicPDF.Document.Draw(Stream stream)

I'm going to upgrade to v10.11 to see if the issue is resolved.
 May 08 2019 12:57 PM
Posted by a ceTe Software moderator
Hello,
 
Please try creating MergeOptions class object and set the XmpMetadata Boolean property of it to false and apply this merge options while merging or appending the PDF documents and see if it works for you. Below is the code sample.

            MergeDocument document = new MergeDocument();
            MergeOptions options = new MergeOptions();
            options.XmpMetadata = false;
            document.Append("C:\Temp\DocumentA.pdf", options);
            document.Draw(@"C:\Temp\Mydocument.pdf");

If you continue getting the error even after setting the MergeOptions while merging then please send over the following details to support@dynamicpdf.com so we can look into it further.
1.        Input PDFs used for merging.
2.        Code sample to recreate the error.
3.        Exact version and build number of the DynamicPDF DLL being used in the application. You can get this information in DLL references properties (Version and Description fields) in Visual Studio.
4.        Full error message along with stack trace.
 
Thanks,
ceTe Software Support Team
 May 08 2019 1:53 PM
Setting XmpMetadata = false does fix the issue.

I will add a validation method to test that the XMP Metadata has a valid XML structure and set the merge option accordingly or is that already built in somewhere?
 May 09 2019 9:21 AM
Posted by a ceTe Software moderator
Hello,
 
There is no option available in DynamicPDF Merger API to dynamically validate xmp metadata in a PDF. You could catch the System.Xml.XmlException however.
 
You can read and update xmp metadata using version 9 and later DynamicPDF Merger product. Below is the code sample to read xmp meta date from an existing PDF:
 
            PdfDocument pdf = new PdfDocument(@"C:\Temp\MyDocument.pdf");
            string xmpString = pdf.XmpMetadata;
           
 
You can add new xmp meta data to the PDF using XmpMetadata property of MergeDocument class. Below is the code sample. If you are wanting to add custom metadata then you will need to build respective schemas and add it to the XmpMetaData object. You can refer to the documentation on adding new xmp metadata to the PDF here.
 
            PdfDocument pdf = new PdfDocument(@"C:\Temp\MyDocument.pdf");
            MergeOptions options = new MergeOptions();
            options.XmpMetadata = false;
            MergeDocument doc = new MergeDocument(pdf, options);
            // Create an Xmp Metadata
            XmpMetadata xmp = new XmpMetadata();
            // Add the Xmp metadata to the document. This will add default metadata to the PDF.
            doc.XmpMetadata = xmp;
            doc.Draw(@"C:\Temp\MyOutput.pdf");
 
Thanks,
ceTe Software Support Team
 May 09 2019 9:54 AM
If the source's Xmp Metadata XML is invalid, does creating a new XmpMetadata object fix the malformed XML or would we still need to test that the Xmp Metadata is properly formatted?

I ended up writing a function that tests (validates) the Xmp Metadata XML and sets the merge option to true (if valid) and false (if invalid).

Thanks!
 May 09 2019 12:12 PM
Posted by a ceTe Software moderator
Hi,

No, you would need to correct the XML yourself. Using it in a new XmpMetatdata object will not fix the malformed XML.

Thanks,
ceTe Software Support Team

All times are US Eastern Standard time. The time now is 2:09 AM.