Free Support Forum - aspose.com

Reference objects in xml

Hi,

I am using xml template for generating pdf document using latest version.
I am not able to reference sections or segments by their ID in xml anymore
com.aspose.pdf.Document pdfDoc = new com.aspose.pdf.Document();
pdfDoc.bindXml(“D:\templates\sampleTags.xml”);


Following used to work with the legacy version.
Pdf pdfDoc = new Pdf(bindXML(“D:\templates\sampleTags.xml”, null);
pdfDoc.bindXml(“D:\templates\sampleTags.xml”);
Section section = (Section)pdfDoc.getObjectByID(“mainSection”)

Sample xml file:
<?xml version="1.0" encoding="utf-8" ?>

Thanks
Mamatha

Hi Mamatha,


Thanks for using our API’s.

In legacy com.aspose.pdf package, each page is termed as Section and in new DOM, the page is referenced from A Page object. So in order to reference XML objects using new approach, you need to create XML according to Document Object Model of com.aspose.pdf. package. Please take a look over following code snippet. I have also attached the output PDF generated over my end.

[Java]

com.aspose.pdf.Document doc = new Document();<o:p></o:p>

doc.bindXml("c:/pdftest/sample (1).xml");

com.aspose.pdf.Page innerpage = doc.getPages().get_Item(1);

innerpage.getParagraphs().add(new com.aspose.pdf.TextFragment("Hello World..."));

System.out.println(doc.getPages().size());

doc.save(“c:/pdftest/XMLtoPDF.pdf”);


[XML]

<?xml version=“1.0” encoding=“utf-8”
?> <o:p></o:p>

Nayyer,

Thanks for the response. We didn't know about the new structure. Is there documentation on how to write xml in the new format?

I am not able to access all the elements in the xml with the new format. I have included the xml file.

Document pdfDoc = new Document();
pdfDoc.bindXml("D:\\templates\\sampleTags.xml");
Page pdfSection = pdfDoc.getPages().get_Item(1);
//how can I access Segments with id=boldHtml and strongHtml from page object

I want to dynamically place html values in the segments?

Thanks

Mamatha

Hi Mamatha,


Thanks for sharing the details.

The Text and Segment objects are present in legacy Aspose.Pdf for Java and I am afraid they are not part of new DOM (Document Object Model). However you may consider using TextFragment and TextSegment objects when using new DOM approach of com.aspose.pdf package.

Nayyer,

How can we access TextFragement and TextSegment elements by name from the Document object. If possible can you please provide an example.

Thanks

Mamatha

Hi Mamatha,


We are working on creating the required code snippet and will get back to you soon.

Did you a chance to work on it?

Hi Mamatha,


We are sorry for the inconvenience. It is not completed due to some other tasks, we will update you soon.

Best Regards,

Hi Mamatha,


Thanks for your patience and sorry for the delayed response.

I have logged an investigation ticket as PDFNEWNET-40014 in our issue tracking system and have intimated our product team to start investigating this requirement. We need to determine the mechanism to accomplish this requirement and once we have some updates, we will let you know. Currently we have logged this investigation ticket for Aspose.Pdf for .NET project and once the feature is implementation, the same solution will be ported to Aspose.Pdf for Java.

Please be patient and spare us little time. We are sorry for this delay and inconvenience.

The issues you have found earlier (filed as PDFNEWNET-40014) have been fixed in Aspose.Pdf for .NET 11.2.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi,



I was testing the behavior after the fix. It is not working properly. If TextSegment is inside a Table row, I am not able to access the object. But if it is directly inside Page element, I am able to access it.



TextSegment segment = (TextSegment)pdfDoc.getObjectById(“patientName”);

segment.setText(“TestSegment12”);



I have included sample xml file.



Thanks

Mamatha

Hi Mamatha,

We are sorry for the inconvenience. I have tested your scenario with shared XML document and noticed that Aspose.Pdf for Java throws NullPointer exception for accessing TextFragment/TextSegment inside Row element. For further investigation, I have logged an issue in our issue tracking system as PDFNEWJAVA-35857 and also linked your request to it. We will keep you updated via this thread regarding the issue status.


Best Regards,

The issues you have found earlier (filed as PDFNEWJAVA-35857) have been fixed in Aspose.Pdf for Java 12.0.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.