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

Free Support Forum - aspose.com

Generating Single Page pdf file from two html files containing Charts

Hi,

I want to generate a single page PDF file from two/three different html files which contains Charts.

Is it possible through Aspose???

Actually i have tried “PdfFileEditor” in “Aspose.Pdf.Facades” but in that first i need to convert both html files in separate pdf output files then i can merge both PDF output files into one pdf but in that case too output file is creating 2 pages in final output file.
And also the output is slightly differed from original input file. (Input and Output Files are attached for reference)

I need only one page including Both charts from two HTML Files
Is there any way i can get charts from two different HTML Pages into Single Page PDF file??



Thanks,
Ashutosh Shukla

Hello Ashutosh,


Thanks for contacting support.

You can use HtmlFragment class provided by DOM to add HTML at paragraph level, inside PDF document. Please check following code snippet that I have used to convert both HTML files into single page PDF document.

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

Page currpage = doc.Pages.Add();

HtmlFragment htmlFrag1 = new HtmlFragment(File.ReadAllText(dataDir + "input1.html"));

HtmlFragment htmlFrag2 = new HtmlFragment(File.ReadAllText(dataDir + "input2.html"));

currpage.Paragraphs.Add(htmlFrag1);

currpage.Paragraphs.Add(htmlFrag2);

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



For your reference, an output generated by above code is also attached. For more information, please visit "Add HTML string using DOM" article in API documentation. In case of any further assistance, please feel free to contact us.

Hi,

Thanks for the quick response. It’s working :slight_smile:

Thank you.

Hello Ashutosh,


Thanks for your feedback.

We are pleased to know that suggested code worked for you. Please keep using our API and in case of any other query, please feel free to ask.


Best Regard,
Hi Asad,

Is there any way i can make borders around each chart (each chart is coming through separate html fragment) in output Pdf file??

Regards:
Ashutosh

Hi Ashutosh,


Thanks for writing back.

You can add HtmlFragment inside a table cell and set cell borders, in order to get the desired results. Please check following code snippet where I have added two different HtmlFragment(s) from different files with borders, inside a PDF.

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

Page currpage = doc.Pages.Add();<o:p></o:p>

HtmlFragment htmlFrag1 = new HtmlFragment(File.ReadAllText(dataDir + “input1.html”));<o:p></o:p>

HtmlFragment htmlFrag2 = new HtmlFragment(File.ReadAllText(dataDir + “input2.html”));<o:p></o:p>

Table table = new Table();<o:p></o:p>

table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow;<o:p></o:p>

table.DefaultCellBorder = new BorderInfo(BorderSide.All, 0.5f);<o:p></o:p>

table.DefaultCellPadding = new MarginInfo(2, 2, 2, 2);<o:p></o:p>

Row row = table.Rows.Add();<o:p></o:p>

Cell cell = row.Cells.Add();<o:p></o:p>

cell.Paragraphs.Add(htmlFrag1);<o:p></o:p>

row = table.Rows.Add();<o:p></o:p>

cell = row.Cells.Add();<o:p></o:p>

cell.Paragraphs.Add(htmlFrag2);<o:p></o:p>

currpage.Paragraphs.Add(table);<o:p></o:p>

doc.Save(dataDir + “HtmlFragWithBorder_out.pdf”);<o:p></o:p>



For your reference, I have also attached an output generated by above code.


Best Regards,