(s i m p l e) ? p d f m a n i p u l a t i o n l a n g u a g e stefano pacifico jayesh kataria dhivya...

13
(S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Post on 21-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

(S i m p l e) ?

P D F

M a n i p u l a t i o n

L a n g u a g eStefano PacificoJayesh Kataria Dhivya Khrishnan Hye Seon Yi

Page 2: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Contents

• Overview & Motivation• Language Features• PDF Functionalities• Architectural Design• Tutorials (including example)• Lesson Learned• Summary

Page 3: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Overview & Motivation• SPML (Simple PDF Manipulation Language) is a

language to create and manipulate PDF files.• PDF is a de-facto standard for electronic

documents because of its open standard format with a free viewer program (Acrobat Reader)

• However, it is difficult and expensive to manipulate PDF files!!!

• There are a few open source libraries available (ex) iText and XPAAJ Why not come up with a language for PDF by using them

• Focus is on manipulation of PDF files since people can easily create PDF files using freewares (ex) PDF ReDirect, cutePDF Writer

Page 4: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Language Features

• Carefully chosen set of keywords • Multiple Types (int, string, pdf, void, array)• Several Operators

– Unary Operators (~,!)– Arithmetic (+ , - , * , /)– Comparison (< , <= , > , >= ,== ,!=)– Logical operators (&&, ||)– PDF operators (+, create, extractpage,

totextfile, highlight, in)

Page 5: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Language Features (con.)

• Various types of statements– Conditional statements (if…else)– Iterative statements (while)– Jump statements (return, continue,

break)– I/O statements (print, totextfile)

• User defined functions• Recursion

Page 6: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

PDF Functionalities

• File generation (create)• File concatenation (+ operator)• Page extraction (extractpage)• Highlight a word(highlight)• All Pdfs in directory (in)• Text file support (totextfile)

Page 7: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Architectural Design

Front End

SPMLLexerSPMLParser

Tree Walker

SPMLWalkerCompilerException

SPMLCodeGenEnvironment Classes

Back End

CodeGenSPMLLibrary

Runtime Library

JRE SystemiTextXPAAJ

Take SPML

source code and

output AST

With the AST passed, perform static semantic checking and generate Java output code

Bridge class

between Java output code and Runtime Libraries

iText (Open Source PDF library in

Java), XPAAJ (XML/PDF Access API

for Java from Adobe)

Page 8: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Tutorials - Example• Program to concatenate two PDF files

start(){

pdf p1;p1 = "a.pdf"; /* open a.pdf */pdf p2;p2 = "b.pdf"; /* open b.pdf */pdf combined;combined = create "c.pdf"; /* create c.pdf */combined = p1 + p2;

}

Page 9: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Tutorials (con.)Function Example

• Variable declaration• Array declaration

• pdf file;• pdf files[10];

• Conditional statement if (a == 1) { print “a is 1”; }

• Iteration statement • while (a < 5) { print “a = “ + a; }

• Jump statement • return a; continue; break;

• I/O statement • print “Hello World!”;

• User defined function • int sum(int a, int b) { return a + b); }

• Recursion • Used to reverse a file( coming soon in the demo)

Page 10: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Tutorials (con.)Function Example

• Length operator • int a;a = length files;

• In operator– all PDFs in a dir– phrase search in PDF

– phrase search in string

• files = pdf in “dir”;• int iArray[10];iArray = “the” in files[0];• a = “1” in “12345”;

• Extract a page • file = extractpage files[0] 1;

• Highlight a phrase • highlight pdfFile “COMS”;

• Save as a text file • totextfile pdfFile “file.txt”;

Page 11: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Applications

• Forming a catalogue of pdfs• Reversing file pages• Deleting a page from pdf• Extracting even and odd pages and

forming a new pdf• Swapping 2 pages of a file• Highlighting word in a pdf• Forming a new pdf of pages containing a specific word.

Page 12: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Lesson Learned

• “Choose types carefully – absence of boolean.”

• “User input could have been added.”• “Deadlines are never too far away!”

Page 13: (S i m p l e) ? P D F M a n i p u l a t i o n L a n g u a g e Stefano Pacifico Jayesh Kataria Dhivya Khrishnan Hye Seon Yi

Summary

• SPML is a simple yet powerful language for manipulating PDF files.

• SPML works!