Converting from html to pdf does not convert same as html

Hello Team,

I am not getting proper output when I convert to pdf from html.
I’m using generated pdf for print later on.

HTML generated is printed in a single paper but when I convert it to pdf, it gets converted to html but it’s cutting it’s edges and taking 2-3 pages to print.

I want it to be same as html with same style, height and width.

I’m using below lines of code to print, please guide me through it.

I have attached a sample HTML and generated pdf with this.

com.aspose.words.Document doc = new com.aspose.words.Document(inputFilePath);
for (Section sectoin : doc.getSections())
{
    PageSetup ps = sectoin.getPageSetup();
    ps.setPaperSize(PaperSize.LETTER);
    ps.setOrientation(Orientation.PORTRAIT);
    Node[] tables = doc.getChildNodes(NodeType.TABLE, true).toArray();
    for (int i = 0; i < tables.length; i++)
    {
        Table table = (Table)tables[i];
        table.setAllowAutoFit(true);
        table.setPreferredWidth(PreferredWidth.fromPercent(100.00));
    }
}
doc.updateTableLayout();
doc.save(outputFilePath);

Hi Parth,

Thanks for your inquiry. I have tested the scenario and have not found any issue while using latest version of Aspose.Words for Java 14.7.0. Please use Aspose.Words for Java 14.7.0. I have attached the output document with this post for your kind reference.

Thanks Tahir,

It seems good, but still it takes two pages to print the html. I want in a single page only.

I think its because of the top and left alignment. Can we have an option to decrease the alignment and fit in in an only page. This is a sample template, and should always take one page to print.

If you could help me with this it would get better

Thanks,
Parth.

Hi Parth,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you load the input html in MS Word, the contents will be shown in two pages. However, you can overcome this issue by increasing the page height and setting page margins as shown in following code example or decrease the font size using Run.Font property.

Please use the following code example to achieve your requirements. Hope this helps you.

Document doc = new Document(MyDir + "html1.html");
for (Section sectoin : doc.getSections())
{
    PageSetup ps = sectoin.getPageSetup();
    ps.setPaperSize(PaperSize.A4);
    // Set the page height
    ps.setPageHeight(ConvertUtil.inchToPoint(13));
    ps.setOrientation(Orientation.PORTRAIT);
    ps.setTopMargin(0.0);
    ps.setBottomMargin(0.0);
    ps.setLeftMargin(0.0);
    ps.setRightMargin(0.0);
    Node[] tables = doc.getChildNodes(NodeType.TABLE, true).toArray();
    for (int i = 0; i < tables.length; i++)
    {
        Table table = (Table)tables[i];
        table.setAllowAutoFit(true);
        table.setPreferredWidth(PreferredWidth.fromPercent(100.00));
    }
}
doc.save(MyDir + "Out.pdf");

Thanks Tahir,

It works perfect except an only change that is minor but important that I have attached here as a screenshot. Please check if we can incorporate that thing as well?

Thanks,
Parth.

Hi Tahir,

Found a problem with the html conversion that It’s not taking a image relative path into the account instead it’s showing some box.

Need your help in this matter.

Thanks,
Parth.

Hi Parth,

Thanks for your inquiry.

*psoni.ism:

It works perfect except an only change that is minor but important that I have attached here as a screenshot. Please check if we can incorporate that thing as well?*

I
have tested the scenario and have managed to reproduce equal space issue with table’s cell at my side. For the sake of correction, I have logged this problem in
our issue tracking system as WORDSNET-10696. I have linked this forum
thread to the same issue and you will be notified via this forum thread
once this issue is resolved. We apologize for your inconvenience.

Regarding the issue, space between (24E) and (ICD), I have not found this issue at my side. Please check the attached output Pdf for your kind reference.

*psoni.ism:

Found a problem with the html conversion that It’s not taking a image relative path into the account instead it’s showing some box.*

Could you please share some more detail about this query? We will then provide you more information about your query along with code.

Hi Tahir,

Please find the attached images that will explain you in detail. I have attached the one highlighted image for your reference as well. Please make a directory named “images” in a drive where html file is residing. So you’ll be able to see that image in top left corner in html. But same will not appear when you convert that file in pdf. Please help me to get through it.

I have also highlighted issue with (24E) and ICD Ind | 9, It should have more space in between them as shown in html.

Can I expect a time when it would get resolved.

Thanks,
Parth

Hi Parth,

Thanks for your inquiry.

*psoni.ism:

I have attached the one highlighted image for your reference as well. Please make a directory named “images” in a drive where html file is residing. So you’ll be able to see that image in top left corner in html. But same will not appear when you convert that file in pdf.*

I have tested this scenario and have not found the shared issue. Please make sure that the image path is correct at your side. Please load the input HTML in MS Word and check either you can see the image or not. I have attached the output Pdf with this post for your kind reference.

*psoni.ism:

I have also highlighted issue with (24E) and ICD Ind | 9, It should have more space in between them as shown in html.*

Please note that Aspose.Words mimics the
same behavior as MS Word does. If you load the input html in MS Word, you will check the same output. Please check the attached image for detail.

However, I have logged this problem in our issue tracking system as WORDSNET-10703. Our development team will check this issue and we will update you via this forum thread once there is any update available on this issue. We apologize for your inconvenience.

Hi Tahir,

Thanks for you reply.

BTW, Can I expect a turn around time for both issue?

  • WORDSNET-10703
  • WORDSNET-10696

Thanks,
Parth.

Hi Parth,

Thanks for your inquiry. I would like
to share with you that issues are addressed and resolved based on first
come first serve basis. Currently, your issue is pending for analysis
and is in the queue. We will update you via this forum thread once there
is any update available on your issue.

Hi Tahir,

Any update on this?

Thanks,
Parth.

Hi Parth,

Thanks for your inquiry. Your issues are still pending for analysis and are in the queue. I have requested the development team to share the ETA. As soon as any information is shared by them, I will be more than happy to share that with you.

Thanks for your patience.

Hi Tahir,

We are in a hurry and we need to resolve this.

We are not getting exact pdf as HTML because of this.

Please provide further status asap.

Thanks,
Parth.

Hi Parth,

Thanks for your inquiry. We do understand your situation, however I am afraid, at the moment we can’t provide you the ETA for your issues. I asked our development team about your issues and I am afraid they are unable to commit any ETA at the moment. The underlying problem here is very complex and this needs more time for analysis. Once your issues are analyzed, we will then be able to provide you the ETA.

Thanks for your patience and understanding.