Welcome Guest Search | Active Topics | Sign In | Register

Mixed orientations(Portrait and Landscape) in a single pdf Options
Eopdf
Posted: Wednesday, July 21, 2021 12:45:25 PM
Rank: Newbie
Groups: Member

Joined: 7/21/2021
Posts: 3
Code: C#


Hi Team,

I have multiple reports and I need to display them in a pdf format. For this, I am storing the html for each report in a string and combining all the html's of every report at the end before converting it to pdf. Here each report has different output size. After converting this entire html to pdf, for larger width report output text is getting smaller because it is taking the portrait page. Then, I tried making the orientation to landscape, then this orientation is applied to all the pages in the report and now the smaller report outputs are getting even smaller. Ultimately I would like to set different orientation for different page based on the output size for each report. Is this possible? If yes, could you please guide me how to achieve this...

Thanks in Advance!!!
eo_support
Posted: Wednesday, July 21, 2021 1:49:03 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

You will not be able to have different output size within a single conversion. So you will need to do multiple conversions with different sizes, then call PdfDocument.Merge to merge the final result into a single PDF file. You can merge links between these files by calling this version of the Merge method:

https://www.essentialobjects.com/doc/eo.pdf.pdfdocument.merge_overload_3.aspx

The links across different conversions work by having <a href="#target_name"> in one conversion and <a name="target_name"></a> in the other conversion. The above merge method will point the first link to the second link as if they were all together inside a single HTML file.

Thanks!
Eopdf
Posted: Thursday, July 22, 2021 4:01:24 AM
Rank: Newbie
Groups: Member

Joined: 7/21/2021
Posts: 3
Hi,

Thanks for the quick response. I completely agree with your answer and that is what I am following for my application till now.

1. Getting HTML for each report.
2. Converting that HTML to PDF for each report.
3. In the last step, I am merging all the PDF’s. Then I am getting the resultant pdf with mixed orientations.

But now, here I am trying to create clickable table of contents(TOC). For this, by following the above-mentioned steps, in the html for content/first page I have added the anchor tags(href id) and slot name/id for each report name in the content page and then I am using that href id and slot id in the html of the respective report.

In the generated pdf, I can see the hyperlinks but they are not taking me to that report. I googled around and came to know that the html anchor tags/slots would only work if we have the anchor tag/id and slot id that I give for the report name in the content page html and the html for the report where I am using the content page href id and slot id should be in a single html. But as of now I am doing separate conversions and the html is also separate. Therefore, clickable TOC is not working in this case.

So now I am storing the html for each report in a string and combining all the html's of every report at the end before converting it to pdf. In this single conversion, I achieved the results, when I click on the hyperlink of the report name in the content page it is taking me to the actual report page. But, the font size for large output reports are getting smaller if I use portrait and If I use landscape the small report outputs are getting smaller.

Is there any way to make my clickable table of contents work? Can I add clickable TOC while converting html to pdf using EO pdf?

If yes, could you please guide me on how to achieve this...

Thanks in Advance!!!
eo_support
Posted: Thursday, July 22, 2021 9:17:26 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

The href and name pair for A elements WILL work in our case even if you are in separate HTMLs and conversions. This is an additional feature provided by our library. The key to get this working is you must Merge an array of HtmlToPdfResult objects.

If it does not work for you, please try to isolate the problem into a small test project and send the test project to us. We will investigate further once we receive that. See here for more details:

https://www.essentialobjects.com/forum/test_project.aspx

Thanks!
Eopdf
Posted: Friday, July 23, 2021 2:26:54 AM
Rank: Newbie
Groups: Member

Joined: 7/21/2021
Posts: 3
Hi,

Sorry, I failed to create a test project but it is structured very well in my major project. I can share with you the sample HTML that suits my case.

Sample HTML 1:

<!DOCTYPE html>
<html>
<table>
<p>Table of Contents</p>
<tr> <td> <li>
<a href="#h1"><slot name="h1">One</slot></a>
</td> </tr> </li>
<tr> <td> <li>
<a href="#h2"><slot name="h2">Two</slot></a>
</td> </tr> </li>
</table>
</html>

Sample HTML2:

<!DOCTYPE html>
<html>
<div style="page-break-after: always;"> </div>
<h2 id="h1" slot="h1">Main 1</h2>
<p>Main 1 Description...</p>
<div style="page-break-after: always;"> </div>

<h2 id="h2" slot="h2">Main 2</h2>
<p>Main 2 Description...</p>
</html>

I have converted the above two HTML's to PDF's using the EOPDF online converter https://www.essentialobjects.com/Products/EOPdf/HtmlToPdf.aspx , and then I merged those two PDF's online. The clickable Table of Contents is not working in the merged file.

Please help me out here...

Thanks!
eo_support
Posted: Friday, July 23, 2021 11:50:52 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

You can not use our online demo page to convert/merge them. You need to write the correct code to convert and merge them. The correct code needs to be something like this:

Code: C#
//Convert the first document
PdfDocument doc1 = new PdfDocument();
HtmlToPdfResult result1 = HtmlToPdf.ConvertUrl(file1, doc1);

//Convert the second document
PdfDocument doc2 = new PdfDocument();
HtmlToPdfResult result2 = HtmlToPdf.ConvertUrl(file2, doc2);

//Merge them
PdfDocument finalDoc = PdfDocument.Merge(result1, result2);
finalDoc.Save(result_pdf_file);


The key line here is:
Code: C#
PdfDocument finalDoc = PdfDocument.Merge(result1, result2);


Note that it merges result1 and result2, not doc1 and doc2. We have pointed this out to you multiple times in our previous replies. You can't just ignore what we tell you and keep thinking what you are thinking in your own mind.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.