next up previous contents index
Next: Creating a Blank Document Up: Basic Usage Previous: Basic Usage   Contents   Index

Reading PDF from Files and Memory

The type of pdf files in memory is Pdf.pdfdoc. To load a PDF from file, assuming it is unencrypted, call FromFile, giving the file name as a string:
\begin{framed}
\noindent\textit{Opening a File}\\
\par
\noindent\begin{tabular}...
...f.pdfdoc = Cpdflib.FromFile(''in.pdf'')!
\end{minipage}\end{tabular}\end{framed}

(If the file is encrypted, but only with a blank user password, it will be decrypted. This is identical to Acrobat's behaviour.)

If the file is encrypted, you must decrypt it to load it fully. This requires either the user or owner password.
\begin{framed}
\noindent\textit{Opening an Encrypted File}\\
\par
\noindent\beg...
...lib.FromFileDecrypt(''in.pdf'', ''pw'')!
\end{minipage}\end{tabular}\end{framed}

If the operations to be performed on the PDF are limited to reading some metadata, or accessing just a portion of the file, it can be more memory- and time-efficient not to load or parse all the PDF upon opening. The only caveat is that the file must be available until the PDF object is destroyed - writing to or removing that file will result in an error.


\begin{framed}
\noindent\textit{Opening an File Lazily}\\
\par
\noindent\begin{...
...fdoc = Cpdflib.FromFileLazy(''in.pdf'')!
\end{minipage}\end{tabular}\end{framed}

No decryption is performed here (even if the password is blank), since it would involve loading the whole file, so you must explicitly check if the file is encrypted using IsEncrypted and decrypt it before performing any operation which requires the file to be in a decrypted state.


next up previous contents index
Next: Creating a Blank Document Up: Basic Usage Previous: Basic Usage   Contents   Index
root 2008-12-01