Posted by & filed under Save as PDF.

One of our popular services is the ‘save as PDF’ functionality. This allows you to add a link to your webpages that your visitors can click on and get a PDF of that particular webpage or any other webpage on the same (sub)domain.

The reason it’s so popular is that it allows website owners to have their visitors create PDFs that look exactly like their webpages. This is useful for sharing blog posts, brochures, but also more data oriented pages like reports, invoices or fact sheets. And it literally integrates in MINUTES! Yes, that’s minutes, not hours.

Let’s highlight the most important reasons for using this functionality:

  • your visitors can save webpages with just a single click in any web browser
  • OTHER WEBPAGES can be saved than just the one the visitor is looking at – this is useful in case you want to add/remove certain information or slightly adjust it to paper settings or what not
  • PDFs are created in high quality and rendered by webkit, which is the engine that supports major browsers like Safari and Chrome and supports HTML, CSS and JavaScript – so it’s truly WYSIWIG

Features

Let’s look at the features of this functionality and how to invoke it. There’s basically two ways of fine-tuning the ‘save as PDF’ functionality (actually all of our services) i.e. – by setting defaults in the elaborate members area and by adding parameters in the call of the functionality.

Calling the functionality is very simple – you just add a link to http://www.htm2pdf.co.uk/display to your website. When your visitors click it – we’ll send him the PDF and that’s it. And of course the members area is also designed to be very user friendly. Every setting can be configured in seconds.

If you want to know how to really set the settings and look at examples – please visit the save as PDF section. This post only explores the features and explains what they do and if you can use them as default or custom.

SettingDefault
(Members area)
Override
(With Parameter)
Webpage to convertcurrent pageyes – any URL on the same (sub)domain
Filenamecurrent URLyes – to any name you want
Page Formatyesyes
Single page PDFyesyes
Headeryesno
Footeryesno
Marginsyesyes
JavaScriptyes + control delayno
Grayscaleyesno
Display Imagesyesno
Display Backgroundyes no
Offset Page numberyes no

We’re quite confident that this makes our “save to PDF” functionality the most comprehensive in the business. Especially the fact that you’re able to set so many defaults quickly and easily in the members area AND that you’re able to pass any URL on the same subdomain is what sets our service apart.

Add that to the great quality of conversion we deliver and we feel we are the creme de la creme!

Check out the full description or just sign up and have your link up in a few minutes from now!

Posted by & filed under HTML to PDF API.

Today I’m going to continue the series on converting HTML to PDF with one line of code with our HTML to PDF API. I’ll be trying to accomplish the same we did in PHP, C#, Java and Ruby in our previous articles, but now in Perl. This will also be the conclusion of this series and I certainly hope you enjoyed it!

Now let’s look at the ‘rules of the game’ again:

  • we’ll only send the HTTP request necessary to do the URL to PDF conversion
  • we’ll refrain from error handling (of course you’d normally do that in your real implementation)
  • we’ll not destroy created objects properly (of course you’d normally do this as well in your own implementation)
  • we’ll not count lines of code that we need to include libraries (mind you: we only use standard libraries, as our API does not require you to install anything you don’t already have)

Now let’s have a look at the challenge request that we’d like to send.

The challenge HTTP request

Our sample HTTP request, that we want to send in Perl is the following:

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

This will use our API with API key yourapikey, URL http://www.google.com and turn it into an encrypted PDF with user password htm2pdf.

Coding the conversion in Perl

In our API documentation we used something like this.

use File::Fetch;

my $apikey = 'yourapikey';
my $url = "https://www.google.com";
my $up = "htm2pdf";

my $ff = File::Fetch->new(uri => "https://api.htm2pdf.co.uk/urltopdf?apikey=$apikey&url=$url&userpass=$up");
my $where = $ff->fetch( to => '/tmp/mypdf.pdf');

Now let’s see what we’ve got.

The code starts with the inclusion of File::Fetch. We won’t be counting that as a real line, since we said in the prerequisites that we won’t the count inclusion of modules. Then the code breaks up the parameters apikey, url and userpass in separate lines and then uses them in the declaration of a new instance of  File::Fetch. Then the result is received into the file /tmp/mypdf.pdf in the next line.

Now here’s a little catch – we said we wouldn’t be counting the storing in the file of the result. In this situation, the sending of the request as well as storing the result is actually in that one line.

So how can shorten this? If we wouldn’t break up the parameters in separate lines and forget about including the module, we would get the following:

my $ff = File::Fetch->new(uri => "https://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=https://www.google.com&userpass=htm2pdf");
my $where = $ff->fetch( to => '/tmp/mypdf.pdf');

That’s only two lines!

Now we can start the debate about whether or not we can remove an extra line, due to the requirements that we laid out. Or we can just say :

WOW! Only two lines of code needed to get a PDF of the highest quality including conversion options!

So we’ll do that instead of argue with you 🙂

Conclusion

This is the end of our series on converting HTML to PDF in one line of code. We set a high goal and sometimes we could achieve it e.g. when we called the API in PHP and Ruby in just a single line or come very close, like today where we could do it in only two lines with Perl or recently when we did it in two lines with C# / .NET.

So I’d like to think that our API could not be much easier to use and therefore quicker to deploy. I hope you enjoyed the series and that you’re at least a little bit impressed by the power of our service.

For now – if you want to learn more about the HTML to PDF API – have a look at the documentation! If you want to use it – SIGN UP!

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

All our services offer the possibility of passing a URL as a parameter so that specific URL will be converted to a PDF. We see a lot of our users struggle the first time they want to pass a URL that contains additional parameters separated by an ampersand (&) sign.

Most of the time you’ll see usage examples in the documentation describing how you can convert the Google website or another straightforward site with a simple URL like http://www.google.com or http://www.nytimes.com. The reasoning behind this is that all URLs will work and there’s not so much that’s difficult about URLs.

Today we’ll talk about an exception: additional parameters passed to the URL with the ampersand (&) character. These URLs will look like:

http://www.example.com/news?author=peter&date=20130316

Usage of the ampersand in our services

You can pass URLs with additional parameters in all our services. In two of them you have to escape the ampersand in the URL you’re passing to %26. This is because you’re already passing other parameters (your apikey, width, height etc) with the ampersand sign as well.

Let’s look at the syntax:

  1. Our Save as PDF functionality
    Here you put a link to http://www.htm2pdf.co.uk/display on your page and if you want to convert a different URL containing an ampersand you would put the following link up:

    http://www.htm2pdf.co.uk/display?url=http://www.example.com/news?author=peter%26date=20130316
  2. Our HTML to PDF API
    With the API you’d do pretty much the same as with the save as PDF functionality. You use HTTP GET to call it, which means you send a HTTP request and that means you have to escape the ampersand in the same way. So if you want to convert the example URL you’d have send a request to:

    https://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.example.com/news?author=peter%26date=20130316

    Note – only the ampersand in the URL you’re passing is translated to %26!

  3. Our HTML to PDF SDK
    With our PHP library you don’t have to worry about escaping anything. Since you’re calling a predefined function that we programmed and is included in your library file, we’ll make sure everything works fine without you thinking about anything. You just pass whichever URL you’d normally type in the browser and we’ll convert  that one.
    So you’d just go and do:

    $pdf->ConvertFromURL('http://www.example.com/news?author=peter&date=20130316');

Translation of the ampersand in coding

For most of you who got this far it’s probably just a matter of ‘AHA!’ and you already know what to do. You’ve been passing the wrong URL a couple of times, took a look at the documentation and are on your way.

Now if you’re still reading you may want to learn what the easiest way is to add the %26 to the URL. I’ll give you a few pointers in PHP and invite all others to give a shout out in the comment box to do the same in C#, Java, Ruby or whatever programming language they’re fluent in.

Example 1
Suppose you already have the URL in parameter $url. You could then just go and do:

$url = str_replace('&','%26', $url);

Example 2
Suppose you have the building blocks of the URL and you were previously doing something like:

$url='http://www.example.com/news?author=' . $author . '&date=' . $date;

Then now you’d go and do the following:

$url='http://www.example.com/news?author=' . $author . '%26date=' . $date;

Now these are just basic examples. I hope you get the idea. If not – scream in the comment box and I’ll try to improve on this.

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

Today I’m going to continue the series on converting HTML to PDF with one line of code with our HTML to PDF API. I’ll be trying to accomplish the same we did in PHP, C# and Java in our previous articles, but now in Ruby.

Now let’s look at the ‘rules of the game’ again:

  • we’ll only send the HTTP request necessary to do the URL to PDF conversion
  • we’ll refrain from error handling (of course you’d normally do that in your real implementation)
  • we’ll not destroy created objects properly (of course you’d normally do this as well in your own implementation)
  • we’ll not count lines of code that we need to include libraries (mind you: we only use standard libraries, as our API does not require you to install anything you don’t already have)

Now let’s have a look at the challenge request that we’d like to send.

The challenge HTTP request

Our infamous HTTP request, that we want to send in Ruby today is the following:

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

This will use our API with API key yourapikey, URL http://www.google.com and turn it into an encrypted PDF with user password htm2pdf.

Coding the conversion in Ruby

In our API documentation we used code similar to the following to do this.

require 'net/http'
apikey = 'abcde12345'
url = 'http://www.google.com'
userpass = 'htm2pdf'

uri = URI("http://api.htm2pdf.co.uk/urltopdf?apikey=#{apikey}&url=#{url}&userpass=#{userpass}")
Net::HTTP.start(uri.host, uri.port) do |http|
request = Net::HTTP::Get.new uri.request_uri

http.request request do |response|
open 'mypdf.pdf', 'w' do |io|
response.read_body do |chunk|
io.write chunk
end
end
end
end

Now this is quite a bit of lines so let’s break it down.

The code starts with the inclusion of net/http. Well right off the bat – we’re not counting that line as we agreed in the prerequisites (inclusion of modules). Then it breaks up the parameters apikey, url and userpass in separate lines and then feeds them to a URI after which this is fed to the Net module and then the request is executed HTTP::GET.

After that we’ll have the lines that move the result of the request to a file.Also – we’ll not be counting those as we said we’d only SEND the HTTP request in our example…

So how can shorten this? If we wouldn’t break up the parameters in separate lines and forget about including the module and feeding the response to a file, we would get the following:

uri = URI("http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com&userpass=htm2pdf")
Net::HTTP.start(uri.host, uri.port) do |http|
request = Net::HTTP::Get.new uri.request_uri

We’re getting close! Only three lines left.

Now after some more searching and searching we think we found the holy grail! Apparently, you can just do the following in Ruby and you’re done:

result = Net::HTTP.get(URI.parse('http://api.htm2pdf.co.uk'), '/urltopdf?apikey=yourapikey&url=http://www.google.com&userpass=htm2pdf')

Conclusion

In the previous posts we could convert HTML to PDF in one (PHP) or two (C#) lines, but we didn’t manage to do it in Java so quickly. In Ruby we succeeded again! Just one single line and you’ll get a great looking PDF from our simple API.

Python, Perl and maybe some other programming languages will be next on the menu of this series and hopefully with similar success.

Stay tuned!

For now – if you want to learn more about the HTML to PDF API – have a look at the documentation! If you want to use it – SIGN UP!

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

Today I’m going to continue the series on converting HTML to PDF with one line of code with our HTML to PDF API. I’ll be trying to accomplish the same we did in PHP and C# last time, but this time in Java.

Now just to summarize the ‘rules of the game’ again:

  • we’ll only send the HTTP request necessary to do the URL to PDF conversion
  • we’ll refrain from error handling (of course you’d normally do that in your real implementation)
  • we’ll not destroy created objects properly (of course you’d normally do this as well in your own implementation)
  • we’ll not count lines of code that we need to include libraries (mind you: we only use standard libraries, as our API does not require you to install anything you don’t already have)

Now let’s look at the challenge request again.

The challenge HTTP request

Our challenge HTTP request, that we will want to send in Java today is going to be the following:

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

This will call our API with the API key yourapikey, the URL http://www.google.com and turn it into an encrypted PDF with user password htm2pdf.

Coding the conversion in Java

In our API documentation we used code similar to the following example code to get this done.

String apikey = "yourapikey";
String url = "http://www.google.com";
String userpass = "htm2pdf";

File outs = new File("C:\\temp\mypdf.pdf");

URL u = new URL("http://api.htm2pdf.co.uk/urltopdf?apikey=" + apikey + "&url=" + url + "&userpass=" + userpass);
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();

This code breaks up the parameters apikey, url and userpass in separate lines and then feeds them to a BufferedInputStream after which this is read and the results fed to a BufferedOutputStream. Now all in all those are probably the most lines of code we’ll be needing in any language to use our API. So let’s see what we can do to reduce it a little and maybe end up with just one line.

Now if we wouldn’t break up the parameters in separate lines, we’d loose 3 lines in the beginning. We would then get:

File outs = new File("C:\\temp\mypdf.pdf");

URL u = new URL("http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com&userpass=htm2pdf");
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();

Hmmm…. That’s just swell (Clint would say this back in the day), but we still have a lot of lines left. What can we do now?

The truth is – we’re not really Java experts and a lot of browsing on the web also indicates we’re running out of possibilities here. The lines that we need to transfer the inputstream to the outputstream can not really be shortened so we’re stuck with at least that.

So we’re gonna be stuck with approximately 12 lines of code to get the job done. But then again – you will also have the PDF stored as a file and not just in a buffer or in memory.

Conclusion

In the previous posts we could convert HTML to PDF in one (PHP) or two (C#) lines, but we didn’t manage to get that close in this post. I blame this partly on our limited knowledge of Java (yes, this is a shoutout to anyone who wants to comment!), but also on the fact that Java is a little bit more elaborate and strict than other languages. But althoug I wasn’t able to trim it down to one or two lines, it’s still only a really limited set of lines and you’ll still get a very high quality PDF from a HTML page in return!

Now, before I sign off – if you have a way of doing this in fewer lines – then please shout it out at the comments!

In the next articles in this series I’ll try to show you that you can accomplish the same in Ruby, Python, Perl and maybe some other programming languages.

Stay tuned!

For now – if you want to learn more about our HTML to PDF API – have a look at the documentation! If you want to use it – SIGN UP!

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

Today I’m going to continue the series on converting to PDF with one line of code with our HTML to PDF API. I’ll be trying to accomplish the same we did in PHP last time, but this time in C# or .NET.

Now just to summarize the ‘rules of the game’ again:

  • we’ll only send the HTTP request necessary to do the URL to PDF conversion
  • we’ll refrain from error handling (of course you’d normally do that in your real implementation)
  • we’ll not destroy created objects properly (of course you’d normally do this as well in your own implementation)
  • we’ll not count lines of code that we need to include libraries (mind you: we only use standard libraries, as our API does not require you to install anything you don’t already have)

Now let’s look at the challenge request again.

The challenge HTTP request

Our challenge HTTP request, that we will want to send in C# today is going to be the following:

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

This will call our API with the API key yourapikey, the URL http://www.google.com and turn it into an encrypted PDF with user password htm2pdf.

Coding the conversion in C#

In our API documentation we used code similar to the following example code to get this done.

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

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

This code breaks up the parameters apikey, url and userpass in separate lines and then feeds them to the WebClient.Downloadfile statement. This is actually the one, which calls and executes the HTTP request (aka calling the API) and stores the result in the file we specify. The using clause is there to make sure we dispose the created object correctly.

Now if we wouldn’t break up the parameters in separate lines, we’d loose 3 lines in the beginning. We would then get:

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

Then we can also just specify the parameters in the URL directly and gain another three lines.

using (var client = new WebClient())
{
client.DownloadFile("http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com&userpass=htm2pdf", @"c:\temp\mypdf.pdf");
}

And last we can also remove the using statement and we’d be left with the following two lines only:

var client = new WebClient();
client.DownloadFile("http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com&userpass=htm2pdf", @"c:\temp\mypdf.pdf");

Now – at this point I’m at a loss here. Can we lose one line more somehow? Or should I even count the 1st line as a line? Cause the ground rules of counting say that we weren’t going to include disposing of newly created objects. But I guess creating an object is something else than disposing of it…

Conclusion

In this post I showed that we can get C# allows to call the API and do the URL to PDF conversion in just two lines of code. I wasn’t able to trim it down to one, like we did in PHP, but I’d say it’s not a whole lot of code to get an awesome high quality PDF from a HTML page!

Now, before I sign off – if you have a way of doing this in one line – then please shout it out at the comments!

In the next articles in this series I’ll try to show you that you can accomplish the same in Java, Ruby, Python, Perl and maybe some other programming languages.

Stay tuned!

For now – if you want to learn more about our HTML to PDF API – have a look at the documentation! If you want to use it – SIGN UP!

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

Today I’m going to start a series on our HTML to PDF API. I’ll be trying to accomplish something really cool – converting a URL to PDF with just a single line of code. And I’m going to try to accomplish that in PHP first, but the next parts of the series are going to be about C#, Java, Python, Ruby, Perl etc.

Right off the bat I can tell you it’s not going to be possible to convert a URL to PDF, do all kinds of error handling, include libraries and what not – with just a single line of code. Mind you – for the HTML to PDF API you will never need any libraries, you don’t already have on your system though.

What we will limit our challenge to, is that we want to call our API with several options and still use as few lines of codes as possible. And hopefully that will just be one. At the beginning of the series we’re jumping in the deep here – cause I really don’t know if I’m going to succeed to do it in one line in each programming language.

The challenge HTTP request

Our challenge HTTP request, that we will want to send for each programming language is going to be the following:


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

This will call our API with the API key yourapikey, the URL http://www.google.com and turn it into an encrypted PDF with user password htm2pdf.

Coding the conversion in PHP

In our API documentation we used code similar to the following example code to get this done.

$apikey = 'yourapikey';
$url = 'http://www.google.com';
$userpass='htm2pdf';

$result = file_get_contents("http://api.htm2pdf.co.uk/urltopdf?apikey=$apikey&url=$url&userpass=$userpass");
file_put_contents('/tmp/mypdf.pdf',$result);

This code breaks up the parameters apikey, url and userpass in separate lines and then feeds them to the file_get_contents command. This is actually the one, which calls and executes the HTTP request (aka calling the API). Subsequently we used file_put_contents to put the PDF in a file with the name /tmp/mypdf.pdf.

Now if we wouldn’t break up the parameters in separate lines, we’d already be done. We would get the PDF in one line of code with:

$result = file_get_contents("http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com&userpass=htm2pdf");

As a bonus we can even save it to a filename as well in the same statement, if we just pass the file_get_contents statement as a parameter to the file_put_contents statement.

It will become this:


file_put_contents('/tmp/mypdf.pdf', file_get_contents("http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com&userpass=htm2pdf"));

Conclusion

In this post I showed you that PHP allows you to call the API to do the URL to PDF conversion in just a single line of code. I don’t really recommend this, because it will not make your code easily legible, but for testing purposes this is of course AWESOME!

It also shows how easy-to-use our API really is. In the next articles in this series I’ll hope to show you that you can accomplish the same in C#, Java, Ruby, Python, Perl and maybe some other programming languages.

Stay tuned!

For now – if you want to know more about the API – see the full documentation! If you want to start using it – SIGN UP!

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

Last week we did an article about using HTML to PDF API from the command line. I think it illustrated well how easy the API works, yet how powerful it is.

It also made me realize that Perl is both these things. I think a lot of people nowadays don’t give Perl the credit it deserves and look at Perl as archaic or just plain ‘old’. I think it deserves more credit and definitely more respect. I still feel Perl opened a lot of doors to begin with in the days of old and furthermore – it’s still used succesfully to the day of today and will be in the future!

Therefore – today we’ll be looking at conversion with the HTML to PDF API in Perl.

Basic HTML to PDF API usage

So as we have seen in previous posts and can be seen in the documentation of the API, the API works by sending HTTP requests of the following form:
[html light=”true”]http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com[/html]
And in Perl we can send a HTTP request easily, by using either the File::Fetch or the LWP::Simple module. So if we want to send the above HTTP request in Perl we could do the following to get your PDF saved in the /tmp directory:

use File::Fetch;
use URI::Escape;

my $apikey = 'yourapikey';
my $url = uri_escape ("http://www.google.com");

my $ff = File::Fetch->new(uri => "http://api.htm2pdf.co.uk/urltopdf?apikey=$apikey&url=$url");
my $where = $ff->fetch( to => '/tmp');

So that’s quite easy, isn’t it?

Using other options of the HTML to PDF API in Perl

Just as the basic usage is very easy, adding options (of which there are many – like page size, margins, encryption, watermarking etc.) is also a breeze. You just attach some extra parameters to the API URL you’re sending the HTTP request to!

For example – if you want to create a single page PDF of http://www.digg.com, you want it to be 10 inches wide and you want the PDF to be protected with the password ‘htm2pdf’ then you’d add the following parameters to the API URL:

  • width=10 (to indicate the width, also – by not specifying height you will get one long single page PDF)
  • unit=in (for the unit of the width)
  • userpass=htm2pdf (for the document open password)

Now the example in Perl becomes the following:


use File::Fetch;
use URI::Escape;

my $apikey = 'yourapikey';
my $url = uri_escape ("http://www.digg.com");
my $width = '10';
my $unit = 'in';
my $pass = 'htm2pdf';

my $ff = File::Fetch->new(uri => "http://api.htm2pdf.co.uk/urltopdf?apikey=$apikey&url=$url&width=$width&unit=$unit&userpass=$pass");
my $where = $ff->fetch( to => '/tmp');

Conclusion

The point I tried to make today is that Perl is still out there and will be for times to come. And that it’s our honour to show that also Perl can easily be used effectively with our API. I hope I succeeded.

If you want to know more about the various options this API has, then please look at the extensive documentation we have. If you want to give it a try – then please Sign Up!

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

As you may know we have two different ways of creating PDFs from your application – our HTML to PDF API and our HTML to PDF SDK.Since not everyone is so familiar with the terms API and SDK, we’ll try to explain them in this post and look at the differences.

The term API is short for Application Programming Interface and is a protocol intended to be used as an interface by software components to communicate with each other (see Wikipedia). So basicly it’s a set of rules that describes how two or more ‘systems’ communicate with each other. Wikipedia goes on to state that it can take many forms and be simple or elaborate.

The term SDK is short for Software Development Kit and is typically a set of software development tools that allows for the creation of applications for a certain software package, software framework, hardware platform, computer system, video game console, operating system, or similar development platform (see Wikipedia). So it means you get tools that allow you to create stuff fast.

Our interpretation of API vs SDK

When we were developing our services we wanted to make sure that they were easy-to-use and quick to deploy no matter what. But we also realized that some people want to have more freedom and others want to lay down in a made bed, that’s warm and cosy. So we made our HTML to PDF API as a basic definition that allows you to generate a PDF from a URL by just sending a HTTP request and we made our HTML to PDF SDK as a fully equipped PHP library that not only does the HTML to PDF conversion, easily adds all kinds of options, but also takes away your worries about error handling, displaying PDFs and what not.

Both the API as well as the SDK are packed with functionality in terms of conversion, although the SDK has a lot more and is one of the most (if not THE most) complete on the market.

Functional differences

So what are the differences in functionality of the API compared to the SDK? Well, let’s make a little list then… But before we start with the list you should know the SDK is only available in PHP right now. This is because it’s a library, which spans quite a few lines of code and has to be maintained, tested etc on an ongoing basis. We’ll be adding different languages in the future, but for now we only offer it in PHP. The HTML to PDF API on the contrary works in ALL programming languages and our site contains examples in the most used programming languages.

Now back to the list. What can you do with the HTML to PDF API and what can you do with the HTML to PDF SDK?

With the API as well as the SDK you can do the following (mind you – non-exhaustive list):

  • convert any URL to PDF
  • use CSS2, quite some CSS3, many character sets – all in high quality
  • use all standard page formats as well as any custom format you can think of
  • have the ability to create single page PDFs
  • use custom margins
  • pre-define a header and/or footer
  • use PDF encryption, password protection and rights management
  • use an image as watermark and control positioning, rotation and opacity

That’s quite a bit, isn’t it? Well, the SDK on top of that allows you to do the following:

  • convert raw HTML, local files and custom forms with parameters (which we can build for you)
  • control PDF rights management in more detail
  • use a text in any font, size and color as a watermark
  • easily control what to do with the resulting PDF – whether to display it inline or as attachment or save it
  • build the code in your application quickly and with built in error checking with the easy-to-use PHP library

It’s a also noteworthy that from a technical perspective the HTML to PDF API works over HTTP GET, while the HTML to PDF SDK sends all data over HTTP POST. The HTTP GET request is basicly a long URL that incorporates all parameters.

Conclusion

Now the most important question of all is – do they both make great PDFs? And the simple answer is – YES THEY DO! The how it works section has a little showcase of PDFs that we make with our service and if you’ve ever converted one on the homepage you know that our output is top notch. After all – we offer a 30 day 100% money back guarantee on all paid subscriptions!

Please check out our HTML to PDF API section or HTML to PDF SDK section if you want to know all about the specifics and how to use these wonderful products. If you feel like signing up – GO AHEAD!

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

A few weeks ago we released the newest version of the HTML to PDF SDK. In this post we’ll go into the new features that have been added in this version.

Our PHP SDK already supported a plethora of functions like page formats, margins, encryption, password protection etc. The newest features that now have been added consist of a set of watermarking options.

With this latest version of the SDK you can now:

  • Add your own image as watermark to the PDF
  • Add your own text in a font and size of your choice to the PDF
  • Define the size and location of the watermark
  • Define the angle of rotation of the watermark
  • Define the opacity of the watermark – in case you choose fully opague, you will notice that the watermark looks like a stamp

Watermarking functions

The new watermarking functions that have been added to our PHP library are listed in the table below.

FunctionDescription
SetWatermarkLocationInput parameters: $x, $y
Indicate where the watermark should start.
Note that the top left of a watermark image will start at this location, whilst this location will indicate the BOTTOM left of a text watermark
SetWatermarkTransformationInput parameters: $angle, $opacity, $scaling_x, $scaling_y
Indicate the rotation in degrees, opacity from 0 to 1 (0 = fully transparant, 1 = fully opague) and scaling (horizontal and vertical) of the watermark
SetWatermarkImageInput parameter: $url
Adds an image as watermark to all the pages of your PDF
SetWatermarkTextInput parameters: $text, $fontname, $color, $fontsize
Adds a text watermark to all the pages of your PDF
You control font name, color and size

Example

The following example code shows how you can watermark your PDFs, by using the newest functions of the HTML to PDF SDK in PHP. If the above list of functions was not enough – this will surely get you going.


$pdf = new Htm2PdfApi ($userid, $apikey); // initialize

$pdf->SetWatermarkLocation(100,100); // put this at position 100,100
$pdf->SetWatermarkTransformation(45,1); // it's at an angle of 45 degrees
// and fully opague (so stamped)
$pdf->SetWatermarkText('SAMPLE','Tahoma','#000000',64); // Print SAMPLE in Tahoma
// use color black, size 64

$pdf->CreateFromURL('http://www.google.com'); // do the conversion
$pdf->Display(); // send it to the user as attachment

Conclusion

This hopefully shows you the power of the new watermarking functions in our HTML to PDF SDK. We feel this makes the SDK even more complete than it already was. If you want learn more about this service, then please view the full documentation we have compiled.

If you’re ready to give it a go – please sign up!