Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

HTML file not converting to PDF

$
0
0
Hi,

I am using Aspose.PDF (7.2.0.0) to convert my HTML files to PDF. Below is a code piece that does this job.

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section sec1 = new Aspose.Pdf.Generator.Section(pdf1);
Aspose.Pdf.Generator.Text t2;

System.IO.StreamReader sr = new System.IO.StreamReader(@"D:\HTMLtoPDF\Sample.htm");
string HTMLStirng = sr.ReadToEnd();

t2 = new Aspose.Pdf.Generator.Text(HTMLStirng);

t2.IsHtmlTagSupported = true;
if (sec1.PageInfo.PageWidth > Aspose.Pdf.Generator.PageSize.A4Width)
sec1.PageInfo.PageWidth = Aspose.Pdf.Generator.PageSize.A4Width;

if (sec1.PageInfo.PageHeight > Aspose.Pdf.Generator.PageSize.A4Height)
sec1.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A4Height;

sec1.Paragraphs.Add(t2);
pdf1.Sections.Add(sec1);

for (int i = 0; i < pdf1.Sections.Count; i++)
{
pdf1.Sections[i].PageInfo.Margin.Left = 0;
pdf1.Sections[i].PageInfo.Margin.Right = 0;
pdf1.Sections[i].PageInfo.Margin.Top = 0;
pdf1.Sections[i].PageInfo.Margin.Bottom = 0;

pdf1.Sections[i].TextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;
}

pdf1.Save(@"D:\HTMLtoPDF\newPDF.pdf");

Code works fine for all of the HTML files except the attached one.

The attached HTML renders perfect in all browsers.

Is there any design issue in HTML / requires any change in my conversion code piece ?


Viewing all articles
Browse latest Browse all 3131

Trending Articles