In today’s digital age, preserving web pages is critical for a variety of reasons, including compliance, research, and record-keeping. The ScreenshotLayer and PDFLayer APIs make it easier to build a powerful web page archiver. This post will walk you through the steps required to develop a web page archiver and demonstrate the capabilities of these two APIs in our API marketplace.
ScreenshotLayer is a compact RESTful API for capturing website screenshots, whereas PDFLayer is a simple utility for converting HTML to PDF. You may simply create a web page archiver that collects and preserves web pages in both image and PDF formats by combining these two APIs.
Table of Contents
Before you begin, make sure that you’ve got all of the following:
- Basic knowledge of APIs and RESTful services.
- A ScreenshotLayer account (sign up here).
- A PDFLayer account (sign up here).
Step 1: How to Capture a Screenshot of the Web Page
Set Up ScreenshotLayer API
- After you join up, go to your account’s dashboard and look for your API Access Key (aka. API Key).
- Install your preferred REST client or use cURL to submit a request to the ScreenshotLayer API.
The API will provide the URL of the recorded screenshot if the request is successful.
Step 2: How to Convert Web Page to PDF
Set Up PDFLayer API
- Navigate to your dashboard and retrieve your API Key.
- Using a REST client or cURL, send a request to the PDFLayer API.
The API will then return a URL to the PDF document.
Step 3: Store the Screenshot and PDF
- Download the screenshot and PDF using the URLs provided by the APIs.
- Store them in your preferred cloud storage or on your server for future reference.
How to Integrate ScreenshotLayer and PDFLayer APIs into Delphi Multi-platform Application?
After you have completed the above steps, you might get an idea of how to use it. In this part, we will build a cross-platform native application using the Delphi programming language and its FireMonkey GUI framework. First, get your Delphi Community Edition here from the official page! Then, create a new multi-device application [Delphi]!
Here is the simple design for our demonstration application. You can observe the Structure of the components and create the same look and feel.
As you can see, we have two buttons for each API. With Delphi, you can use various ways to integrate RESTful API services; one is using REST Client Components, and another one is just HTTP components. The difference is that REST Client Components provide more power when manipulating data responses and stuff, while Net HTTP components provide the same functions with a bit more complex process if you are working with big data responses.
How to Download Image and Document Files in Delphi Using HTTP Requests?
In our demo, we utilized Net HTTP Client components to showcase how you can get streams of data, in our case, PDF and PNG files. Here is our main function: DownloadFile. This function has been utilized for both API endpoints because it they have similar and straightforward processes.
procedure TForm1.DownloadFile(FURL, FFileName: String);
HTTPClient := TNetHTTPClient.Create(nil);
HTTPRequest := TNetHTTPRequest.Create(nil);
var MemoryStream := TMemoryStream.Create;
// Set up the client and request
HTTPClient.Accept := 'application/json';
HTTPRequest.Client := HTTPClient;
// Make the request
HTTPRequest.URL := FURL;
Response := HTTPRequest.Get(FURL, MemoryStream);
// Check the response status code
if Response.StatusCode = 200 then
// Save the image to a file
Writeln('Error: ', Response.StatusCode, ' ', Response.StatusText);
And this above function used like this:
+ Edit4.Text + '&url='
+ Edit1.Text + '&viewport=1440x900&fullpage='
+ Edit3.Text, 'screenshot.png');
+ Edit6.Text + '&document_url='
+ Edit5.Text, 'my_file.pdf');
This is the result:
Overall, with both APIs you can achieve similar result. But there is a difference, while the ScreenshotLayer API might work better in some cases, the PDFlayer might be able to read the HTML document better and generate clean PDF format of it. Because, PDFLayer has several features where you can just provide the HTML elements and turn them into PDF format with high accuracy. Get the complete source code from this repository.
Moreover, check out our latest articles and tutorials where you can learn how to automate various business tasks using robust APIs powered by APILayer:
- How to Use the Mediastack and Web page to PDF APIs to Create a News Aggregator
- Automated Social Media Monitoring ChatGPT App With Keyword Extraction, Sentiment Analysis API
- How To Scrape Review From Amazon And Google
With just a few steps, the ScreenshotLayer and PDFLayer APIs enable you to create a comprehensive web page archiver. This tool can be a valuable asset for businesses, researchers, and individuals looking to preserve digital content. The APIs’ ease of use, coupled with their efficient performance, makes the task of web archiving straightforward and hassle-free.