Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
Lib-PDF
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
JS Toolbox
Lib-PDF
Commits
1d62a8df
Commit
1d62a8df
authored
3 years ago
by
Zdravko Iliev
Browse files
Options
Downloads
Patches
Plain Diff
multipage support
parent
6a5aa3a4
No related branches found
No related tags found
1 merge request
!1
Draft: Resolve "[Document Sealing] Implement PDF parser"
Pipeline
#49124
passed with stages
Stage:
Stage:
in 44 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dist/pdfParser.js
+16
-14
16 additions, 14 deletions
dist/pdfParser.js
src/pdfParser.ts
+16
-14
16 additions, 14 deletions
src/pdfParser.ts
with
32 additions
and
28 deletions
dist/pdfParser.js
+
16
−
14
View file @
1d62a8df
...
...
@@ -51,20 +51,22 @@ class PDFparser {
const
img
=
yield
pdfDoc
.
embedPng
(
imgBytes
);
const
scaled
=
img
.
scale
(
0.2
);
const
pages
=
pdfDoc
.
getPages
();
const
firstPage
=
pages
[
0
];
firstPage
.
drawImage
(
img
,
{
x
:
firstPage
.
getWidth
()
/
2
-
scaled
.
width
/
2
,
y
:
firstPage
.
getHeight
()
/
2
-
scaled
.
height
/
2
,
width
:
scaled
.
width
,
height
:
scaled
.
height
,
});
const
link
=
this
.
createPageLinkAnnotation
(
firstPage
,
url
,
{
imgXPos
:
firstPage
.
getWidth
()
/
2
-
scaled
.
width
/
2
,
imgYPos
:
firstPage
.
getHeight
()
/
2
-
scaled
.
height
/
2
,
imgWidth
:
scaled
.
width
,
imagHeight
:
scaled
.
height
,
});
firstPage
.
node
.
set
(
pdf_lib_1
.
PDFName
.
of
(
"
Annots
"
),
pdfDoc
.
context
.
obj
([
link
]));
for
(
let
index
=
0
;
index
<
pages
.
length
;
index
++
)
{
const
page
=
pages
[
index
];
page
.
drawImage
(
img
,
{
x
:
page
.
getWidth
()
/
2
-
scaled
.
width
/
2
,
y
:
page
.
getHeight
()
/
2
-
scaled
.
height
/
2
,
width
:
scaled
.
width
,
height
:
scaled
.
height
,
});
const
link
=
this
.
createPageLinkAnnotation
(
page
,
url
,
{
imgXPos
:
page
.
getWidth
()
/
2
-
scaled
.
width
/
2
,
imgYPos
:
page
.
getHeight
()
/
2
-
scaled
.
height
/
2
,
imgWidth
:
scaled
.
width
,
imagHeight
:
scaled
.
height
,
});
page
.
node
.
set
(
pdf_lib_1
.
PDFName
.
of
(
"
Annots
"
),
pdfDoc
.
context
.
obj
([
link
]));
}
const
pdfBytes
=
yield
pdfDoc
.
save
();
return
pdfBytes
;
});
...
...
This diff is collapsed.
Click to expand it.
src/pdfParser.ts
+
16
−
14
View file @
1d62a8df
...
...
@@ -52,23 +52,25 @@ class PDFparser {
const
pages
=
pdfDoc
.
getPages
();
const
firstPage
=
pages
[
0
];
for
(
let
index
=
0
;
index
<
pages
.
length
;
index
++
)
{
const
page
=
pages
[
index
];
firstP
age
.
drawImage
(
img
,
{
x
:
firstP
age
.
getWidth
()
/
2
-
scaled
.
width
/
2
,
y
:
firstP
age
.
getHeight
()
/
2
-
scaled
.
height
/
2
,
width
:
scaled
.
width
,
height
:
scaled
.
height
,
});
p
age
.
drawImage
(
img
,
{
x
:
p
age
.
getWidth
()
/
2
-
scaled
.
width
/
2
,
y
:
p
age
.
getHeight
()
/
2
-
scaled
.
height
/
2
,
width
:
scaled
.
width
,
height
:
scaled
.
height
,
});
const
link
=
this
.
createPageLinkAnnotation
(
firstP
age
,
url
,
{
imgXPos
:
firstP
age
.
getWidth
()
/
2
-
scaled
.
width
/
2
,
imgYPos
:
firstP
age
.
getHeight
()
/
2
-
scaled
.
height
/
2
,
imgWidth
:
scaled
.
width
,
imagHeight
:
scaled
.
height
,
});
const
link
=
this
.
createPageLinkAnnotation
(
p
age
,
url
,
{
imgXPos
:
p
age
.
getWidth
()
/
2
-
scaled
.
width
/
2
,
imgYPos
:
p
age
.
getHeight
()
/
2
-
scaled
.
height
/
2
,
imgWidth
:
scaled
.
width
,
imagHeight
:
scaled
.
height
,
});
firstPage
.
node
.
set
(
PDFName
.
of
(
"
Annots
"
),
pdfDoc
.
context
.
obj
([
link
]));
page
.
node
.
set
(
PDFName
.
of
(
"
Annots
"
),
pdfDoc
.
context
.
obj
([
link
]));
}
const
pdfBytes
=
await
pdfDoc
.
save
();
...
...
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