Skip to content

Instantly share code, notes, and snippets.

@dohyunkim
Last active July 30, 2026 04:13
Show Gist options
  • Select an option

  • Save dohyunkim/93e4feae0501c07c7bb2a3c529f1dd26 to your computer and use it in GitHub Desktop.

Select an option

Save dohyunkim/93e4feae0501c07c7bb2a3c529f1dd26 to your computer and use it in GitHub Desktop.
get content from tagged pdf
local doit = true
for line in io.lines(arg[1]) do
if doit and line:find"<?MarkedContent " then
local content = line:match">(.-)$"
if content and content ~= "" then
io.write(content)
end
elseif doit and line:find"</?P[%s>]" then
io.write"\n"
elseif line:find"<Lbl " then
doit = false
elseif line:find"</Lbl>" then
doit = true
elseif doit and line:find"<FENote " then
io.write"\\footnote{"
elseif doit and line:find"</FENote>" then
io.write"}"
end
end
for line in io.lines(arg[1]) do
if line:find"<?MarkedContent%s" then
local content = line:match">(.-)$"
if content and content ~= "" then
io.write(content)
end
elseif line:find"</?P[%s>]"
or line:find"</?Title[%s>]"
or line:find"</?H%d[%s>]"
or line:find"<FENote[%s]" then
io.write"\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment