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

Free Support Forum - aspose.com

Convert a web page to a pdf file

Hi, can Aspose pdf API convert a web page to a pdf file? That is, by giving a URL and render it into a pdf file.


I am looking for the API that can convert a web page to a pdf file by giving a URL. I saw the API sample as below:

String basePath = “C:/pdftest/”;
com.aspose.pdf.HtmlLoadOptions htmloptions = new com.aspose.pdf.HtmlLoadOptions(basePath);
// use the new conversion engine
// load HTML file
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(basePath+“EmailDemo_updated.html”, htmloptions);
// Save HTML file

Can I assign the basePath with a web URL, such as “http://www.myhost.com/mydir/”?
And then I want put a web page URL to new a pdf.Document:
new com.aspose.pdf.Document(basePath + “MyPage.jsp”, htmloptions);

Does it work for any web URL?


Hi Kevin,

Thanks for contacting support.

Please visit the following link for required information on

The doc listed above shows only C# and Dot.Net. Is it supported in Java?

Hi Kevin,

We are working on preparing the required code snippet for Java platform and will get back to you soon.

Hi Kevin,

We have a class named HtmlFragment which provides the feature to add HTML contents inside PDF file. In order to convert URL contents to PDF format, first you need to get the contents from internet, instantiate HtmlFragment object using contents retrieved from Internet and then try placing the HtmlFragment inside the PDF document.

However during my testing, I have observed that our API is having some issues when using following code snippet. For the sake of correction, I have logged this problem
PDFNEWJAVA-34479 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.




java.net.URL url = new java.net.URL("http://www.aspose.com");

InputStream is = url.openConnection().getInputStream();

BufferedReader reader = new BufferedReader( new java.io.InputStreamReader( is ) );

String line = null;

while( ( line = reader.readLine() ) != null ) {




// Instantiate HtmlFragment with HTML contents

com.aspose.pdf.HtmlFragment contents = new com.aspose.pdf.HtmlFragment(line);


com.aspose.pdf.Document doc = new com.aspose.pdf.Document();





} catch (java.net.MalformedURLException e) {


} catch (IOException e) {