Aspose html to pdf conversion at client side or aspose server side

Hello Team,

while converting html to pdf using aspose library, is that conversion happen in client’s own machine where application is deployed or it’s happen on aspose server??

if it’s happen on aspose server then how can I use it as a web service??

Thanks,
Madhuri

@MadhuriMaru

Aspose.PDF for .NET/Java is a desktop API and it does not send any call to Aspose Server for any functionality. All the processing is done on the machine where the application (in which the API is used) has been deployed/installed.

Thank you for your response. could you please share url or any documentation that contains this type of information?? I need to read it in detailed as I have to create POC document that contains all about Aspose and based on that we consider it for future use.

I have some other queries about HTML to PDF conversion:

  1. can I add dynamic header/footer based on page Number. Like if pageNumber is one then showing simple header and if pageNumber>1 then showing custom header based on javascript. I checked aspose documentation but they provide odd-even page header but didn’t get any solution for my requirement.
  2. is Aspose.HTML support SVG?? here svg is present within html file.
  3. how can I break page using Aspose.HTML?

Please suggest.

@MadhuriMaru

You may please check the product complete overview in the public API documentation. In case you do not find any specific information, you may please tell us.

You can surely add page header specifically to the page numbers by using Aspose.PDF. For example,

Document doc = new Document("input.pdf");
foreach(Page page in doc.Pages)
{
 if(page.Number == 1)
 {
  HtmlFragment htf = new HtmlFragment("<span style='color: #ff0000; white-space: nowrap; -ms-writing-mode: tb-rl; transform: rotate(180deg); background-color: #ffff00; -webkit-writing-mode: vertical-rl;'>123456</span>");
  HeaderFooter header = new HeaderFooter();
  header.Paragraphs.Add(htf);
  page.Header = header;
 }
 else if (page.Number == 3)
 {
  // do other different stuff
 }
}
doc.Save(dataDir + "HTMLInHeader.pdf");

By “based on javascript”, could you please explain a bit more about it? We will provide our feedback accordingly.

Yes, if SVG image is present in the HTML file, Aspose.HTML will support and render it during conversion.

In case you want to break pages inside output PDF during conversion from HTML. You can specify following CSS property in your HTML content that will cause a page break:

page-break-before: always;

Please feel free to let us know in case you need further information or face any issue while implementing any of the above functionalities.

can I add adder using Apsose.HTML?

I researched on site and found that Aspose.HTML and Aspose.pdf both can be used for HTML to pdf conversion but what’s the big difference between them?

is There any major limitation or challenge about Aspose lib for java?

It would be great if you can share url that contains information about conevrsion happens on Aspose server or customer’s machine?

@MadhuriMaru

Yes, both Aspose.PDF and Aspose.HTML provide HTML to PDF conversion feature. The Aspose.PDF is specialized to process PDF documents i.e. create new or modify existing PDF documents whereas, Aspose.HTML is well suited to deal with HTML files. If you want to modify PDF files after conversion, Aspose.PDF will be right API in order to do that otherwise you can go with Aspose.HTML if you only need to process HTML files and convert them into PDF or other file formats.

Could you please explain a bit more about your above inquiry? What kind of limitations or challenges are your asking about? Aspose Java APIs offers almost same feature as .NET APIs do and as long as supported JDK/JRE is installed in the system, you will be able to use them without any issue.

We are afraid that particular line of information is not mentioned explicitly in the documentation. Please note that the API documentation addresses basic and common concerns a user can have about using the API and implementing its Classes and Methods to achieve his requirements. For further technical and scenario based inquiries, we offer assistance via our forums. In other words, you can use both documentation and support forum in order to gather information related to the API you are interested in.

Hello, Thank you for your response.

I am checking below type of limitation:

  1. Aspose.HTML is converting document on customer’s own machine?
  2. customization header/footer based on page number? (above you provided example for header/footer customization, is it for ASpose.PDF or I can use it for Aspose.HTML)
  3. Is Aspose.HTML convert HTML string to byteArray? If yes, please suggest so I can cross check with implementation.
  4. We are having html template that containing lots of small image icon, is it convert properly in PDF of it breaks anything?
  5. In previous response you shared I can add header footer based on page number, but my question is like if header having diff height and footer having diff height then how can I add them with HTMLFragment? and also in one HeaderFooter , do I need to pass both header and footer or do I need to create 2 HtmlFragment?

@MadhuriMaru

Yes, Aspose.HTML will convert the document on the machine where the application is deployed. Please also note that it will connect to the internet as well in case some online resources (e.g. images) are used in the give HTML.

The provided example was about Aspose.PDF. It adds the Header/Footer in the PDF document.

You can achieve it using only Java without Aspose.HTML intervention:

byte[] byteArray = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(dataDir + "test.html"));

There is no such known issue in the Aspose.HTML that can cause missing images in the output. However, you can please evaluate the API with a 30-day free temporary license and let us know if you face any issue.

The same HeaderFooter Class is responsible for adding both Header and Footer of a Page in a PDF. In case you want to add same content for header/footer, one instance of the Class will be assigned for both Page.Header and Page.Footer. For example:

HtmlFragment htf = new HtmlFragment("<span style='color: #ff0000; white-space: nowrap; -ms-writing-mode: tb-rl; transform: rotate(180deg); background-color: #ffff00; -webkit-writing-mode: vertical-rl;'>123456</span>");
HeaderFooter hf = new HeaderFooter();
header.Paragraphs.Add(htf);
page.Header = hf;
page.footer = hf;

In case you need to give different content for header and footer, you will initialize new HeaderFooter Class for each of them with desired content being added to the Paragraphs Collection.

Thank you.
I am trying with free license to check my project requirement is fulfil with Aspose.Html lib.
I have queries about maven dependency shared in documents (Installation - Aspose.HTML for Java)

 <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-html</artifactId>
        <version>20.9.1</version>
        <classifier>jdk16</classifier>
    </dependency>

what is the use of classifier jdk16?? is it mandatory or optional parameters??

Another question that I want to ask , In Aspose.Html document they only shared gradle project link. do we have any demo project that present in Maven?? If yes then could you please share link.

@MadhuriMaru

Yes, this classifier tag is mandatory while adding the dependency of Aspose.HTML in a Maven project. Furthermore, you may please check Aspose.HTML for Java GitHub Repository which is public and contains an example project from which code samples are showcased in API documentation.

I asked about Maven Github project, In doumentation they mentioned about Gradle project.

And you shared header/footer example is about Apsose.PDF and I am using Aspose.Html.

It would be great if you can provide detail about How to set header/footer, orientation, page size, marging using Aspose.Html.

@MadhuriMaru

In the documentation, the dependency configuration is shared for both Maven and Gradle. In case you are working in a Maven Project, you only need to use the Maven dependency. You can create an empty Maven Project in Eclipse or Intelli J IDEA and add Aspose.HTML dependency in pom.xml. You should be able to use the API without any issue. However, if you still face any issue while setting up the environment, please let use know. We will share a basic Maven Project with you.

Do you want to set header/footer in output PDF? Or you need to modify existing HTML file?

  1. Yes in GitHub, it’s shared both maven and Gradle dependency. But my concern is I want to get some API reference for implementation.

  2. Dynamically generated document not containing header/ footer as it’s generated dynamically based on some user information. so currently we are adding header/footer after template file is processing and then that header/footer apply to HTML and effect is visible in PDF file.

@MadhuriMaru

Please find an attached sample Maven Project which includes dependency of Aspose.HTML. It is a simple console application which you can further modify as per your needs. For more depth knowledge about API Class, you can check API Reference Section as well.

sample.zip (6.6 KB)

It would be helpful for better understanding if you could please share a sample template along with expected output/resultant files that you want to generate using Aspose.HTML. We will try to produce it at our end and share the code snippet with you.