Net - Unable to creating PDF using HTML String

Hi:


I have an html string with no HTML,HEAD & BODY tags. I am not using stream reader since the
html string is in a c# variable. No errors but an empty pdf was created.
The htmlstr c# variable has value something like

table.AdvTbl {border:1px solid gray; width:800px; } th.AdvTbl{ background-color: Silver; } td.AdvTbl { border-right:1px solid silver; border-bottom:1px solid silver; } .wbs_hdr { background-color:silver; font-weight:bold; text-align:center; border-right:1px solid silver; border-bottom:1px solid silver; }
[[DOCUMENT_NUMBER_INFO]]
Funding Advisement: GER OAA
Fiscal Year: 2014
Date Issued: 10/09/2013 10:10 AM
Funding Source: "Treasury Symbol"
Cost Center Number: 323244A
Project/Activity: N/A if not in captured
Allotment: 1st quarter Initial, Modification to “Latest Version”, Final
To:Head of Post and Admin
Post Authority:


My C# Code:
------------
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, htmlStr);
text2.IsHtmlTagSupported = true;
text2.IsFitToPage = true;
section.Paragraphs.Add(text2);
pdf.Save(“c:/test/HTML2pdf.pdf”);

How do I handle this. Please advise

Suresh

Hi Suresh,


Thanks for using our products.

I have tested the scenario with Aspose.Pdf for .NET 8.5.0 where I have used the following code snippet and as per my observations, the PDF file is properly being created. For your reference, I have also attached the resultant PDF file generated over my end.

Please note that I have used VisualStudio 2010 application running over Windows 7 (x64).

[C#]

String htmlstring = "<style
type="text/css">
table.AdvTbl {border:1px solid gray; width:800px; } th.AdvTbl{ background-color: Silver; } td.AdvTbl { border-right:1px solid silver;
border-bottom:1px solid silver; }
.wbs_hdr { background-color:silver; font-weight:bold; text-align:center; border-right:1px solid silver; border-bottom:1px solid silver; }
<div
style="width:600px;">[[DOCUMENT_NUMBER_INFO]]
Funding
Advisement:
GER
OAA
Fiscal Year:
2014
Date Issued: 10/09/2013 10:10
AM
Funding Source: "Treasury
Symbol"
Cost Center Number:
323244A
Project/Activity: N/A if not in captured

Allotment: 1st quarter Initial, Modification to "Latest Version",
Final
To:Head of Post and Admin

Post Authority:

";

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

Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, htmlstring);

text2.IsHtmlTagSupported = true;

text2.IsFitToPage = true;

section.Paragraphs.Add(text2);

pdf.Save(“c:/pdftest/HTML2pdf.pdf”);



We are sorry for your inconvenience.

Thanks.


The portion of the HTML String that I sent you works fine. The rest of the string which has
tables etc are not rendered properly. They are cutoff and does not seem to fit into the page.

I have attached the entire string to try it on your side.

Also I need to add header (with an image) & footer to each page. Can you provide some link to the
same.

Thanks
Suresh

Hi Suresh,


Thanks you for sharing additional information. We’ve tested the scenario both with string variable and using HTML file, We have noticed that complete data is not being rendered along with table formatting issue and logged issue as PDFNEWNET-35898 for further investigation and resolution. We will update you as soon as its resolved.

Moreover, Please check the documentation link to add image in header/footer of a page. Hopefully it will help you to accomplish your requirements.

Please feel free to contact us for any further assistance.

Best Regards,

Thanks.


While the investigation is going on with my previous issues, I would appreciate if you could help me with the following.
1. Unable to get header and footer displayed
2. Some of the styles like font-style.

tags are not rendered properly.


I have tried it with simple htmlSting. Please find the sample that I was testing

Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();
pdfLicense.SetLicense(@“C:\Aspose\Aspose.Total.lic”);
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

section.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A4Height;
section.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A4Width;

string headStr = “

Test Aspose

The newest iPads could make their debut later this month.

Apple is planning an October 22 press event to show off the latest additions to its iPad line, according to AllThingsD’s John Paczkowski, confirming an earlier report in Current Editorials

”;
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, headStr);
text2.IsHtmlTagSupported = true;
section.Paragraphs.Add(text2);
// Create Header Section of the document
Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(section);
Aspose.Pdf.Generator.Text headerTxt = new Aspose.Pdf.Generator.Text(“Government of United States”);
header.Paragraphs.Add(headerTxt);
// Create Footer Section of the document
Aspose.Pdf.Generator.HeaderFooter footer = new Aspose.Pdf.Generator.HeaderFooter(section);
// Create a Footer Text object
Aspose.Pdf.Generator.Text footerTxt = new Aspose.Pdf.Generator.Text("Page: ($p of $P ) ");
footer.Paragraphs.Add(footerTxt);
pdf.Save(“c:/test/HTML2pdf.pdf”);
Hi Suresh,

Thanks for your feedback.

sureshcs:
1. Unable to get header and footer displayed
Please note you also need to assign header and footer to desired section. Kindly amend you code as following.

.....

// Asign header/footer to the Secion

section.OddHeader = section.EvenHeader = header;

section.OddFooter = section.EvenFooter = footer;

....

....

sureshcs:

2. Some of the styles like font-style.

tags are not rendered properly.

Font styles are being working fine. Moreover, header tag will not be rendered as it is used for document title and document related information.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Suresh,


Thanks for your patience.

In order to get optimized performance while converting HTML to PDF, please try using the following code snippet based on new Document Object Model (DOM) of Aspose.Pdf namespace.

[C#]

HtmlLoadOptions options = new HtmlLoadOptions(externalResourcesBaseUri);<o:p></o:p>

options.UseNewConversionEngine = true;<o:p></o:p>

Document pdfDocument = new Document(inFile, options);

pdfDocument.Save(outFile);