https://github.com/Florents-Tselai/pgpdf Skip to content Navigation Menu Toggle navigation Sign in * Product + GitHub Copilot Write better code with AI + Security Find and fix vulnerabilities + Actions Automate any workflow + Codespaces Instant dev environments + Issues Plan and track work + Code Review Manage code changes + Discussions Collaborate outside of code + Code Search Find more, search less Explore + All features + Documentation + GitHub Skills + Blog * Solutions By company size + Enterprises + Small and medium teams + Startups By use case + DevSecOps + DevOps + CI/CD + View all use cases By industry + Healthcare + Financial services + Manufacturing + Government + View all industries View all solutions * Resources Topics + AI + DevOps + Security + Software Development + View all Explore + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Enterprise + Enterprise platform AI-powered developer platform Available add-ons + Advanced Security Enterprise-grade security features + GitHub Copilot Enterprise-grade AI features + Premium Support Enterprise-grade 24/7 support * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up Reseting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} Florents-Tselai / pgpdf Public * Notifications You must be signed in to change notification settings * Fork 0 * Star 132 pdf type for Postgres tselai.com/pgpdf-pdf-type-postgres License GPL-2.0 license 132 stars 0 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings * Code * Issues 0 * Pull requests 1 * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Projects * Security * Insights Florents-Tselai/pgpdf main BranchesTags [ ] Go to file Code Folders and files Name Name Last commit Last commit message date Latest commit History 23 Commits .github/workflows .github/ workflows sql sql test test .gitignore .gitignore LICENSE LICENSE Makefile Makefile README.md README.md pgpdf.c pgpdf.c pgpdf.control pgpdf.control View all files Repository files navigation * README * GPL-2.0 license pgPDF: pdf type for Postgres build This extension for PostgreSQL provides a pdf data type and assorted functions. The actual PDF parsing is done by poppler. SELECT '/tmp/pgintro.pdf'::pdf; pdf ---------------------------------------------------------------------------------- PostgreSQL Introduction + Digoal.Zhou + 7/20/2011Catalog + PostgreSQL Origin Also check blog: * Full Text Search on PDFs With Postgres * pgpdf: pdf type for Postgres Usage Creating a pdf type, by casting either text path or bytea blob. SELECT '/path/to.pdf'::pdf; SELECT pg_read_binary_file('/path/to.pdf')::bytea::pdf; Below are some examples wget https://wiki.postgresql.org/images/e/ea/PostgreSQL_Introduction.pdf -O /tmp/pgintro.pdf Full-Text Search (FTS) You can also perform full-text search (FTS), since you can work on a pdf file like normal text. SELECT '/tmp/pgintro.pdf'::pdf::text @@ to_tsquery('postgres'); ?column? ---------- t (1 row) SELECT '/tmp/pgintro.pdf'::pdf::text @@ to_tsquery('oracle'); ?column? ---------- f (1 row) bytea If you don't have the PDF file in your filesystem but have already stored its content in a bytea column, you can cast a bytea to pdf, like so: SELECT pg_read_binary_file('/tmp/pgintro.pdf')::pdf Content SELECT '/tmp/pgintro.pdf'::pdf; pdf ---------------------------------------------------------------------------------- PostgreSQL Introduction + Digoal.Zhou + 7/20/2011Catalog + PostgreSQL Origin SELECT pdf_title('/tmp/pgintro.pdf'); pdf_title ------------------------- PostgreSQL Introduction (1 row) Getting a subset of pages SELECT pdf_num_pages('/tmp/pgintro.pdf'); pdf_num_pages --------------- 24 (1 row) SELECT pdf_page('/tmp/pgintro.pdf', 1); pdf_page ------------------------------ Catalog + PostgreSQL Origin + Layout + Features + Enterprise Class Attribute+ Case (1 row) SELECT pdf_subject('/tmp/pgintro.pdf'); pdf_subject ------------- (1 row) Metadata The following functions are available: * pdf_title(pdf) - text * pdf_author(pdf) - text * pdf_num_pages(pdf) - integer Total number of pages in the document * pdf_page(pdf, integer) - text Get the i-th page as text * pdf_creator(pdf) - text * pdf_keywords(pdf) - text * pdf_metadata(pdf) - text * pdf_version(pdf) - text * pdf_subject(pdf) - text * pdf_creation(pdf) - timestamp * pdf_modification(pdf) - timestamp SELECT pdf_author('/tmp/pgintro.pdf'); pdf_author ------------ Zhou Zheng Zhong (1 row) SELECT pdf_creation('/tmp/pgintro.pdf'); pdf_creation -------------------------- Wed Jul 20 11:13:37 2011 (1 row) SELECT pdf_modification('/tmp/pgintro.pdf'); pdf_modification -------------------------- Wed Jul 20 11:13:37 2011 (1 row) SELECT pdf_creator('/tmp/pgintro.pdf'); pdf_creator ------------------------------------ Microsoft(r) Office PowerPoint(r) 2007 (1 row) SELECT pdf_metadata('/tmp/pgintro.pdf'); pdf_metadata -------------- (1 row) SELECT pdf_version('/tmp/pgintro.pdf'); pdf_version ------------- PDF-1.5 (1 row) Installation sudo apt install -y libpoppler-glib-dev pkg-config cd /tmp git clone https://github.com/Florents-Tselai/pgpdf.git cd pgpdf make make install CREATE EXTENSION pgpdf; Warning Reading arbitrary binary data (PDF) into your database can pose security risks. Only use this for files you trust. About pdf type for Postgres tselai.com/pgpdf-pdf-type-postgres Topics pdf postgresql documents Resources Readme License GPL-2.0 license Activity Stars 132 stars Watchers 2 watching Forks 0 forks Report repository Releases No releases published Packages 0 No packages published Languages * C 91.4% * Makefile 8.6% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.