diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index 0a7cd5a..dfd84be 100644 Binary files a/cpdfmanual.pdf and b/cpdfmanual.pdf differ diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 0a07d9b..7802086 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -530,7 +530,7 @@ public static void main(String[] args) \end{jcpdflib} \begin{jscpdflib} -\chapter*{Example Program in Java} +\chapter*{Example Program in JavaScript} This program loads a file \texttt{hello.pdf} from disk and writes out a document with the original included three times. @@ -538,41 +538,26 @@ document with the original included three times. \begin{small} \begin{verbatim} //Merge example -import com.coherentpdf.Jcpdf -public static void main(String[] args) -{ - // Initialise cpdf - Jcpdf jcpdf = new Jcpdf(); - try - { - jcpdf.startup(); - } - catch (Jcpdf.CpdfError e) - { - System.out.println("Error during cpdf startup"); - } - // We will take the input hello.pdf and repeat it three times - try (Jcpdf.Pdf mergepdf = jcpdf.fromFile("hello.pdf", "")) - { - // The array of PDFs to merge - Jcpdf.Pdf[] pdfs = {mergepdf, mergepdf, mergepdf}; - // Merge them - Jcpdf.Pdf merged = jcpdf.mergeSimple(pdfs); - // Write output - jcpdf.toFile(merged, "merged.pdf", false, false); - // Dispose of merged PDF - merged.close(); - } - catch (Jcpdf.CpdfError e) - { - System.out.println("Error during cpdf operation"); - } -} +//Load coherentpdf.js +const coherentpdf = require('./coherentpdf.js'); + +//Load the file hello.pdf from the current directory +var pdf = coherentpdf.fromFile('hello.pdf', ''); + +//Merge three copies of it +var merged = coherentpdf.mergeSimple([pdf, pdf, pdf]); + +//Write to merged.pdf +coherentpdf.toFile(merged, 'merged.pdf', false, false); + +//Clean up the two PDFs +coherentpdf.deletePdf(pdf); +coherentpdf.deletePdf(merged); \end{verbatim} \end{small} -\noindent Note the use of \texttt{try} and \texttt{close()} to ensure the PDFs are thrown away when no longer required. +\noindent To be run in node. A browser example is included in the distribution of coherentpdf.js. \end{jscpdflib} \pagestyle{plain} diff --git a/javascriptsplits/c00.tex b/javascriptsplits/c00.tex index 9f4ee70..42d77b8 100644 --- a/javascriptsplits/c00.tex +++ b/javascriptsplits/c00.tex @@ -4,15 +4,19 @@ Use --- -cpdf.js can be used from both node and the browser. +coherentpdf.js can be used from both node and the browser. -For development server-side with node: `cpdf.js` (minified version -`cpdf.min.js`) Load with `const cpdf = require('cpdf.js')` if installed in npm, -or `const cpdf = require('./cpdf.js')` to load from current directory. +The file `cpdflibtest.js` uses every function in coherentpdf.js. Call `./run` +to run it in node. -For development client-side with the browser : `cpdf.browser.js` (minified -version for deployment : `cpdf.browser.min.js`). Load with `` or similar. +For development server-side with node: `coherentpdf.js` (minified version +`coherentpdf.min.js`). Load with `const coherentpdf = require('coherentpdf')` +if installed in npm, or `const coherentpdf = require('./coherentpdf.js')` to +load from current directory. + +For development client-side with the browser : `coherentpdf.browser.js` +(minified version for deployment : `coherentpdf.browser.min.js`). Load with +`` or similar. Data types @@ -37,6 +41,6 @@ Any function may raise an exception, containing a string describing the problem. Concurrency ----------- -cpdf.js is synchronous and non-re-entrant. In the browser, best used in a worker. +coherentpdf.js is synchronous and non-re-entrant. In the browser, best used in a worker. **/ diff --git a/splitjs b/splitjs index d0670ac..655421f 100755 --- a/splitjs +++ b/splitjs @@ -1,5 +1,5 @@ #!/bin/bash -csplit -k -f javascriptsplits/c ../cpdf.js/cpdfdocs.js '/CHAPTER/' {18} +csplit -k -f javascriptsplits/c ../coherentpdf.js/cpdfdocs.js '/CHAPTER/' {18} mv javascriptsplits/c00 javascriptsplits/c00.tex mv javascriptsplits/c01 javascriptsplits/c01.tex mv javascriptsplits/c02 javascriptsplits/c02.tex