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

Free Support Forum - aspose.com

Creationg PDF document from HTML string loses background color

Hi,



I have a XML and XSLT content which is transformed in to a HTML string. Trying to create a PDF document from this HTML string using Pdf.BindHtml. The content is displayed correctly but the background color is missing.



code:

-------

string html = DoTransform(xmlDocument,Xslt stylesheett);

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

pdf.BindHTML(html, “”);

pdf.Save(@“FolderLocation”);



Attached is the html string from 'DoTransform" and the .pdf file that created using Pdf.BindHtml.



Please help me, how I can achieve the background color to the PDF file as specified in .



Also, is it possible to have multiple Html strings to store in the same PDF file.

I have n documents, where I need to loop through all the documents, get the xml and xslt content. Transform in to html string and save them all to a single PDF file.

I tried saving all the html strings to same PDF file, If I use the same PDF object to save .

e.g:

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

For(int i=0;i
{

string html=doTransform(doc[i],xslt[i]);

pdf.BindHTML(html, “”);



}

pdf.Save(@fileLocation);



Am I doing it correct to save different html to a single PDF file?.

Hi there,


Thanks for your inquiry. You may use new DOM approach to add HTML string in a PDF document. Please check following documentation link for the purpose. It will help you to accomplish the task.

Moreover, you may add as many HtmlFragment for html string into a PDF as you wish.


Best Regards,

Uma Annareddy:
Also, is it possible to have multiple Html strings to store in the same PDF file.
I have n documents, where I need to loop through all the documents, get the xml and xslt content. Transform in to html string and save them all to a single PDF file.
I tried saving all the html strings to same PDF file, If I use the same PDF object to save .
e.g:
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
For(int i=0;i<=4;i++)
{
string html=doTransform(doc[i],xslt[i]);
pdf.BindHTML(html, “”);

}
pdf.Save(@fileLocation);

Am I doing it correct to save different html to a single PDF file?.

Hi Uma,

Adding more to Tilal’s comments, using HtmlFragment object inside Aspose.Pdf namespace, you can read individual HTML files and add each HtmlFragment to paragraphs collection of page instance. When using this approach, you will have a single resultant PDF document. Add HTML String using DOM

Besides this, you may consider converting individual HTML file to PDF format and then try concatenating the individual files to single resultant file. For further details, please visit Concatenate PDF Files

Hi,

I used the DOM approach explained as in above mail and the things worked great for small size HTML strings where the content of the html can fix in a single Page of the PDF file.



Now, I have a large HTML string. when instantiated the HtmlFragment with this large html string, add this to collection of Page and save. Throws the error “The rectangle size can not be larger page size

Parameter name: rectangle”



The detailed error message is

at ‰.‹ž…ctor(Page , RectangleF , Boolean )

at Aspose.Pdf.Page.Accept(•– , RectangleF , Boolean , Boolean )

at ‰.Ž.Process()

at Aspose.Pdf.Page.(Page )

at Aspose.Pdf.Page.‡Š()

at Aspose.Pdf.Document.‡Š()

at Aspose.Pdf.Document.Save(Stream output)

at Aspose.Pdf.Document.Save(String outputFileName)



Can you Please help me to resolve this error.



Looks to be the page is not sufficient to fit the large HTML string data in a single Page.



below is the code snippet:

----------------------------

string html="";



Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

Aspose.Pdf.License license = new Aspose.Pdf.License();

license.SetLicense(“Aspose.Pdf.lic”);

Document doc1 = new Document();



// Add a page to pages collection of PDF file

Page page = doc1.Pages.Add();



// Instantiate HtmlFragment with HTML contnets

HtmlFragment htmlfrag = new HtmlFragment(html);





// Add HTML Fragment to paragraphs collection of page

page.Paragraphs.Add(htmlfrag);



doc1.Save(@filelocation);





I am using Aspose.Pdf version - 9.7.0.0



Attached is the Html string that is input to HtmlFragment.



Please help me to resolve this error.







Thanks,

Uma.A

Hi Uma,

Thanks for your inquiry. While testing the scenario, we have managed to reproduce the issue with latest version of Aspose.Pdf for .NET 9.7.0. We have logged a ticket PDFNEWNET-37693 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

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


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