Skip to content

Commit 53b6015

Browse files
committed
Code and testcase change for inline image
Graceful handling.
1 parent 515ea1a commit 53b6015

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

src/PDPageElement.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ A [`PDPageElement`](@ref) that represents the beginning of an inline image.
164164
"""
165165
mutable struct PDPage_BeginInlineImage <: PDPageObject
166166
elem::PDPageElement
167-
PDPage_BeginInlineImage(ts::AbstractString,ver::Tuple{Int,Int},nop)=
167+
PDPage_BeginInlineImage(ts::AbstractString, ver::Tuple{Int,Int}, nop, ::Type)=
168168
new(PDPageElement(ts,ver,nop))
169169
end
170170

@@ -174,7 +174,7 @@ function collect_object(grp::PDPageObjectGroup, beg::PDPage_BeginInlineImage,
174174

175175
while(!newobj.isRead)
176176
value=parse_value(bis, get_pdfcontentops)
177-
collect_inline_image(img,value,bis)
177+
collect_inline_image(newobj, value, bis)
178178
end
179179
push!(grp.objs, newobj)
180180
return newobj
@@ -230,18 +230,18 @@ end
230230
function collect_inline_image(img::PDPageInlineImage, elem::PDPageElement,
231231
bis::BufferedInputStream)
232232
if (elem.t == Symbol("ID"))
233-
while(!image.isRead && !eof(bis))
233+
while(!img.isRead && !eof(bis))
234234
b1 = peek(bis)
235-
if (b1 == LATIN_E)
235+
if (b1 == LATIN_UPPER_E)
236236
mark(bis)
237237
skip(bis,1);
238238
b2 = peek(bis)
239-
if (b2 == LATIN_I)
239+
if (b2 == LATIN_UPPER_I)
240240
skip(bis,1);b3 = peek(bis)
241-
if (is_crorlf(b3))
241+
if (ispdfspace(b3))
242242
skip(bis,1)
243243
img.isRead=true
244-
unmark(s)
244+
unmark(bis)
245245
break
246246
else
247247
reset(bis)
@@ -522,4 +522,6 @@ function showtext(io::IO, pdo::PDPageElement, state::Vector{Dict}=Vector{Dict}()
522522
return io
523523
end
524524

525+
showtext(io::IO, pdo::PDPageInlineImage, state::Vector{Dict}=Vector{Dict}()) = io
526+
525527
showtext(io::IO, pdo::CosObject, state::Vector{Dict}=Vector{Dict}()) = (show(io, pdo); io)

src/bytes.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export BACKSPACE, NULL,TAB, LINE_FEED,NEWLINE, FORM_FEED, RETURN,
22
SPACE, STRING_DELIM, PLUS_SIGN, DELIMITER, MINUS_SIGN,
33
DECIMAL_POINT, SOLIDUS, DIGIT_ZERO, DIGIT_NINE, SEPARATOR,
4-
LATIN_UPPER_A, LATIN_UPPER_F, BACKSLASH, LATIN_A, LATIN_B,LATIN_E,
5-
LATIN_F, LATIN_L, LATIN_N, LATIN_R, LATIN_S, LATIN_T, LATIN_U,LATIN_Z,
4+
LATIN_UPPER_A, LATIN_UPPER_F, LATIN_UPPER_I, BACKSLASH, LATIN_A, LATIN_B,LATIN_E,
5+
LATIN_F, LATIN_I, LATIN_L, LATIN_N, LATIN_R, LATIN_S, LATIN_T, LATIN_U,LATIN_Z,
66
OBJECT_BEGIN, OBJECT_END, ESCAPES, REVERSE_ESCAPES,
77
ESCAPED_ARRAY, LEFT_PAREN, RIGHT_PAREN, LESS_THAN,
88
GREATER_THAN, LEFT_CB, RIGHT_CB, LEFT_SB, RIGHT_SB,
@@ -53,6 +53,7 @@ const LATIN_UPPER_A = UInt8('A')
5353
const LATIN_UPPER_D = UInt8('D')
5454
const LATIN_UPPER_E = UInt8('E')
5555
const LATIN_UPPER_F = UInt8('F')
56+
const LATIN_UPPER_I = UInt8('I')
5657
const LATIN_UPPER_M = UInt8('M')
5758
const LATIN_UPPER_O = UInt8('O')
5859
const LATIN_UPPER_P = UInt8('P')

test/runtests.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,30 @@ include("debugIO.jl")
218218
end
219219
end
220220

221+
@testset "Inline Image test" begin
222+
@test begin
223+
filename="files/Pratham\ Sanskaran.pdf"
224+
DEBUG && println(filename)
225+
doc = pdDocOpen(filename)
226+
(npage = pdDocGetPageCount(doc)) == 54
227+
try
228+
open("Pratham\ Sanskaran.res", "w") do io
229+
for i=1:npage
230+
page = pdDocGetPage(doc, i)
231+
if pdPageIsEmpty(page) == false
232+
pdPageGetContentObjects(page)
233+
pdPageExtractText(io, page)
234+
end
235+
end
236+
end
237+
@test files_equal("Pratham\ Sanskaran.res", "files/Pratham\ Sanskaran.txt")
238+
finally
239+
pdDocClose(doc)
240+
end
241+
length(utilPrintOpenFiles()) == 0
242+
end
243+
end
244+
221245
@testset "MacRomanEncoding Fonts test" begin
222246
@test begin
223247
filename="files/spec-2.pdf"

0 commit comments

Comments
 (0)