Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fillpdf
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
fillpdf
Commits
b47b6f49
Commit
b47b6f49
authored
5 years ago
by
Bernd Oliver Suenderhauf
Browse files
Options
Downloads
Patches
Plain Diff
Issue #3056207 by Pancho: Use pdftk dump_data_fields_utf8
parent
2ae24cfd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/FillPdfBackend/PdftkFillPdfBackend.php
+4
-13
4 additions, 13 deletions
src/Plugin/FillPdfBackend/PdftkFillPdfBackend.php
tests/src/Functional/PdfParseTest.php
+3
-5
3 additions, 5 deletions
tests/src/Functional/PdfParseTest.php
with
7 additions
and
18 deletions
src/Plugin/FillPdfBackend/PdftkFillPdfBackend.php
+
4
−
13
View file @
b47b6f49
...
...
@@ -2,7 +2,6 @@
namespace
Drupal\fillpdf\Plugin\FillPdfBackend
;
use
Drupal\Component\Utility\Html
;
use
Drupal\Core\File\FileSystem
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
...
...
@@ -116,15 +115,15 @@ class PdftkFillPdfBackend implements FillPdfBackendPluginInterface, ContainerFac
// Use exec() to call pdftk (because it will be easier to go line-by-line
// parsing the output) and pass $content via stdin. Retrieve the fields with
// dump_data_fields().
// dump_data_fields
_utf8
().
$output
=
[];
exec
(
"
{
$pdftk_path
}
{
$template_path
}
dump_data_fields"
,
$output
,
$status
);
exec
(
"
{
$pdftk_path
}
{
$template_path
}
dump_data_fields
_utf8
"
,
$output
,
$status
);
if
(
count
(
$output
)
===
0
)
{
\Drupal
::
messenger
()
->
addWarning
(
$this
->
t
(
'PDF does not contain fillable fields.'
));
return
[];
}
// Build a simple map of dump_data_fields keys to our own array keys.
// Build a simple map of dump_data_fields
_utf8
keys to our own array keys.
$data_fields_map
=
[
'FieldType'
=>
'type'
,
'FieldName'
=>
'name'
,
...
...
@@ -144,16 +143,8 @@ class PdftkFillPdfBackend implements FillPdfBackendPluginInterface, ContainerFac
// Separate the data key from the data value.
list
(
$key
,
$value
)
=
explode
(
':'
,
$lineitem
);
if
(
in_array
(
$key
,
array_keys
(
$data_fields_map
),
NULL
))
{
// pdftk sometimes inserts random � markers - strip these out.
// NOTE: This may break forms that actually DO contain this pattern,
// but 99%-of-the-time functionality is better than merge failing due
// to improper parsing.
$value
=
str_replace
(
'�'
,
''
,
$value
);
// pdftk encodes diacritics as XML numerical entities, e.g. 'ü' is
// represented by ü We need to reverse this.
$decoded
=
Html
::
decodeEntities
(
$value
);
// Trim spaces.
$fields
[
$fieldindex
][
$data_fields_map
[
$key
]]
=
trim
(
$
decoded
);
$fields
[
$fieldindex
][
$data_fields_map
[
$key
]]
=
trim
(
$
value
);
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Functional/PdfParseTest.php
+
3
−
5
View file @
b47b6f49
...
...
@@ -2,7 +2,6 @@
namespace
Drupal\Tests\fillpdf\Functional
;
use
Drupal\Component\Utility\Html
;
use
Drupal\Core\Url
;
use
Drupal\Tests\BrowserTestBase
;
use
Drupal\Tests\fillpdf\Traits\TestFillPdfTrait
;
...
...
@@ -110,12 +109,11 @@ class PdfParseTest extends BrowserTestBase {
$backend
=
$backend_manager
->
createInstance
(
'pdftk'
,
$config
->
get
());
// Reparse the sample PDF file and check for each text field that the
//
HTML-decode
d value equals the
HTML-decode
d name.
//
fiel
d value equals the
fiel
d name.
foreach
(
$backend
->
parse
(
$fillpdf_form
)
as
$field
)
{
if
(
$field
[
'type'
]
==
'Text'
)
{
$name
=
Html
::
decodeEntities
(
$field
[
'name'
]);
$value
=
isset
(
$field
[
'value'
])
?
Html
::
decodeEntities
(
$field
[
'value'
])
:
NULL
;
static
::
assertEquals
(
$name
,
$value
);
$value
=
isset
(
$field
[
'value'
])
?
$field
[
'value'
]
:
NULL
;
static
::
assertEquals
(
$field
[
'name'
],
$value
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment