Giter Club home page Giter Club logo

fn-text2pdf's Introduction

Function for converting text to PDF

This Function converts a text file to PDF. It reads a text (.txt) file from a Oracle Cloud Infrastructure Object Storage Bucket, converts it into PDF and stores the converted file in the same bucket (with a .pdf extension)

  • It's written in Go and uses gofpdf for text to PDF conversion
  • Uses the OCI Go SDK to execute Object Storage read and write operations
  • A custom Dockerfile is used to build the function

Pre-requisites

  • Start by cloning this repository
  • Create Oracle Cloud Infrastructure Object Storage bucket
  • Collect the following information for you OCI tenancy (you'll need these in subsequent steps) - Tenancy OCID, User OCID of a user in the tenancy, OCI private key, OCI public key passphrase, OCI region, Object Storage namespace and name of the bucket you just created
  • Copy your OCI private key to folder. If you don't already have one, please follow the documentation

Switch to correct context

  • fn use context <your context name>
  • Check using fn ls apps

Create application

fn create app text2pdf --annotation oracle.com/oci/subnetIds=<SUBNETS> --config TENANT_OCID=<TENANT_OCID> --config USER_OCID=<USER_OCID> --config FINGERPRINT=<FINGERPRINT> --config PASSPHRASE=<PASSPHRASE> --config REGION=<REGION> --config PRIVATE_KEY_NAME=<PRIVATE_KEY_NAME> --config NAMESPACE=<NAMESPACE> --config BUCKET_NAME=<BUCKET_NAME>

e.g.

fn create app text2pdf --annotation oracle.com/oci/subnetIds='["ocid1.subnet.oc1.phx.aaaaaaaaghmsma7mpqhqdhbgnby25u2zo4wqlrrcskvu7jg56dryxt3hgvkz"]' --config TENANT_OCID=ocid1.tenancy.oc1..aaaaaaaaydrjm77otncda2xn7qtv7l3hqnd3zxn2u6siwdhniibwfv4wwhta --config USER_OCID=ocid1.user.oc1..aaaaaaaa4seqx6jeyma46ldy4cbuv35q4l26scz5p4rkz3rauuoioo26qwmq --config FINGERPRINT=41:82:5f:44:ca:a1:2e:58:d2:63:6a:af:52:d5:3d:04 --config PASSPHRASE=1987 --config REGION=us-phoenix-1 --config PRIVATE_KEY_NAME=oci_private_key.pem --config NAMESPACE=oracle-functions --config BUCKET_NAME=test-bucket

Check

fn inspect app text2pdf

Deploy the application

  • cd fn-text2pdf
  • fn -v deploy --app text2pdf --build-arg PRIVATE_KEY_NAME=<private_key_name> e.g. fn -v deploy --app text2pdf --build-arg PRIVATE_KEY_NAME=oci_private_key.pem

Test

A sample text file (lorem.txt) has been provided to test the function

  • Upload file to your object storage bucket,
  • and then test using echo -n 'lorem.txt' | fn invoke text2pdf convert

If successful, you should see the following output - PDF lorem.pdf written to storage bucket - test-bucket. Now, you can download the PDF (lorem.pdf) from your Object Storage bucket

fn-text2pdf's People

Contributors

abhirockzz avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

rcarrascosps

fn-text2pdf's Issues

Error While invoking text2pdf function

I have copied the PRIVATE_KEY to the folder fn-text2pdf, the function got deployed successfully.
But when i tried to invoke the function it is giving me below error-:
savatar-mac:fn-text2pdf savatar$ echo -n 'lorem.txt' | fn invoke text2pdf convert
{"Message":"Unable to read private Key","Error":"open /function/savatar_function_private_key.pem: permission denied"}

Can you please comment on this. Did i miss any steps?

Thanks in Advance.
Screenshot 2020-02-06 at 12 35 19 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.