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();

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();
Page currpage = doc.Pages.Add();
HtmlFragment htmlFrag1 = new HtmlFragment(File.ReadAllText(dataDir + “input1.html”));
HtmlFragment htmlFrag2 = new HtmlFragment(File.ReadAllText(dataDir + “input2.html”));
Table table = new Table();
table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow;
table.DefaultCellBorder = new BorderInfo(BorderSide.All, 0.5f);
table.DefaultCellPadding = new MarginInfo(2, 2, 2, 2);
Row row = table.Rows.Add();
Cell cell = row.Cells.Add();
cell.Paragraphs.Add(htmlFrag1);
row = table.Rows.Add();
cell = row.Cells.Add();
cell.Paragraphs.Add(htmlFrag2);
currpage.Paragraphs.Add(table);
doc.Save(dataDir + “HtmlFragWithBorder_out.pdf”);

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

Best Regards,