We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Foreground colour triggers a carriage return

When I create a PDF, HTML segments styled with foreground are not displayed as expected


The segment is defined as :


IsHtmlTagSupported = true;
IfHtmlTagSupportedOverwriteHtmlFontNames = true;
IfHtmlTagSupportedOverwriteHtmlFontSizes = true;
IfHtmlTagSupportedCssWinsOnFirstLevelChildren = true;

The HTML I’m setting in the segment is defined in the attached file.

The output is also attached. See the new line created after the text with yellow foreground colour. This should not happen. Could you look into it ?



Hi There,


Thanks for contacting support.

In order to add HTML content inside PDF document, you can use HtmlFragment Class provide by Aspose.Pdf DOM model. Please check following code snippet where I have added your HTML string into PDF using Aspose.Pdf for .NET 17.4.0, by HtmlFragment and did not notice the issue which you have mentioned. I have also attached a screenshot of the output, generated by below code, for your reference.

Document doc = new Document();<o:p></o:p>

Table tab = new Table();

tab.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow;

tab.DefaultCellBorder = new BorderInfo(BorderSide.All, 1.0f, Color.Black);

tab.IsBordersIncluded = false;

Row row = tab.Rows.Add();

Cell cell = row.Cells.Add();

// Below HTML string (htmlString) is same which you have shared

cell.Paragraphs.Add(new HtmlFragment(htmlString));

cell = row.Cells.Add();

cell.Paragraphs.Add(new HtmlFragment(htmlString));

cell = row.Cells.Add();

cell.Paragraphs.Add(new HtmlFragment(htmlString));

doc.Pages.Add().Paragraphs.Add(tab);

doc.Save(dataDir + "HtmlFragment.pdf");



Please try to add HTML content by above mentioned approach and latest version of the API and in case if you still face an issue, please share a complete code snippet with sample input file(s). This way we can test the scenario in our environment and address it accordingly.


Best Regards,

Thank you for your help.


I forgot to mention that I’m using a XML template. It looks like this:

Original

However, I don’t see how to use the HtmlFragment element in XML. Do you have an example ?

Also I have tried your code :

firstRow.Cells[“original”].Paragraphs.Add(new HtmlFragment(evalRow.Original));

But then I get a cast error - cannot convert from ‘Aspose.Pdf.HtmlFragment’ to 'Aspose.Pdf.Generator.Paragraph’

I’m using the latest version.

Hello There,


graphicsxp44:
I forgot to mention that I’m using a XML template. It looks like this:

Original

However, I don’t see how to use the HtmlFragment element in XML. Do you have an example ?

Thanks for adding more details to the scenario. As shared above, HtmlFragment class has been introduced in Aspose.Pdf DOM (Document Object Model) approach, whereas you are using an old Aspose.Pdf.Generator approach. I am afraid that old Aspose.Pdf.Generator approach is going to be obsolete soon and it is highly recommended to use new DOM model.

However, in order to generate PDF from XML by new model, your XML structure should be based upon new Aspose.Pdf DOM. Please check attached XML file in which I have shown a basic DOM based XML structure. You can modify your XML template/file according to new DOM based structure and generate PDF by following code snippet (Please check attached PDF file, generated by below code).

Aspose.Pdf.Document doc = new Document();<o:p></o:p>

doc.BindXml(dataDir + "XMLDOM.xml");

doc.Save(dataDir + "XMLtoPDF_out.pdf");



graphicsxp44:
Also I have tried your code :

firstRow.Cells["original"].Paragraphs.Add(new HtmlFragment(evalRow.Original));

But then I get a cast error - cannot convert from 'Aspose.Pdf.HtmlFragment' to 'Aspose.Pdf.Generator.Paragraph'

I'm using the latest version.


You encountered this problem because you were trying to add DOM based object (i.e HtmlFragment) into an old Aspose.Pdf.Generator based Paragraph collection. However, in order to use HtmlFragment, please check following code snippet, based upon new DOM model, where I have added a HtmlFragment inside table cell.

Aspose.Pdf.Document doc = new Document();

doc.Pages.Add();

Aspose.Pdf.Table table = new Aspose.Pdf.Table();

Aspose.Pdf.Row row = table.Rows.Add();

Aspose.Pdf.Cell cell = row.Cells.Add();

cell.Paragraphs.Add(new HtmlFragment("

This is text

"));

doc.Pages[1].Paragraphs.Add(table);



For more information, you may visit "Add Html String using DOM" article in API documentation. In case of any further assistance, please feel free to contact us.


Best Regards,

Well…Aspose.Pdf.Generator may become obsolete but we have been using it extensively over the last few years. It seems the new Library is not compatible with our XML templates and we are on a schedule here.


I’ve attached one of our XML templates as well as the corresponding C# code to generate it. Could you please take a look and send us the updated version with the new code and XML template ?
We’ll get inspiration from that one in order to update all our templates.

Is an xsd available and where can we download it?

Hi,


Thanks for writing back.

graphicsxp44:
Well…Aspose.Pdf.Generator may become obsolete but we have been using it extensively over the last few years. It seems the new Library is not compatible with our XML templates and we are on a schedule here.

I’ve attached one of our XML templates as well as the corresponding C# code to generate it. Could you please take a look and send us the updated version with the new code and XML template ?
We’ll get inspiration from that one in order to update all our templates.

We are working over modifying your shared XML template according to new DOM structure and will share results with you as soon as possible. Please be patient and spare us little time. We are sorry for the inconvenience.


Best Regards,

Hi Laurent,


Thanks for your inquiry.

lnullens:
Is an xsd available and where can we download it?

You can check XML Schema present in the XML folder, located in the installation directory of Aspose.Pdf for .NET (Please check the attached image). In case if you have not downloaded latest version of the API yet, you can download it from Downloads section of our website. Moreover, for your convenience, I have also attached .XSD file with this post (Please find attachment). In case of any further assistance, please feel free to contact us.


Best Regards,

Thanks for the schema.


We always use the nuget package. Maybe you could add the xsd to the nuget package and add it to the solution when installed.

Best regards,

Hi Laurent,


Thanks for your feedback. We are working over providing XSD along with all required artifacts on GitHub, so that they all can be always available. As soon as we have things ready we will upload it to GitHub. Please be patient and spare us little time. We are sorry for the inconvenience.


Best Regards,

Hello,


Any news on this ? Can we expect to have some code by the end of the week ?

Thanks

Hi There,


Thanks for your inquiry. As shared earlier that we are working over making the XML template and as soon as we complete the testing of generated XML template, we will share results along with template file with you, so that you can take inspiration from that and modify your existing templates. Please be patient and spare us little time.

We are sorry for the inconvenience.


Best Regards,

Hello,


I was wondering if you had a chance to look into our issue ? FYI we have a paid licence with support so maybe there’s a way to submit our request through official support in order to speed things up ?

Hi There,


Thanks for your inquiry.

Please note that there are other pending scenarios in the queue as well which are meant to be investigated before yours as they were reported previously. We are trying our best to accommodate your request in our schedule so that we can share some significant results with you. We hope that we will be able to share DOM based XML template after modifying your old template, by the end of this week.

We greatly appreciate your patience and comprehension in this regard. Please spare us little time. We are sorry for the inconvenience.

Best Regards,

Hello There,


As shared above that we are working over modifying your existing XML template according to new DOM based structure, so meanwhile would you please share the PDF document which has been generated over your end from same XML file (evaluation.xml), which you have shared. This would really help us in producing the results accordingly.


Best Regards,

Sure, here it is.


As you can see, the text is cut after Lorem because it uses a background colour.

Hi,


Thanks for sharing sample PDF document. As soon as we have some significant results, we will let you know. Please spare us little time.

Best Regards,

Could you please urgently get back to us with a fix ? We are close to production release and this issue has been pending for almost a month.

Hi,


Thanks for your patience.

We have converted your XML template according to new DOM based XML structure and tried to generate PDF from it but API was throwing an IndexOutOfRangeException Exception while converting the XML into PDF. Hence, we have logged an issue PDFNET-42870 in our issue tracking system, for the sake of detailed investigation.

For your reference, I have also attached new DOM based XML template, from which we have tried to generate PDF at our end. We will further look into the details of the issue which has been shared above and keep you informed with the status of its rectification. Please be patient and spare us little time.

We are sorry for the inconvenience.


Best Regards,

Can you give us an estimation as to when it will be fixed ?


What part of the template triggers the error ? Maybe we can live without this information in the PDF and still have the rest of the document generated the right way with correct formatting…