검색 및 인덱싱

사례 메인 배너 사용

조직은 종종 하드카피 문서와 스캔한 파일을 디지털화해야 합니다. 이 점 고려하기 시나리오. 법률 회사는 디지털 파일을 만들기 위해 스캔한 수천 건의 법률 계약서를 보유하고 있습니다. 그들은 그러한 법률 계약들 중 어떤 것에 특정한 조항이 있는지 혹은 그들이 수정해야 하는 보완을 가지고 있는지 결정하기를 원합니다. 규정 준수를 위해서는 정확성이 필요합니다. 이 솔루션을 통해 디지털 문서의 인벤토리를 관리하고, 텍스트를 검색 가능하게 만들고, 색인을 만들어 이 정보를 찾을 수 있습니다.

디지털 아카이브를 만들어 편집 또는 다운스트림 작업을 위한 정보를 검색하는 것은 대부분의 조직에서 어려운 일입니다.

학습 내용

이 실습 튜토리얼에서는 Adobe Acrobat Services API의 기능을 사용하여 문서를 보관하고 디지털화할 수 있습니다. Express NodeJS 애플리케이션을 구축한 다음 통합을 통해 이러한 기능을 살펴볼 수 있습니다 Acrobat Services 아카이빙, 디지털화, 문서 변환을 위한 API

팔로우하려면 Node.js Node.js 및 ES6 구문.

관련 API 및 리소스

프로젝트 설정

먼저 응용 프로그램의 폴더 구조를 설정합니다. 소스 코드를 검색할 수 있습니다 여기.

디렉토리 구조

AdobeDocumentServicesAPIs라는 폴더를 만들어 선택한 편집기에서 엽니다. 기본 NodeJS 응용 프로그램 만들기 npm init 이 폴더 구조를 사용하는 명령:

AdobeDocumentServicesAPIs
config
default.json
controllers
createPDFController.js
makeOCRController.js
searchController.js
models
document.js
output
.gitkeep
routes
web.js
services
upload.js
views
index.hbs
ocr.hbs
search.hbs
index.js

MongoDB를 이 응용 프로그램의 데이터베이스로 사용하고 있습니다. 따라서 구성하려면 아래 코드 조각을 이 폴더의 default.json 파일에 붙여넣어 기본 데이터베이스 구성을 config/ 폴더에 배치한 다음 데이터베이스의 URL을 추가하십시오.

### config/default.json and config/dev.json
{ "DBHost": "YOUR_DB_URI" }

패키지 설치

이제 아래 코드 조각에 표시된 대로 npm install 명령을 사용하여 일부 패키지를 설치합니다.

{
    "name": "adobedocumentservicesapis",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "directories": {
    "test": "test"
    },
    "dependencies": {
    "body-parser": "^1.19.0",
    "config": "^3.3.6",
    "express": "^4.17.1",
    "hbs": "^4.1.1",
    "mongoose": "^5.12.1",
    "morgan": "^1.10.0",
    "multer": "^1.4.2",
    "path": "^0.12.7"
    },
    "devDependencies": {},
    "scripts": {
    "start": "set NODE_ENV=dev && node index.js"
    },
    "repository": {
    "type": "git",
    "url": "git+https://github.com/agavitalis/AdobeDocumentServicesAPIs.git"
    },
    "author": "Ogbonna Vitalis",
    "license": "ISC",
    "bugs": {
    "url": "https://github.com/agavitalis/AdobeDocumentServicesAPIs/issues"
    },
    "homepage": "https://github.com/agavitalis/AdobeDocumentServicesAPIs#readme"
}
###bash
npm install express mongoose config body-parser morgan multer hbs path pdf-parse
Ensure that the content of your package.json file is similar to this code snippet:
###package.json
{

이러한 코드 조각은 보기에 대한 핸들 템플릿 엔진을 비롯하여 응용 프로그램 종속성을 설치합니다. scripts 태그에서 응용 프로그램의 런타임 매개 변수를 구성합니다.

통합 Acrobat Services API

Acrobat Services 세 가지 API 포함:

  • Adobe PDF 서비스 API

  • Adobe PDF 임베드 API

  • Adobe 문서 생성 API

이러한 API는 클라우드 기반 웹 서비스 세트를 통해 PDF 콘텐츠의 생성, 조작 및 변환을 자동화합니다.

자격 증명을 얻으려면 레지스터 를 클릭하여 워크플로를 완료합니다. PDF 포함 API는 무료로 사용할 수 있습니다. PDF 서비스 API와 문서 생성 API는 6개월간 무료다. 체험판이 종료되면 다음을 수행할 수 있습니다. 사용한 만큼 지불 문서 트랜잭션당 0.05 USD입니다. 회사가 성장하고 더 많은 계약을 처리하는 동안에만 비용을 지불합니다.

자격 증명 만들기 스크린샷

등록을 완료하면 API 자격 증명이 포함된 코드 샘플이 PC에 다운로드됩니다. 이 코드 샘플을 추출하고 private.key 및 pdftools-api-credentials.json 파일을 응용 프로그램의 루트 디렉터리에 배치합니다.

이제 PDF 서비스 Node.js SDK 를 실행하여 npm install --save @adobe/documentservices-pdftools-node-sdk 명령입니다.

PDF 만들기

Acrobat Services 에서는 Microsoft Office 문서(Word, Excel 및 PowerPoint) 및 기타 문서에서 PDF 만들기를 지원합니다 지원되는 파일 형식 .txt, .rtf, .bmp, .jpg, .gif, .tiff, .png와 같은 형식입니다.

지원되는 파일 형식으로 PDF 문서를 만들려면 이 양식을 사용하여 문서를 업로드하십시오. 에서 양식의 HTML 및 CSS 파일에 액세스할 수 있습니다 GitHub.

웹 양식 스크린샷

이제 controllers/createPDFController.js 파일에 다음 코드 스니펫을 추가합니다. 이 코드는 문서를 검색하고 PDF으로 변환합니다.

원본 파일과 변형된 파일은 응용 프로그램 내의 폴더에 저장됩니다.

const PDFToolsSdk = require('@adobe/documentservices-pdftools-node-sdk');
/*
* GET / route to show the createPDF form.
*/
function createPDF(req, res) {
//catch any response on the url
let response = req.query.response
res.render('index', { response })
}
/*
* POST /createPDF to create a new PDF File.
*/
function createPDFPost(req, res) {
let filePath = req.file.path;
let fileName = req.file.filename;
try {
// Initial setup, create credentials instance.
const credentials = PDFToolsSdk.Credentials
.serviceAccountCredentialsBuilder()
.fromFile("pdftools-api-credentials.json")
.build();
// Create an ExecutionContext using credentials and create a new operation
instance.
const executionContext = PDFToolsSdk.ExecutionContext.create(credentials),
createPdfOperation = PDFToolsSdk.CreatePDF.Operation.createNew();
// Set operation input from a source file.
const input = PDFToolsSdk.FileRef.createFromLocalFile(filePath);
createPdfOperation.setInput(input);
// Execute the operation and Save the result to the specified location.
createPdfOperation.execute(executionContext)
.then((result) => {
result.saveAsFile('output/createPDFFromDOCX.pdf')
//download the file
res.redirect('/?response=PDF Successfully created')
})
.catch(err => {
if (err instanceof PDFToolsSdk.Error.ServiceApiError
|| err instanceof PDFToolsSdk.Error.ServiceUsageError) {
console.log('Exception encountered while executing operation',
err);
} else {
console.log('Exception encountered while executing operation',
err);
}
});
} catch (err) {
console.log('Exception encountered while executing operation', err);
}
}
//export all the functions
module.exports = { createPDF, createPDFPost };

이 코드 조각에는 PDF 서비스 Node.js SDK. 다음 기능을 사용합니다.

  • 문서 업로드 양식을 표시하는 createPDF

  • createPDFPost - 업로드된 문서를 PDF으로 변환합니다.

변환된 PDF 문서는 출력 디렉토리에 저장되고 원본 파일은 업로드 디렉토리에 저장됩니다.

텍스트 인식 사용

OCR(광학 문자 인식)을 통해 이미지 및 스캔한 문서를 검색 가능한 파일로 변환할 수 있습니다. 변환 Acrobat Services API, 이미지, 스캔한 문서를 검색 가능한 PDF으로 변환 OCR 작업을 수행하면 파일을 편집 및 검색할 수 있습니다. 파일의 내용을 데이터 저장소에 저장하여 색인화 및 기타 용도로 사용할 수 있습니다.

파일 관리 및 정보 처리가 필수인 많은 조직에서는 스캔한 문서의 검색 및 색인화가 매우 중요합니다. OCR 기능으로 이러한 문제를 해결할 수 있습니다.

이 기능을 구현하려면 위의 것과 유사한 업로드 양식을 디자인해야 합니다. 이번에는 PDF 문서에서만 OCR 기능을 사용할 수 있으므로 양식을 PDF 파일로 제한합니다.

이 예제의 업로드 양식은 다음과 같습니다.

파일 업로드 양식 스크린샷

이제 업로드된 PDF을 조작하고 일부 OCR 작업을 수행하려면 아래 코드 스니펫을 controllers/makeOCRController.js 파일에 추가하십시오. 이 코드는 업로드된 파일에 OCR 프로세스를 구현한 다음 응용 프로그램의 파일 시스템에 파일을 저장합니다.

const fs = require('fs')
const pdf = require('pdf-parse');
const mongoose = require('mongoose');
const Document = require('../models/document');
const PDFToolsSdk = require('@adobe/documentservices-pdftools-node-sdk');
/*
* GET /makeOCR route to show the makeOCR form.
*/
function makeOCR(req, res) {
//catch any response on the url
let response = req.query.response
res.render('ocr', { response })
}
/*
* POST /makeOCRPost to create a new PDF File.
*/
function makeOCRPost(req, res) {
let filePath = req.file.path;
let fileName = req.file.filename;
try {
// Initial setup, create credentials instance.
const credentials = PDFToolsSdk.Credentials
.serviceAccountCredentialsBuilder()
.fromFile("pdftools-api-credentials.json")
.build();
// Create an ExecutionContext using credentials and create a new operation
instance.
const executionContext = PDFToolsSdk.ExecutionContext.create(credentials),
ocrOperation = PDFToolsSdk.OCR.Operation.createNew();
// Set operation input from a source file.
const input = PDFToolsSdk.FileRef.createFromLocalFile(filePath);
ocrOperation.setInput(input);
// Execute the operation and Save the result to the specified location.
ocrOperation.execute(executionContext)
.then(async (result) => {
let newFileName = `createPDFFromDOCX-${Math.random() * 171}.pdf`;
await result.saveAsFile(`output/${newFileName}`);
let documentContent = fs.readFileSync(
require("path").resolve("./") + `\\output\\${newFileName}`
);
pdf(documentContent)
.then(function (data) {
//Creates a new document
var newDocument = new Document({
documentName: fileName,
documentDescription: description,
documentContent: data.text,
url: require("path").resolve("./") + `\\output\\${newFileName}`
});
//Save it into the DB.
newDocument.save((err, docs) => {
if (err) {
res.send(err);
} else {
//If no errors, send it back to the client
res.redirect(
"/makeOCR?response=OCR Operation Successfully performed on
the PDF File"
);
}
});
})
.catch(function (error) {
// handle exceptions
console.log(error);
});
})
.catch(err => {
if (err instanceof PDFToolsSdk.Error.ServiceApiError
|| err instanceof PDFToolsSdk.Error.ServiceUsageError) {
console.log('Exception encountered while executing operation',
err);
} else {
console.log('Exception encountered while executing operation',
err);
}
});
} catch (err) {
console.log('Exception encountered while executing operation', err);
}
}
//export all the functions
module.exports = { makeOCR, makeOCRPost };

필요한 Acrobat Services 노드 SDK, mongoose, pdf 구문 분석, fs 모듈 및 문서 모델 스키마입니다. 이러한 모듈은 변환된 파일의 내용을 MongoDB 데이터베이스에 저장하는 데 필요합니다.

이제 두 가지 함수를 만듭니다. makeOCR을 사용하여 업로드된 양식을 표시한 다음 업로드된 문서를 처리할 수 있도록 OCR을 만듭니다. 원본 양식을 데이터베이스에 저장한 다음 변환된 양식을 응용 프로그램의 출력 폴더에 저장합니다.

pdftools-api-credentials.json 파일의 Adobe 제공 자격 증명은 파일을 변환하기 전에 각 경우에 로드됩니다.

NOTE
OCR 기능은 PDF 문서만 지원합니다.

또한 아래 코드 조각을 응용 프로그램의 Modes/Document.js 파일에 추가합니다.

코드 조각에서 몽구스 모델을 정의한 다음 데이터베이스에 저장할 문서의 속성을 설명합니다. 또한 documentContent 필드를 색인화하면 텍스트를 쉽고 효율적으로 검색할 수 있습니다.

const mongoose = require("mongoose");
const Schema = mongoose.Schema;
//Document schema definition
var DocumentSchema = new Schema(
{
documentName: { type: String, required: false },
documentDescription: { type: String, required: false },
documentContent: { type: String, required: false },
url: { type: String, required: false },
status: {
type: String,
enum : ["active","inactive"],
default: "active"
}
},
{ timestamps: true }
);
//for text search
DocumentSchema.index({
documentContent: "text",
});
//Exports the DocumentSchema for use elsewhere.
module.exports = mongoose.model("document", DocumentSchema);

텍스트 검색

이제 사용자가 간단한 텍스트 검색을 수행할 수 있도록 간단한 검색 기능을 구현합니다. PDF 파일 다운로드를 활성화하는 다운로드 기능도 추가할 수 있습니다.

이 기능을 사용하려면 검색 결과를 표시하는 간단한 양식과 카드가 필요합니다. 양식 및 카드에 대한 디자인은 GitHub.

아래 스크린샷은 검색 기능과 검색 결과를 보여줍니다. 원하는 검색 결과를 다운로드할 수 있습니다.

검색 기능 스크린샷

검색 함수를 구현하려면 응용 프로그램의 컨트롤러 폴더 내에 searchController.js 파일을 만들고 아래 코드 조각을 붙여넣습니다.

const fs = require('fs')
const mongoose = require('mongoose');
const Document = require('../models/document');
/*
* GET / route to show the search form.
*/
function search(req, res) {
//catch any response on the url
let response = req.query.response
res.render('search', { response })
}
/*
* POST /searchPost to search the contents of your saved file.
*/
function searchPost(req, res) {
let searchString = req.body.searchString;
Document.aggregate([
{ $match: { $text: { $search: searchString } } },
{ $sort: { score: { $meta: "textScore" } } },
])
.then(function (documents) {
res.render('search', { documents })
})
.catch(function (error) {
let response = error
res.render('search', { response })
});
}
//export all the functions
module.exports = { search, searchPost, downloadPDF };

이제 다운로드 기능을 구현하여 사용자의 검색에서 반환된 문서를 다운로드할 수 있습니다.

문서 다운로드

다운로드 기능 구현은 이미 수행한 것과 유사합니다. controllers/earchController.js 파일에서 searchPost 함수 뒤에 다음 코드 조각을 추가합니다.

/*
* POST /downloadPDF To Download PDF Documents.
*/
async function downloadPDF(req, res) {
console.log("here")
let documentId = req.params.documentId
let document = await Document.findOne({_id:documentId});
res.download(download.link);
}

다음 단계

이 실습 튜토리얼에서는 Acrobat Services API를 Node.js 응용 프로그램으로 변환하고 API를 사용하여 파일을 PDF으로 변환하는 문서 변환을 구현했습니다. 사진 및 스캔한 파일을 검색할 수 있도록 하는 OCR 기능을 추가했습니다. 파일을 다운로드할 수 있도록 폴더에 저장했습니다.

다음으로 OCR에 의해 텍스트로 변환된 문서를 검색하는 검색 기능을 추가했습니다. 마지막으로 다운로드 기능을 구현하여 해당 파일을 쉽게 다운로드할 수 있도록 했습니다. 완성된 응용 프로그램을 사용하면 법률 회사에서 특정 텍스트를 손쉽게 찾고 처리할 수 있습니다.

사용 Acrobat Services 문서 변환은 다른 서비스에 비해 견고성과 사용 편의성이 뛰어나기 때문에 권장됩니다. 계정을 신속하게 만들어 Acrobat Services 문서 변환 및 관리를 위한 API

이제 사용법에 대한 이해가 깊어졌습니다 Acrobat Services API를 통해 연습을 통해 스킬을 향상시킬 수 있습니다. 이 튜토리얼에서 사용된 리포지토리를 복제하고 학습한 몇 가지 스킬을 실험해 볼 수 있습니다. 더 나은 방법인 Acrobat Services API

자체 앱에서 문서 공유 및 검토를 활성화할 준비가 되셨습니까? 등록 Adobe Acrobat Services
개발자 계정입니다. 6개월 무료 체험판을 사용하면 사용한 만큼 지불 비즈니스 규모에 맞게 문서 트랜잭션당 $0.05에 이용하세요.

recommendation-more-help
61c3404d-2baf-407c-beb9-87b95f86ccab