Giter Site home page Giter Site logo

myogpatterns / layered-pdf-merge Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 2.0 846 KB

Merges multiple PDFs into a combined PDF file respecting layers aka Optional Content Group

License: MIT License

Python 100.00%
pdf-tools pdf-layer pdf-merge pdf-ocg pdf pdf-converter pdf-format pymupdf

layered-pdf-merge's Introduction

Layered PDF Merge

Merge and layer PDF files using Optional Content Groups (OCG)

Conventionally, when creating a garment sewing pattern, the designer overlays all available garment sizes onto a large sheet of paper to be printed. The dressmaker or sewist locates the desired garment size and either cuts or traces that particular set of pattern panels from the set of available sizes. For home sewists, 'projector sewing' reduces paper waste and PDF Layers allow hiding unwanted sizes or pattern elements.

This script combines A0 paper-size PDF files into single multi-page PDF, with each exported "layer" added to its own PDF Layer. Using PDF Optional Content Group and a compatible PDF viewing application e.g. Adobe Acrobat Reader, the user may show or hide different content layers.

The PDF layers are named using the filename of the individual exports. Common page numbers are combined onto the same page in the output file.

Example Use Case

Using the Hugo hoodie pattern from freesewing.org

  • hugo-sample-pattern.svg is the design file with common, small, and medium layers
  • small.pdf is a 2 page file exported with the small garment patterns
  • medium.pdf is a 2 page file exported with the medium garment patterns
  • common.pdf is a 2 page file exported with elements common to all garments patterns such as titles and pattern symbols

The above sample files may be found in example/ subfolder. Copy the three test pdf files to patterns/ subfolder to try the script.

Executing the script, the resulting file 'layered-output.pdf' is a 2 page PDF displaying all elements: common, small, and medium. Opening in a PDF viewer such as Adobe Acrobat Reader, navigate to the "layers" toolbar, the user may hide or show either small or medium content. The sewist who only wants to sew the small garment may hide all of the unnecessary information for a medium garment size.

Layered PDF Example

Installation and Use

Requires

Installation

  1. mupdf "brew install mupdf"
  2. pip install wheel setuptools
  3. pip install pymupdf

Usage

  1. From your design application, such as Inkscape, export individual layers into separate A0-sized PDF files
  2. Save all files into patterns/ folder within this script file folder location
  3. Run the script and locate the output file within the script file folder location
  4. Open the output PDF in Adobe Acrobat Reader or other viewer capable of displaying Optional Content Groups (OCG)

Note: As of writing Chrome, Safari, and Preview's PDF viewers do NOT currently support OCGs

A few hardcoded configuration settings can be easily changed in the script.

  • 'path' location of pdf exports
  • 'doc.save' filename for output file
  • 'author' PDF metadata

Known Limitations or Desired Changes

  • The script currently expects A0 sized input files. temp-get-page-bound.py will work to get the page size rather than defaulting to A0 but has not yet been incorporated
  • All input pdfs are selectable layers. In above example, common layer may be shown or hidden. May make sense in future to have a layer such as common to be in the base PDF rather than a layer
  • Only import pdfs of equal page counts and page sizes (e.g. A0) have been tested

layered-pdf-merge's People

Contributors

myogpatterns avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

ebsr12 hroeger

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.