| 686 | } |
| 687 | |
| 688 | async function detectPdfText(bucketName, fileName, outputPrefix) { |
| 689 | // [START vision_text_detection_pdf_gcs] |
| 690 | |
| 691 | // Imports the Google Cloud client libraries |
| 692 | const vision = require('@google-cloud/vision').v1; |
| 693 | |
| 694 | // Creates a client |
| 695 | const client = new vision.ImageAnnotatorClient(); |
| 696 | |
| 697 | /** |
| 698 | * TODO(developer): Uncomment the following lines before running the sample. |
| 699 | */ |
| 700 | // Bucket where the file resides |
| 701 | // const bucketName = 'my-bucket'; |
| 702 | // Path to PDF file within bucket |
| 703 | // const fileName = 'path/to/document.pdf'; |
| 704 | // The folder to store the results |
| 705 | // const outputPrefix = 'results' |
| 706 | |
| 707 | const gcsSourceUri = `gs://${bucketName}/${fileName}`; |
| 708 | const gcsDestinationUri = `gs://${bucketName}/${outputPrefix}/`; |
| 709 | |
| 710 | const inputConfig = { |
| 711 | // Supported mime_types are: 'application/pdf' and 'image/tiff' |
| 712 | mimeType: 'application/pdf', |
| 713 | gcsSource: { |
| 714 | uri: gcsSourceUri, |
| 715 | }, |
| 716 | }; |
| 717 | const outputConfig = { |
| 718 | gcsDestination: { |
| 719 | uri: gcsDestinationUri, |
| 720 | }, |
| 721 | }; |
| 722 | const features = [{type: 'DOCUMENT_TEXT_DETECTION'}]; |
| 723 | const request = { |
| 724 | requests: [ |
| 725 | { |
| 726 | inputConfig: inputConfig, |
| 727 | features: features, |
| 728 | outputConfig: outputConfig, |
| 729 | }, |
| 730 | ], |
| 731 | }; |
| 732 | |
| 733 | const [operation] = await client.asyncBatchAnnotateFiles(request); |
| 734 | const [filesResponse] = await operation.promise(); |
| 735 | const destinationUri = |
| 736 | filesResponse.responses[0].outputConfig.gcsDestination.uri; |
| 737 | console.log('Json saved to: ' + destinationUri); |
| 738 | // [END vision_text_detection_pdf_gcs] |
| 739 | } |
| 740 | |
| 741 | async function localizeObjects(fileName) { |
| 742 | // [START vision_localize_objects] |