Skip to content

Commit 0f61cb7

Browse files
committed
Adding a scratch pad
Functions to quickly analyze and extract from PDF files.
1 parent b778151 commit 0f61cb7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/helpers.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#This has very limited methods created to use the PDFIO functionality for
2+
#testing and quick prototyping. While you can use them to get some of the
3+
#regular testing these are not currently part of the core library.
4+
5+
using PDFIO
6+
using PDFIO.Common
7+
using PDFIO.Cos
8+
using PDFIO.PD
9+
10+
function pdfhlp_extract_doc_content_to_dir(filename,dir=tempdir())
11+
file=rsplit(filename, '/',limit=2)
12+
filenm=file[end]
13+
dirpath=joinpath(dir,filenm)
14+
if isdir(dirpath)
15+
rm(dirpath; force=true, recursive=true)
16+
end
17+
mkdir(dirpath)
18+
doc=pdDocOpen(filename)
19+
try
20+
npage= pdDocGetPageCount(doc)
21+
for i=1:npage
22+
page = pdDocGetPage(doc, i)
23+
if pdPageIsEmpty(page)==false
24+
contents=pdPageGetContents(page)
25+
bufstm = get(contents)
26+
buf = read(bufstm)
27+
close(bufstm)
28+
path=joinpath(dirpath,string(i)*".txt")
29+
write(path, buf)
30+
end
31+
end
32+
finally
33+
pdDocClose(doc)
34+
end
35+
end

0 commit comments

Comments
 (0)