n8n-nodes-pdf-api-hub 4.0.10 → 4.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ class PdfSplitMerge {
10
10
  icon: { light: 'file:../../icons/pdfhub.light.svg', dark: 'file:../../icons/pdfhub.dark.svg' },
11
11
  group: ['transform'],
12
12
  version: 1,
13
- description: 'PDF and image tools: merge/split/compress, OCR, convert, lock/unlock, watermark, and URL/HTML processing.',
13
+ description: 'PDF and image tools: merge/split/compress, OCR, convert, document similarity, lock/unlock, watermark, and URL/HTML processing.',
14
14
  defaults: {
15
15
  name: 'PDF API Hub',
16
16
  },
@@ -35,6 +35,11 @@ class PdfSplitMerge {
35
35
  value: 'documentConversion',
36
36
  description: 'Convert DOCX/Office documents to PDF and PDF to DOCX',
37
37
  },
38
+ {
39
+ name: 'Document Intelligence',
40
+ value: 'documentIntelligence',
41
+ description: 'Compare similarity between two image/PDF documents',
42
+ },
38
43
  {
39
44
  name: 'Image to PDF',
40
45
  value: 'imageToPdf',
@@ -224,6 +229,26 @@ class PdfSplitMerge {
224
229
  ],
225
230
  default: 'docxToPdf',
226
231
  },
232
+ {
233
+ displayName: 'Operation',
234
+ name: 'operation',
235
+ type: 'options',
236
+ noDataExpression: true,
237
+ displayOptions: {
238
+ show: {
239
+ resource: ['documentIntelligence'],
240
+ },
241
+ },
242
+ options: [
243
+ {
244
+ name: 'Similarity Check',
245
+ value: 'documentSimilarity',
246
+ description: 'Compare similarity between two images/PDF documents',
247
+ action: 'Compare similarity between two documents',
248
+ },
249
+ ],
250
+ default: 'documentSimilarity',
251
+ },
227
252
  {
228
253
  displayName: 'Operation',
229
254
  name: 'operation',
@@ -245,7 +270,7 @@ class PdfSplitMerge {
245
270
  name: 'PDF to WebP',
246
271
  value: 'pdfToWebp',
247
272
  description: 'Convert PDF pages to WebP images',
248
- action: 'Convert pdf to web p images',
273
+ action: 'Convert pdf to webp images',
249
274
  },
250
275
  {
251
276
  name: 'PDF to JPG',
@@ -1902,6 +1927,125 @@ class PdfSplitMerge {
1902
1927
  },
1903
1928
  },
1904
1929
  },
1930
+ {
1931
+ displayName: 'Input Mode',
1932
+ name: 'doc_similarity_input_mode',
1933
+ type: 'options',
1934
+ options: [
1935
+ { name: 'URLs', value: 'url', description: 'Use two public URLs' },
1936
+ { name: 'Base64', value: 'base64', description: 'Use two Base64 strings (or data URLs)' },
1937
+ { name: 'Binary Files', value: 'file', description: 'Use two binary input properties' },
1938
+ ],
1939
+ default: 'url',
1940
+ description: 'How to provide the two documents',
1941
+ displayOptions: {
1942
+ show: {
1943
+ operation: ['documentSimilarity'],
1944
+ },
1945
+ },
1946
+ },
1947
+ {
1948
+ displayName: 'URL 1',
1949
+ name: 'doc_similarity_url1',
1950
+ type: 'string',
1951
+ default: 'https://pdfapihub.com/sample-document-similarity-1.jpg',
1952
+ description: 'URL to first image/PDF',
1953
+ displayOptions: {
1954
+ show: {
1955
+ operation: ['documentSimilarity'],
1956
+ doc_similarity_input_mode: ['url'],
1957
+ },
1958
+ },
1959
+ },
1960
+ {
1961
+ displayName: 'URL 2',
1962
+ name: 'doc_similarity_url2',
1963
+ type: 'string',
1964
+ default: 'https://pdfapihub.com/sample-document-similarity-2.jpg',
1965
+ description: 'URL to second image/PDF',
1966
+ displayOptions: {
1967
+ show: {
1968
+ operation: ['documentSimilarity'],
1969
+ doc_similarity_input_mode: ['url'],
1970
+ },
1971
+ },
1972
+ },
1973
+ {
1974
+ displayName: 'Image/PDF 1 Base64',
1975
+ name: 'doc_similarity_base64_1',
1976
+ type: 'string',
1977
+ typeOptions: {
1978
+ rows: 4,
1979
+ },
1980
+ default: '',
1981
+ description: 'Base64 string (or data URL) for first image/PDF',
1982
+ displayOptions: {
1983
+ show: {
1984
+ operation: ['documentSimilarity'],
1985
+ doc_similarity_input_mode: ['base64'],
1986
+ },
1987
+ },
1988
+ },
1989
+ {
1990
+ displayName: 'Image/PDF 2 Base64',
1991
+ name: 'doc_similarity_base64_2',
1992
+ type: 'string',
1993
+ typeOptions: {
1994
+ rows: 4,
1995
+ },
1996
+ default: '',
1997
+ description: 'Base64 string (or data URL) for second image/PDF',
1998
+ displayOptions: {
1999
+ show: {
2000
+ operation: ['documentSimilarity'],
2001
+ doc_similarity_input_mode: ['base64'],
2002
+ },
2003
+ },
2004
+ },
2005
+ {
2006
+ displayName: 'File 1 Binary Property',
2007
+ name: 'doc_similarity_file1_binary_property',
2008
+ type: 'string',
2009
+ default: 'data1',
2010
+ description: 'Binary property containing first image/PDF file',
2011
+ displayOptions: {
2012
+ show: {
2013
+ operation: ['documentSimilarity'],
2014
+ doc_similarity_input_mode: ['file'],
2015
+ },
2016
+ },
2017
+ },
2018
+ {
2019
+ displayName: 'File 2 Binary Property',
2020
+ name: 'doc_similarity_file2_binary_property',
2021
+ type: 'string',
2022
+ default: 'data2',
2023
+ description: 'Binary property containing second image/PDF file',
2024
+ displayOptions: {
2025
+ show: {
2026
+ operation: ['documentSimilarity'],
2027
+ doc_similarity_input_mode: ['file'],
2028
+ },
2029
+ },
2030
+ },
2031
+ {
2032
+ displayName: 'Method',
2033
+ name: 'doc_similarity_method',
2034
+ type: 'options',
2035
+ options: [
2036
+ { name: 'Auto', value: 'auto' },
2037
+ { name: 'Feature Match', value: 'feature_match' },
2038
+ { name: 'SSIM', value: 'ssim' },
2039
+ { name: 'PHash', value: 'phash' },
2040
+ ],
2041
+ default: 'auto',
2042
+ description: 'Similarity method',
2043
+ displayOptions: {
2044
+ show: {
2045
+ operation: ['documentSimilarity'],
2046
+ },
2047
+ },
2048
+ },
1905
2049
  {
1906
2050
  displayName: 'URL',
1907
2051
  name: 'html_fetch_url',
@@ -2190,6 +2334,36 @@ class PdfSplitMerge {
2190
2334
  },
2191
2335
  };
2192
2336
  };
2337
+ const createTwoFileMultipart = async (itemIndex, file1BinaryProperty, file2BinaryProperty, method) => {
2338
+ const boundary = `----n8nFormBoundary${Math.random().toString(36).slice(2)}`;
2339
+ const parts = [];
2340
+ const appendFile = async (fieldName, binaryPropertyName) => {
2341
+ var _a, _b;
2342
+ const binaryData = this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
2343
+ const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName);
2344
+ const fileName = (_a = binaryData.fileName) !== null && _a !== void 0 ? _a : `${fieldName}.bin`;
2345
+ const contentType = (_b = binaryData.mimeType) !== null && _b !== void 0 ? _b : 'application/octet-stream';
2346
+ parts.push(Buffer.from(`--${boundary}\r\n` +
2347
+ `Content-Disposition: form-data; name="${fieldName}"; filename="${fileName}"\r\n` +
2348
+ `Content-Type: ${contentType}\r\n\r\n`));
2349
+ parts.push(Buffer.from(binaryDataBuffer));
2350
+ parts.push(Buffer.from('\r\n'));
2351
+ };
2352
+ await appendFile('file1', file1BinaryProperty);
2353
+ await appendFile('file2', file2BinaryProperty);
2354
+ if (method) {
2355
+ parts.push(Buffer.from(`--${boundary}\r\n` +
2356
+ 'Content-Disposition: form-data; name="method"\r\n\r\n' +
2357
+ `${method}\r\n`));
2358
+ }
2359
+ parts.push(Buffer.from(`--${boundary}--\r\n`));
2360
+ return {
2361
+ body: Buffer.concat(parts),
2362
+ headers: {
2363
+ 'Content-Type': `multipart/form-data; boundary=${boundary}`,
2364
+ },
2365
+ };
2366
+ };
2193
2367
  for (let i = 0; i < items.length; i++) {
2194
2368
  try {
2195
2369
  const operation = this.getNodeParameter('operation', i);
@@ -2745,6 +2919,62 @@ class PdfSplitMerge {
2745
2919
  returnData.push({ json: responseData, pairedItem: { item: i } });
2746
2920
  }
2747
2921
  }
2922
+ else if (operation === 'documentSimilarity') {
2923
+ const inputMode = this.getNodeParameter('doc_similarity_input_mode', i);
2924
+ const method = this.getNodeParameter('doc_similarity_method', i);
2925
+ if (inputMode === 'file') {
2926
+ const file1BinaryProperty = this.getNodeParameter('doc_similarity_file1_binary_property', i);
2927
+ const file2BinaryProperty = this.getNodeParameter('doc_similarity_file2_binary_property', i);
2928
+ const requestOptions = await createTwoFileMultipart(i, file1BinaryProperty, file2BinaryProperty, method);
2929
+ const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'pdfapihubApi', {
2930
+ method: 'POST',
2931
+ url: 'https://pdfapihub.com/api/v1/document/similarity',
2932
+ ...requestOptions,
2933
+ returnFullResponse: true,
2934
+ });
2935
+ const responseBody = responseData.body;
2936
+ if (typeof responseBody === 'string') {
2937
+ try {
2938
+ returnData.push({ json: JSON.parse(responseBody), pairedItem: { item: i } });
2939
+ }
2940
+ catch {
2941
+ returnData.push({ json: { raw: responseBody }, pairedItem: { item: i } });
2942
+ }
2943
+ }
2944
+ else if (Buffer.isBuffer(responseBody)) {
2945
+ const text = responseBody.toString('utf8');
2946
+ try {
2947
+ returnData.push({ json: JSON.parse(text), pairedItem: { item: i } });
2948
+ }
2949
+ catch {
2950
+ returnData.push({ json: { raw: text }, pairedItem: { item: i } });
2951
+ }
2952
+ }
2953
+ else {
2954
+ returnData.push({ json: (responseBody !== null && responseBody !== void 0 ? responseBody : {}), pairedItem: { item: i } });
2955
+ }
2956
+ }
2957
+ else {
2958
+ const body = {
2959
+ method,
2960
+ };
2961
+ if (inputMode === 'url') {
2962
+ body.url1 = normalizeUrl(this.getNodeParameter('doc_similarity_url1', i));
2963
+ body.url2 = normalizeUrl(this.getNodeParameter('doc_similarity_url2', i));
2964
+ }
2965
+ else {
2966
+ body.image1_base64 = this.getNodeParameter('doc_similarity_base64_1', i);
2967
+ body.image2_base64 = this.getNodeParameter('doc_similarity_base64_2', i);
2968
+ }
2969
+ const responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'pdfapihubApi', {
2970
+ method: 'POST',
2971
+ url: 'https://pdfapihub.com/api/v1/document/similarity',
2972
+ body,
2973
+ json: true,
2974
+ });
2975
+ returnData.push({ json: responseData, pairedItem: { item: i } });
2976
+ }
2977
+ }
2748
2978
  else if (operation === 'pngToPdf' || operation === 'webpToPdf' || operation === 'jpgToPdf') {
2749
2979
  const inputType = this.getNodeParameter('img2pdf_input_type', i);
2750
2980
  const outputFormat = this.getNodeParameter('img2pdf_output', i);