Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extract Text from PDF using REST API in Node.js
global.clientId = "112f0f38-9dae-42d5-b4fc-cc84ae644972";
global.clientSecret = "16ad3fe0bdc39c910f57d2fd48a5d618";
global.myStorage = "";
const configuration = new groupdocs_parser_cloud.Configuration(clientId, clientSecret);
configuration.apiBaseUrl = "https://api.groupdocs.cloud";
// Api initialization
let parseApi = groupdocs_parser_cloud.ParseApi.fromConfig(configuration);
// Input file
let fileInfo = new groupdocs_parser_cloud.FileInfo();
fileInfo.filePath = "sample.pdf";
// Define text options
let options = new groupdocs_parser_cloud.TextOptions();
options.fileInfo = fileInfo;
// Create text request
let request = new groupdocs_parser_cloud.TextRequest(options);
// Extract text
let result = await parseApi.text(request);
console.log(result.text);
// Api initialization
let parseApi = groupdocs_parser_cloud.ParseApi.fromConfig(configuration);
// Input file path
let fileInfo = new groupdocs_parser_cloud.FileInfo();
fileInfo.filePath = "sample.pdf";
// Define text options
let options = new groupdocs_parser_cloud.TextOptions();
options.fileInfo = fileInfo;
options.startPageNumber = 0;
options.countPagesToExtract = 1;
// Create text request
let request = new groupdocs_parser_cloud.TextRequest(options);
// Extract text
let result = await parseApi.text(request);
// Show results
let pages = result.pages;
pages.forEach(page => console.log("Page No: " + page.pageIndex + 1 + " - " + page.text));
// Api initialization
let parseApi = groupdocs_parser_cloud.ParseApi.fromConfig(configuration);
// Input file
let fileInfo = new groupdocs_parser_cloud.FileInfo();
fileInfo.filePath = "PDF_with_Attachments.pdf";
fileInfo.password = "password";
// Input container item
let containerInfo = new groupdocs_parser_cloud.ContainerItemInfo();
containerInfo.relativePath = "template-document.pdf";
// Define text options
let options = new groupdocs_parser_cloud.TextOptions();
options.fileInfo = fileInfo;
options.containerItemInfo = containerInfo;
// Create text request
let request = new groupdocs_parser_cloud.TextRequest(options);
// Extract text
let result = await parseApi.text(request);
console.log(result.text);
// Construct FileApi
let fileApi = groupdocs_parser_cloud.FileApi.fromConfig(configuration);
let filePath = 'C:\\Files\\Parser\\sample.pdf';
fs.readFile(filePath, (err, fileStream) => {
// Create file upload request
let request = new groupdocs_parser_cloud.UploadFileRequest("sample.pdf", fileStream, myStorage);
// Upload file
fileApi.uploadFile(request);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment