Section CompleteClone() doesn't keep custom positioning

Hi Tommy, more questions for you… :slight_smile:

I’m trying to load an invoice template from an XML file and then use the same template to generate many invoices. Here the C# code used :

 


string templateFile = System.Web.HttpRuntime.AppDomainAppPath + “\Settings\AsposeInvoice.xml”;
mPdfDocument.BindXML(templateFile, null);

Aspose.Pdf.Section section = mPdfDocument.Sections[“invoice1”];

// Create PDF Template
CreateTemplate(section);
Aspose.Pdf.Section templateSection = section.CompleteClone() as Aspose.Pdf.Section;

bool firstInvoice = true;

Model.Client client;
for (int i=0; i<mClientList.Count; ++i) {
client = mClientList[ i ] as Model.Client;

if (firstInvoice == true) {
section = mPdfDocument.Sections[“invoice1”];
firstInvoice = false;
}
else {
section = templateSection.CompleteClone() as Aspose.Pdf.Section;
section.ID = “invoice” + (i+1);
mPdfDocument.Sections.Add(section);
}

GeneratePage(client, section);
}


CreateTemplate() fills the text common to all invoices (such as date, legal notice, return address, etc.)

GeneratePage() fills the client-dependant data (such as name, balance, address, etc.)

The problem is that the first invoice is OK, but all the following seem to lose the custom positioning used (ParagraphRelative mostly) when I make a CompleteClone() of the templateSection. It seems to revert to AutoPositioning. As you can imagine, this is a problem for me.

Is there a way to use the same “virgin” template XML for all sections of the Pdf, instead of creating the first section and then copying it. Kind of like what you have in ceTe.DynamicPdf?

Can you confirm this ?

Thanks,

Dominic.

Dear Dominic,

Thank you for considering Aspose.

Sorry, using xml template for all sections is not supported. I have noticed that the custom positioning info is lost in CompleteClone(). I can fix this but you have to change the ID yourself after cloning.

Thanks Tommy, do you have any idea when the hotfix can be available ?

By changing the ID, you mean only the ID of the section, right? Not of all the Paragraph it contains?

Like so :



section = templateSection.CompleteClone() as Aspose.Pdf.Section;
section.ID = “invoice” + (i+1);
mPdfDocument.Sections.Add(section);

Thanks again,

Dominic.


Dear Dominic,

Thank you for considering Aspose.

I think I can provide this hot fix before Monday. But if you have used paragraph relative positioning in your XML, you have to chang the ID and reference ID.

Dear Dominic,

Thank you for considering Aspose.

I have fixed this bug. Please download hotfix.

Here is an example for this issue:

[XML]


This is the ref para.

This is the custom positioned paragraph.




[c# code]
Pdf pdf = new Pdf();

pdf.BindXML("d:/CSharp/Pdf-bak/Xml/Test/Test.xml",null);

Section sec1 = pdf.Sections[0];

Section sec2 = sec1.CompleteClone() as Section;

Text t1 = sec2.GetObjectByID("s1p1") as Text;
t1.ID = "s2p1";

Text t2 = sec2.GetObjectByID("s1p2") as Text;
t2.ID = "s2p2";
t2.ReferenceParagraphID = "s2p1";

pdf.Sections.Add(sec2);

pdf.Save(@"d:\temp\Test.pdf");