Posted by & filed under HTML to PDF conversion.

Every now and then we like to dedicate a post to a little bug or quirk of our beautiful rendering engine that is webkit. Today we dedicate it to rendering charts from Highcharts.com.

There are two problems that typically occur when people try to render charts from Highcharts with a renderer based on webkit:

  1. Thick grey lines appear over the graph lines
  2. The graph lines are not completely drawn, but only partly

Let’s discuss these two problems with examples.These are both taken by rendering the demo at http://www.highcharts.com/demo/.

Thick grey lines problem

Highcharts grey lines problemThe problem with the thick grey lines being displayed is shown in the image on the right. We’ve taken the liberty to take a snapshot of a rendering of one of our competitors’ websites. As you understand by now – we don’t have this issue in our patched system.

As you can clearly see the graph itself is obscured by thick grey lines. In reality these are lines with a very low opacity, which are meant to control mouse tracking. Because a bug in most webkit installations these are displayed with full opacity.

The recommended solution (unless you want to use our service, where you don’t have this problem) is to use the following fix in your JavaScript:
[javascript light=”true”]plotOptions:{series:{ enableMouseTracking:false, shadow:false, animation:false } }[/javascript]

Incomplete graph lines problem

Highcharts incomplete lines problemThe next problem is a little more prevalent. You’ll see it on all conversion websites (including our homepage, but obviously you’ll be able to correct it when you are a paid service member).

The Highcharts demo actually ‘draws’ the graph live for you in JavaScript. This is a nice little touch of interactivity, but the problem is – any rendering engine only has ONE chance to take a snapshot of the demo page. And it doesn’t really have a good way of knowing when the JavaScript is finished, other than waiting a set time.

This set time is called a JavaScript delay and can be controlled in our webkit service for all our members in the members area – the ones on the Save as PDF plan as well as subscribers to the HTML to PDF API or the HTML to PDF SDK.

On our homepage we have set this delay to a very low value, because we don’t want our free conversion service to always wait for JavaScript to render, cause most pages don’t even have JavaScript to wait for.

The FIX!

Highcharts fixedThis is what the demo page of Highcharts IS supposed to look like as PDF. We’ve generated this in a jiffy with our HTML to PDF API and so can you!

You can rest assured your Highcharts graphs or any other graphs will render fine with our HTML to PDF conversion service. They’ll work with the save as PDF service, the HTML to PDF API and also the SDK!

Conclusion

The JavaScript charts from Highcharts are a pretty popular product, but in most webkit services you’ll experience problems with them. In this post we hoped to have showed you that you will be able to use them comfortable with our services. We can also recommend you to check out Flot charts as we believe they’re just as nice and very easy to use.

If you want to know more about our services then please have a look at the section describing our different services. If you heard enough and want to join – please go ahead and sign up!

Posted by & filed under HTML to PDF API, HTML to PDF conversion.

Converting HTML to PDF in C# is an easy task with our API. Today we’ll be going over the functions in this library and we’ll show you code examples in C# that help you turn HTML into PDF.

Our HTML to PDF library works on any platform that has a HTTP connection and supports the following functions for HTML to PDF conversion and enhancing of the PDF:

  1. General options such as page format, margins, single page PDF creation etc
  2. Protection options such as password protection, encryption and rights management
  3. Watermarking or stamping

Basic API usage in C#

In order to use our API to get a PDF you just send a HTTP request with the right information. It’s like typing a URL in the browser address bar. The URL that you use contains the parameters that are the commands that control the API. In it’s simplest form you only pass an API key and a URL and we’ll then return the PDF based on the settings that you have defaulted in your members area.

The HTTP request for getting ‘http://www.google.com’ as PDF looks like this:

https://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com

In C# you’d code this as follows:

string apiKey = "yourapikey";
string url = "http://www.google.com";

using (var client = new WebClient())
{
client.QueryString.Add("apikey", apiKey);
client.QueryString.Add("url", url);
client.DownloadFile("http://api.htm2pdf.co.uk/urltopdf", @"c:\temp\mypdf.pdf");
}

So you don’t need to install any libraries or nothing. This works out of the box as long as you have subscribed to our simple HTML to PDF API and use your API key.

Additional options for HTML to PDF conversion in C#

As we described earlier, your members area has quite a few defaults that you can easily control there. So if you always need the same page format, margins, header, footer etc etc – you can just edit them there very easily. If you want to have some additional power to control each and every single PDF then you’ll use the additional options, which we’ll describe now.

General options

The table below shows all general options you can add to the HTTP request in order to change the layout of the PDF.

ParameterDescription
widthCustom width of the PDF
heightCustom height of the PDF, if you specify the width, but not the height, then we fit the whole page into a one page PDF by auto-adjusting the height of the PDF.
leftLeft margin
rightRight margin
topTop margin
bottomBottom margin
unitUnit for size & margin settings. Can be ‘mm’ (millimeters), ‘in’ (inches) or ‘pt’ (points).
We’ll use mm in case you don’t specify a unit.
popupIf you set this to y we will return a URL to the PDF on our server instead of the actual PDF.
This allows you to generate the PDF, without having to use bandwith to serve it to your visitors.

Encryption and protection options

The table below shows the options you have to encrypt the PDF and use protection and rights management options.

ParameterDescription
encryptionSpecifies the level of encryption for the PDF. You can choose the following values:

  • 40 for 40-bit RC4 encryption.
  • 128 for 128-bit RC4 encryption, requires Acrobat reader 5 or later
  • 128aes for 128-bit AES encryption, requires Acrobat reader 7 or later
  • 256 for 256-bit AES encryption, requires Acrobat reader X or later
ownerpassSpecifies the master password that controls all rights management settings for the PDF.
userpassSpecifies the password a user needs to open the PDF.
Also known as ‘document open password’.
noprintIf you pass this parameter, Acrobat Reader will prevent users from printing the PDF.
nocopyIf you pass this parameter, Acrobat Reader will prevent users from copying content from the PDF.
nomodifyIf you pass this parameter, Acrobat Reader will prevent users from modifying the PDF.

Watermarking and stamping

If you’d like to watermark or stamp your PDF you can do so with any image that you provide. We’ll add it to your PDF on every page automaticly. We consider stamping to be the same as watermarking, but then with an opacity of 1 (meaning fully opague).

The table below shows the parameters you can pass to control the watermark on your PDF.

ParameterDescription
wmSpecifies the full URL where we can find the image you want to use as watermark.
Please make sure the image is really there.
wm_xSpecifies the horizontal position where you want the watermark to start.
wm_ySpecifies the vertical position where you want the watermark to start.
wm_angleSpecifies the angle of rotation (in degrees) you want for your watermark.
wm_opacSpecifies the level of opacity you want for your watermark.
This is a “real” number between 0 and 1. 0 is fully transparant and 1 is fully opague (what some call a ‘stamp’).

Example with additional options in C#

Now let’s look at what happens if we want to pass additional parameters to control the PDF. In our initial example we were using the C# WebClient() object and then specified two parameters that we added to the query string: apikey & url. Since we have seen the other parameters now we can simple select the ones we want and add those to the query string as well.

So let’s say we want to protect our PDF with password ‘htm2pdf’ and we also would like to watermark it with the logo of our service (who wouldn’t want that?). We’ll use an opacity of 0.5 to make it half transparant and we’ll rotate it 50 degrees and put it on position 100, 100.

We would then do the following in C#:

string apiKey = "yourapikey";
string url = "http://www.google.com";
string userpass = "htm2pdf";
string wm = "http://www.htm2pdf.co.uk/img/logo.png";
string wm_opac = "0.5";
string wm_angle = "50";
string wm_x = "100";
string wm_y = "100";
using (var client = new WebClient()) {
client.QueryString.Add("apikey", apiKey);
client.QueryString.Add("url", url);
client.QueryString.Add("userpass", userpass);
client.QueryString.Add("wm", wm);
client.QueryString.Add("wm_opac", wm_opac);
client.QueryString.Add("wm_angle", wm_angle);
client.QueryString.Add("wm_x", wm_x);
client.QueryString.Add("wm_y", wm_y);
client.DownloadFile("http://api.htm2pdf.co.uk/urltopdf", @"c:\temp\mypdf.pdf");
}

Conclusion on the PDF C# library

As you can see the HTML to PDF API is very easy-to-use in C# and will work right off the bat without installing anything. If you’d like to learn more about all the options then please see the full documentation on the HTML to PDF API. If you think this is awesome then feel free to sign up now!

Posted by & filed under HTML to PDF API, HTML to PDF conversion.

It’s a little known fact that our HTML to PDF API can also be used from the command line or the browser address bar directly. This may sound a little strange and geeky, but I assure you – it’s neither.

The reason behind this is that our API is based on sending a HTTP request with a certain set of parameters. And as you may know – sending a HTTP request can be done by typing a URL in the browser window. And in the Unix command line you can just use the WGET command. Before we look at some examples let’s answer the most basic of questions.

Why would I want to manually convert HTML to PDF?

Good question. You may think you can also just throw it in our online conversion service at the home page. While that works if you don’t want to pass any options, it will not take the defaults you have set in your members area nor will it accept any additional options. It’s a free service after all..

So if you want to use those defaults in the members area or if you want to pass the extra options that the API allows, you can quickly use the manual conversion option. You can use it to test if the parameters you’re passing in the code should do (so to test your code) or to quickly do a few manual conversions of documents that you need to have without using any code.

It’s basicly your cut and dry toolset for manual conversions and although we said it’s not geeky – it may be a little 😉

How do I manually convert a URL to PDF in the browser window?

Well this basicly couldn’t be easier. You just type in the URL with the right parameters!

So if your API key is ‘yourapikey’ and you want to convert ‘http://www.google.com’, you’ll throw the following in the browser address bar to get the PDF version of Google. By the way – of course you’ll first sign up to get your api key.

https://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com

And if you would like to add options for the conversion you just add them as parameters to the above. So if you want the PDF to be 400mm wide and 600mm high you’d make it:

http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com&width=400&height=600&unit=mm

An overview of all the options is available at the documentation page of our API.

How do I convert a URL to PDF from the command line?

Unix sports the wonderful WGET command and we can use this to convert HTML to PDF from the command line. So let’s take the examples that we used above again and see what they’ll look like.

To just convert google and save it in the file ‘google.pdf’ you’d use the following command:

wget -O google.pdf 'http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com'

Note that you’ll be using the -O option to indicate the filename and that you’re using quotes to escape the URL you’re calling.

And the other example of adding parameters would work as well. So if you want the PDF to be 400mm wide and 600mm high you’d make it:

wget -O google.pdf 'http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com&width=400&height=600&unit=mm'

Conclusion

Hopefully I made the point of how easy it is to use our API manually as well. If you want to know more about it – check out the documentation or just sign up for a monthly plan!

Posted by & filed under HTML to PDF API, HTML to PDF conversion.

Converting a HTML web page into a PDF can be easily done in Java with our HTML to PDF API. We’ll show you the basic steps and point you to all options you can use to customize the conversion process.

You don’t need to install any additional libraries or anything. All you need to do is sign up for our service and you’ll get an API key. Then you’ll just call our API over a HTTP connection and we’ll send you the converted PDF in return. You’ll be up and running in minutes!

Example code for HTML to PDF conversion in Java

Suppose you’d like to convert the web page ‘http://www.digg.com’ to PDF, just because Digg is awesome. We’ll use ‘yourapikey’ as the example API key in the code below. You’d use the following simple statements to get this job done.

String apikey = "yourapikey";
String url = "http://www.digg.com";
File outs = new File("C:\\temp\mypdf.pdf");

URL u = new URL("http://api.htm2pdf.co.uk/urltopdf?apikey=" + apikey + "&url=" + url);
URLConnection uc = u.openConnection();
BufferedInputStream is = new BufferedInputStream(uc.getInputStream());
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(outs));

byte[] b = new byte[8 * 1024];
int read = 0;
while ((read = is.read(b)) > -1) {
bout.write(b, 0, read);
}
bout.flush();
bout.close();
is.close();

As you can see you’ll set up a connection to the URL of our API service and pass the ‘apikey’ and ‘url’ parameters to get the job done. Easy peasy. That’s really all there is to it. If you want to use more options, like watermarking, pdf encryption, different page formats or what not – you just add extra parameters to the URL and it will work.

The options you can add can be found in our online documentation. If you are excited to get going now – Sign up here!

Posted by & filed under PDF security.

Today we’ll be going over PDF encryption and protection options, which also cover what Adobe calls ‘Rights management’. We’ll explain what kind of different options there are, what they are intended to do and how they are used in our HTML to PDF API services.

There are three basic components of PDF security.

  1. Encryption
  2. Password protection
  3. Rights management

We’ll cover these one by one in this order, because it should be noted that you can only have password protection and rights management if you encrypt the PDF as well. Well of course that kind of makes sense, cause why would you protect a PDF with a password if the contents remain readable in the same manner?

PDF encryption

So what exactly is PDF encryption, what are the consequences and what are the options or flavours?

PDF encryption is done with a key of either 40, 128 or 256 bits. It causes the contents of the file to be encrypted so that anyone, who wants to access the contents needs the user (or document open) password to access it. An important side effect of this is that search engines can not read the contents of the PDF either (as you may know a lot of them, the almighty Google included, index PDFs as well).

The key length and algorithm type determines the strength of the encryption and the resulting security of the PDF. 40-bit RC4 encryption is the weakest form of encryption and 256-bit AES the strongest, which is currently supported. Adobe reader X is needed to open documents encrypted with 256-AES.

If you want to know how safe these encryptions are – 40-bit RC4 is known to be susceptible to brute force attacks and currently it is thought that brute force attacks on 256-AES are not possible. So the longer the better and AES is better than RC4: 40-bit RC4 < 128-bit RC4 < 128-bit AES < 256-bit AES.

Password protection

An encrypted PDF can have two passwords: an owner password and a user (or document open) password.The owner password doesn’t actually do anything in terms of encryption, but is used to control rights management (see the section about that below). The user password (or document open password) is the password that matters. It makes sure the file is properly encrypted and your users will need it to open the file. You’re advised to use this and forget about using an owner’s password. For more information check Wikipedia on this.

Rights management

Rights management is a great idea by Adobe. The idea is that the owner of the PDF can determine if others are allowed to modify the document, can make annotations, can print the PDF and/or can copy from the document. All these settings can be controlled and set individually.

Although this idea in itself is great – it only works in controlled environments where everyone is using Adobe Reader. This is because other PDF reading programs can choose to ignore these settings. You see – the PDF standard is open and this means anybody can write a program reading PDFs and choose what to interpret when they read a PDF file and how to deal with what they read. Hence – PDF readers exist that ignore these settings.

Options supported by our HTML to PDF API services

As you know by now, we have two HTML to PDF API services – a so-called ‘simple API‘ and an ‘advanced API‘. The simple API supports all different encryption keys, both the owner & user password and the possibility of determining whether a file can be printed, modified or content copied. The advanced API supports all options, so that means the full scala of rights management as well instead of the scaled down version.

If you want to learn more about our services – find out everyting at the HOW IT WORKS page. You may also just want to SIGN UP!

Posted by & filed under HTML to PDF API, HTML to PDF conversion.

So you want to convert HTML to PDF in C#? Well – you’ve come to the right place. We’ve made our HTML to PDF API so easy that you’ll be converting any URL to PDF in C# in a matter of minutes.

Our API works by sending a HTTP request with the parameters for the conversion. There’s no library or anything for you to install. You’ll only need a valid API key, which you can get by signing up for our service. In this article we assume your API key is “yourapikey” and we’ll use this in the sample code.

The sole purpose of the code is to send a HTTP request that looks like this:

https://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com

As you can see you send us a request with just the API key and the URL and in return we’ll send you the PDF. We’ll use the settings in your members area for the conversion. If you want to adjust these you can add parameters to the URL to indicate how you want to do the conversion. We’ll get to that later.

Now suppose you want to do the above URL to PDF conversion in C#. The code you’ll be using will be the following:

string apiKey = "yourapikey";
string url = "http://www.google.com";

using (var client = new WebClient())
{
client.QueryString.Add("apikey", apiKey);
client.QueryString.Add("url", url);
client.DownloadFile("http://api.htm2pdf.co.uk/urltopdf", @"c:\temp\mypdf.pdf");
}

This will get the PDF and store it in the file ‘mypdf.pdf’ in your temp directory.

Adding PDF conversion options in C#

If you want to change the options for the conversion in C#, you can just add extra parameters to the query string and the API will obey your orders. You can find an overview of all the different parameters you can pass in the description of the HTML to PDF API.

For now let’s assume you want to watermark the PDF with our logo and rotate it 45 degrees. You’d then add the correct watermarking parameters to the query string and that’s all there is to it!

Your code would look something like this:

string apiKey = "yourapikey";
string url = "http://www.google.com";
string wm = "http://www.htm2pdf.co.uk/img/logo.png";
string wm_angle = "45";
using (var client = new WebClient())
{
client.QueryString.Add("apikey", apiKey);
client.QueryString.Add("url", url);
client.QueryString.Add("wm", wm);
client.QueryString.Add("wm_angle", wm_angle);
client.DownloadFile("http://api.htm2pdf.co.uk/urltopdf", @"c:\temp\mypdf.pdf");
}

We think this should get you converting HTML to PDF in C# over the next 10 minutes. All you need now is a valid API key, which you can get here. If you want to more about the HTML to PDF API and what all the different conversion options are, then go to the extensive documentation.

Posted by & filed under HTML to PDF API, HTML to PDF conversion.

Converting HTML to PDF in Java is very simple with our easy-to-use HTML to PDF API. In this post we will show you some basic examples of how you can use the PDF API in Java and what kind of options you can use for the conversion as well as additional options like password protection and watermarking.

Our HTML to PDF API works by sending a HTTP GET request. You’ll need an API key and then you’ll be ready to use it in any language you want, so also Java, which we’ll be discussing now. In this post we’ll assume your api key is ‘yourapikey’. You’ll get your own key when you sign up for a HTML to PDF api plan.

A basic URL to PDF conversion of http://www.google.com is done by sending the following HTTP request:
[html light=”true”]http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com[/html]
In the above example you’re converting the URL ‘http://www.google.com’ into a PDF, which you’ll receive from us. The conversion is done with the defaults that you have in your own members area. If you want to use different settings for the conversions you will append other parameters to the HTTP request, which we’ll show you later on this post.

Now let’s see how you would do this URL to PDF conversion in Java.
We’ll assume you want to store the PDF we send you in the file ‘mypdf.pdf’:

String apikey = "yourapikey";
String url = "http://www.google.com";
File outs = new File("C:\\temp\mypdf.pdf");

URL u = new URL("http://api.htm2pdf.co.uk/urltopdf?apikey=" + apikey + "&url=" + url);
URLConnection uc = u.openConnection();
BufferedInputStream is = new BufferedInputStream(uc.getInputStream());
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(outs));

byte[] b = new byte[8 * 1024];
int read = 0;
while ((read = is.read(b)) > -1) {
bout.write(b, 0, read);
}
bout.flush();
bout.close();
is.close();

From the above example you see it’s really nothing more then forming a URL that calls our API, setting up the connection and writing the results to your output stream.

The most important command in the example is:

URL u = new URL("http://api.htm2pdf.co.uk/urltopdf?apikey=" + apikey + "&url=" + url);

That command controls the way the API is called. If you want to pass additional settings to the API for the HTML to PDF conversion then you’ll have to do that here by appending them to the URL.

There are a lot of conversion settings you can use with our API – you can find a detailed overview of them in the description of the HTML to PDF API. There are basicly three types of settings:

  1. Settings for the actual conversion itself – page format, single page PDF, margins, header and footer etc
  2. Settings for security and protection of the resulting PDF like password protection, encryption etc
  3. Settings for watermarking or stamping of the resulting PDF

Now let’s look at an example where you want to convert a URL to PDF and you’d like get a password protected PDF from us. You’d then need to pass two additional parameters to the API: the owner password and the user password. The owner password is the password that controls the security settings of the PDF and the user password is the password that you give to the user who needs to open the document.

You would need to append these two options to the URL we already had and to do this you just change the first couple of lines of the code to:

String apikey = "yourapikey";
String url = "http://www.google.com";
String op = "verysecret";
String up = "alsosecret";
File outs = new File("C:\\temp\mypdf.pdf");

URL u = new URL("http://api.htm2pdf.co.uk/urltopdf?apikey=" + apikey + "&url=" + url + "&ownerpass=" + op + "&userpass=" + up);

This will get the job done and get you PDF protected with owner password “verysecret” and document open password “alsosecret”.

Hopefully this shows you how easy it can be to convert HTML to PDF in Java with our HTML to PDF API. If you want to learn more about the PDF API then please check out the documentation. If you want to use it then please sign up for a HTML to PDF API plan.

Posted by & filed under HTML to PDF conversion, Save as PDF.

Our core business is converting HTML to PDF and as such we deal with a lot of web site owners that want their visitors to be able to just click a link or button on their website and trust that they will get a PDF in return.

This functionality is called a save as PDF button or save as PDF link. The interesting thing is that although it’s quite easy for web sites to get such a button or link on their web site and – with a little help from our web site – to have it working perfectly, there’s quite a bit of technology behind it to make it work well.

So that brings us to a few questions, such as:

  • Can I built that functionality myself?
  • If I can’t build it myself – how do I get it?
  • What kind of things can I do with it?
  • Can I get a free save as PDF link for my website?

Of course there are many more questions, and we’ll be sure to cover those in another article, but let’s look at these first.

Can I built this functionality myself?

So you think you can dance built a HTML to PDF conversion tool, hum? Well, unfortunately it’s not as easy as it sounds.

You’ll need to first get a piece of conversion software that allows you to convert HTML to PDF. Now if you do a little Google search you’ll find quite a few alternatives, although the king of search engines will not immediately tell you which one will work for you and why. For that you’ll be searching some hours and maybe days more. You’ll then buy it – or download it for free.

Next you’ll be tuning that piece of conversion software and beat it into submission with countless commands and modifications to make sure it does what you want it to do. Cause maybe you didn’t hear this before, but no – none of them do what you want out of the box. And obviously you’ll be testing it, arrange power for it (in the form of expensive hosting) and then test it some more.

Finally you’ll built the interface between your ‘save as PDF’ button and your beautiful customized piece of conversion software. You’ll tweak it for all the specific needs you have and then you’ll start testing and testing again.

Does that sound like a nice little adventure? Well – actually for us it does, but we guess we’re not like most people. So the answer to the question is – yes, but it’s a major piece of work to do and to uphold.

So…

If I can’t build it myself – how do I get it?

This question is actually very easy to answer. We offer a great save as PDF service for your website that allows your visitors to save your webpages with one click. You can find all the information at our save as PDF information page.

What kind of things can I do with it?

When you use our save as PDF service you will get a whole lot of things with it that allow you to tweak the links to perfection and also use it for a variety of functions. You’re not restricted to just converting the page the visitors is looking at or just a few character sets. No – we offer support for the following:

  • all major character sets like Asian, Arabic, Cyrillic and Western fonts
  • all standard page formats like A0, A1, A2, A3, A4, letter, tabloid etc as well as custom page formats
  • custom margins and a custom header and/or footer
  • fitting a web page to a single page PDF
  • conversion of any other URL on the same web site in the ‘save as PDF’ link

And we offer some other things as well. All these things can be tuned just by adding a parameter in the save as PDF link that you put on your website. Find more information in our save as PDF link page.

Obviously with all that greatness comes a price tag, although it’s a small one. If you want a free save as PDF link on your site, it brings us to the last question:

Can I get a free save as PDF link for my website?

The answer is a simple – YES. We offer that too. By just link your Save as PDF link to our homepage you’ll get that functionality.

Your link would look something like:

<a href="http://www.htm2pdf.co.uk">Save this page as PDF</a>

If your visitor arrives at our site we will detect the referring page (which is the page on your website) and we’ll convert it to PDF for you. Your visitor can then download it from our website.

The big differences between this free save as PDF functionality and the paid service are the following:

  • your visitor will see our website with the free version
  • you’ll not be able to customize any settings for the conversion with the free version

We’ll welcome you to the free version as much as to the paid service though. Please enjoy whichever service you prefer.