Try to generate pdf from this html http://jsfiddle.net/6tpfs9h5/.
For me, block with text is located under image, but must be placed on the right from image. I use Aspose 10.1.0.
Hi Eddi,
Thank you,
But i use the Aspose.Pdf.Generator.Pdf class because i need footer and header sections. My code looks like this:
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
section.PageInfo.Margin = new MarginInfo { Left = 40, Right = 40, Top = 30, Bottom = 20 };
CreatePdfFooter(ref section, footer);
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, HTML);
text2.IsHtmlTagSupported = true;
section.Paragraphs.Add(text2);
i tried this code instead used Aspose.Pdf.Generator.Text:
pdf.BindHTML(HTML);
and with pdf.HtmlInfo.UseNewHtmlConvertorForEachHtmlTextBlock = true;
The result is the same, text block below the image.
Hi Eddi,
Thanks for your feedback. I am afraid Aspose.Pdf.Generator is an old generator, and we are fixing issues with the old generator in the new generator (Aspose.Pdf). It is recommended to use the new generator as it is more efficient and enhanced. You can also add a header/footer to the object with the new generator as follows:
HtmlLoadOptions options = new HtmlLoadOptions();
options.PageInfo.Margin = new MarginInfo { Left = 40, Right = 40, Top = 30, Bottom = 20 };
// Instantiate Document object
Document doc = new Document(myDir + "Htmlimagetest.html", options);
MemoryStream ms= new MemoryStream();
doc.Save(ms);
doc = new Document(ms);
Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
Aspose.Pdf.HeaderFooter footer = new Aspose.Pdf.HeaderFooter();
FileStream fs = new FileStream(myDir + "logo.png", FileMode.Open, FileAccess.Read);
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
image1.FixWidth = 50;
image1.FixHeight = 50;
// Add the image into paragraphs collection of the section
header.Paragraphs.Add(image1);
// Set the ImageStream to a MemoryStream object
image1.ImageStream = fs;
// Add footer text
Aspose.Pdf.Text.TextFragment fTxt = new Aspose.Pdf.Text.TextFragment("$p / $P ");
fTxt.TextState.Font = FontRepository.FindFont("Arial");
fTxt.TextState.FontSize = 16;
fTxt.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;
footer.Paragraphs.Add(fTxt);
foreach (Page page in doc.Pages)
{
page.Header = header;
page.Footer = footer;
}
// Save PDF file
doc.Save(myDir + "htmltopdf.pdf");
Please feel free to contact us for any further assistance.
Best Regards,