Skip to content

Instantly share code, notes, and snippets.

View documentprocessing's full-sized avatar

Document Processing documentprocessing

View GitHub Profile
@documentprocessing
documentprocessing / adding-images-to-pdf-in-javascript-using-pdfkit.js
Last active November 3, 2023 02:20
Create PDF documents, Add Images and Shapes to PDF & Create PDF Forms in JavaScript using pdfkit Library. Check for more details.
// Include pdfkit library and fs module of Node.js
const PDFDocument = require('pdfkit');
const fs = require('fs');
// Create a document
const doc = new PDFDocument();
// Pipe its output
doc.pipe(fs.createWriteStream('pdfkit.pdf'));
@documentprocessing
documentprocessing / create-pdf-and-add-content-to-pdf-in-javascript-using-pdf-lib-library.js
Last active November 8, 2023 12:02
Create PDF & Add Content to PDF, Modify PDF Document and Create PDF Forms in JavaScript using pdf-lib Library. Check https://products.documentprocessing.com/editor/javascript/pdf-lib/ for more details.
// Import required objects and functions from pdf-lib library
import { PDFDocument, StandardFonts, rgb } from 'pdf-lib';
// Import fs module from Node.js standard library
import fs from 'fs/promises';
// Asynchronously create a PDF document
async function createPdf() {
// Create a new PDF document
@documentprocessing
documentprocessing / creating-password-protected-pdf-documents-in-javascript-using-pdfmake-library.js
Last active November 15, 2023 11:53
Create PDF Documents with Tables, Images and Password-Protect your PDFs in JavaScript using pdfmake library. Check https://products.documentprocessing.com/editor/javascript/pdfmake/ for more details.
// Import required modules from pdfmake library
const pdfMake = require('pdfmake/build/pdfmake');
const pdfFonts = require('pdfmake/build/vfs_fonts');
// Import Node.js built-in fs module for file system operations
const fs = require('fs');
// Configure virtual file system of pdfMake
pdfMake.vfs = pdfFonts.pdfMake.vfs;
@documentprocessing
documentprocessing / converting-html-file-to-pdf-document-using-xhtml2pdf-library.py
Last active November 20, 2023 10:02
Convert HTML to PDF documents in Python using xhtml2pdf library. Check https://products.documentprocessing.com/conversion/python/xhtml2pdf/ for more details.
# Import the pisa module from the xhtml2pdf library
from xhtml2pdf import pisa
# Import the BytesIO class from the io module
from io import BytesIO
# Open the HTML file for reading
with open("file.html", "r", encoding="utf-8") as file:
# Read the content of the file and store it as a string
html_content = file.read()
@documentprocessing
documentprocessing / create-a-fallback-mechanism-using-pdfobject-library.html
Last active November 20, 2023 16:16
Embed PDFs in webpages using JavaScript with the PDFObject library. Check https://products.documentprocessing.com/viewer/javascript/pdfobject/ for more details.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Set the character set and viewport -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
@documentprocessing
documentprocessing / read-metadata-of-pdf-using-pypdf-library.py
Last active November 28, 2023 09:14
Read and update metadata of PDFs in Python using pypdf library. Check https://products.documentprocessing.com/metadata/python/pypdf/ for more details.
# Import PdfReader module from the pypdf library
from pypdf import PdfReader
# Create a PdfReader object and load the input PDF file
reader = PdfReader("meta-pdf.pdf")
# Reading metadata
meta = reader.metadata
@documentprocessing
documentprocessing / edit-metadata-of-pdf-using-pdf-lib-library.js
Last active November 28, 2023 09:14
Read and edit metadata of PDF documents in JavaScript using pdf-lib library. Check https://products.documentprocessing.com/metadata/javascript/pdf-lib/ for more details.
// Import necessary modules from 'pdf-lib'
import { PDFDocument } from 'pdf-lib';
// Import 'fs/promises' for file system operations
import fs from 'fs/promises';
// Function to set metadata of a PDF document
async function setMetadata(pdfDoc) {
// Change the Metadata of the PDF Document
@documentprocessing
documentprocessing / add-link-annotation-to-pdf-using-pypdf-library.py
Last active November 28, 2023 09:14
Add and extract annotations from PDF documents using pypdf library. Check https://products.documentprocessing.com/annotation/python/pypdf/ for more details.
@documentprocessing
documentprocessing / add-and-format-tables-in-word-document-using-python-docx-library.py
Created November 24, 2023 15:42
Edit Word Documents (.docx) using python-docx library. Check [URL] for more details.
# Import necessary modules from the python-docx library
from docx import Document
from docx.shared import Pt
from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT
# Create a new Document object
doc = Document()
# Add a title to the document
title = doc.add_heading('Table Handling Example', level=1)
@documentprocessing
documentprocessing / add-a-watermark-using-react-pdf-viewer-library.js
Created December 1, 2023 10:35
Render PDFs in React Web Applications. Check [URL] for more details.
// Import necessary dependencies from React and react-pdf-viewer library
import React from 'react';
import { Viewer, SpecialZoomLevel, Worker } from '@react-pdf-viewer/core';
import '@react-pdf-viewer/core/lib/styles/index.css';
// Functional component for rendering a PDF with a watermark
const WaterMarkExample = ({ fileUrl }) => {
// Custom rendering function for each page
const renderPage = (props) => (