Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qfqPDF
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
typo3
qfqPDF
Commits
5bff81ab
Commit
5bff81ab
authored
1 year ago
by
bbaer
Browse files
Options
Downloads
Patches
Plain Diff
added defaults for screenshot
parent
a2b02a8f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/index.js
+13
-1
13 additions, 1 deletion
src/index.js
src/wrapper/puppeteer.js
+12
-4
12 additions, 4 deletions
src/wrapper/puppeteer.js
src/wrapper/puppeteerOptions.js
+10
-4
10 additions, 4 deletions
src/wrapper/puppeteerOptions.js
with
35 additions
and
9 deletions
src/index.js
+
13
−
1
View file @
5bff81ab
...
...
@@ -20,6 +20,11 @@ const arguments = argv(hideBin(process.argv))
if
(
argv
.
verbose
)
console
.
info
(
`generating pdf from: "
${
argv
.
source
}
" to:
${
argv
.
output
}
`
)
/* program to run */
})
.
option
(
'
screenshot
'
,
{
alias
:
'
s
'
,
type
:
'
boolean
'
,
description
:
'
Take a screenshot instead (default output changes to: output.png)
'
})
.
option
(
'
cookies
'
,
{
alias
:
'
c
'
,
type
:
'
array
'
,
...
...
@@ -45,7 +50,7 @@ const arguments = argv(hideBin(process.argv))
description
:
'
Print in landscape
'
})
.
option
(
'
paper-size
'
,
{
alias
:
"
s
"
,
alias
:
"
p
"
,
description
:
'
Set papersize to: A0 - A6, Letter, Legal, etc.
'
,
default
:
"
A4
"
,
type
:
"
string
"
...
...
@@ -108,6 +113,12 @@ const arguments = argv(hideBin(process.argv))
default
:
'
1280x720
'
,
description
:
'
Viewport of the opened browser window
'
})
.
option
(
'
clip-to-viewport
'
,
{
alias
:
'
C
'
,
type
:
'
boolean
'
,
default
:
'
true
'
,
description
:
'
Screenshot only shows what would be visible by the viewport size
'
})
.
epilog
(
'
qfqPDF 2021, detailed information and sources: https://git.math.uzh.ch/bbaer/qfqpdf
'
)
.
argv
...
...
@@ -115,4 +126,5 @@ const arguments = argv(hideBin(process.argv))
const
options
=
new
PuppeteerOptions
(
arguments
);
const
puppeteerWrap
=
new
PuppeteerWrapper
(
arguments
.
source
,
options
,
cookies
)
puppeteerWrap
.
printPDF
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/wrapper/puppeteer.js
+
12
−
4
View file @
5bff81ab
...
...
@@ -12,9 +12,10 @@ class PuppeteerWrapper {
async
printPDF
()
{
const
browser
=
await
this
.
getBrowserInstance
()
const
page
=
await
browser
.
newPage
()
await
page
.
setViewport
({
width
:
this
.
options
.
viewport
.
width
,
height
:
this
.
options
.
viewport
.
height
,
width
:
parseInt
(
this
.
options
.
viewport
.
width
)
,
height
:
parseInt
(
this
.
options
.
viewport
.
height
)
,
})
if
(
this
.
cookies
.
hasCookies
()
&&
!
this
.
cookies
.
requireReload
())
await
page
.
setCookies
(
this
.
cookies
.
getCookies
())
...
...
@@ -29,14 +30,21 @@ class PuppeteerWrapper {
}
if
(
this
.
cookies
.
options
.
verbose
)
console
.
log
(
"
Cookies in use:
"
,
await
page
.
cookies
())
await
page
.
pdf
(
this
.
options
);
if
(
this
.
options
.
screenshot
)
{
await
page
.
screenshot
(
this
.
options
)
}
else
{
await
page
.
pdf
(
this
.
options
);
}
await
browser
.
close
()
}
async
getBrowserInstance
()
{
const
path
=
Path
.
join
(
process
.
cwd
(),
'
.qfqpdf-chromium
'
)
const
fetcher
=
puppeteer
.
createBrowserFetcher
({
path
:
path
})
const
{
local
,
revision
,
executablePath
}
=
fetcher
.
revisionInfo
(
'
884014
'
)
// Latest supported Revision Number is usually in one of the release notes here: https://github.com/puppeteer/puppeteer/releases
const
{
local
,
revision
,
executablePath
}
=
fetcher
.
revisionInfo
(
'
1181205
'
)
if
(
!
local
)
{
...
...
This diff is collapsed.
Click to expand it.
src/wrapper/puppeteerOptions.js
+
10
−
4
View file @
5bff81ab
...
...
@@ -3,14 +3,20 @@ const { Template } = require('../helper/template')
class
PuppeteerOptions
{
constructor
(
argv
)
{
this
.
path
=
argv
.
output
||
"
output.pdf
"
this
.
type
=
argv
.
type
||
"
pdf
"
this
.
screenshot
=
!!
argv
.
screenshot
let
defaultPath
=
"
output.pdf
"
let
defaultType
=
"
pdf
"
if
(
!!
argv
.
screenshot
)
defaultPath
=
"
output.png
"
if
(
!!
argv
.
screenshot
)
defaultType
=
"
png
"
this
.
path
=
argv
.
output
||
defaultPath
this
.
type
=
argv
.
type
||
defaultType
this
.
format
=
argv
.
pageSize
this
.
scale
=
argv
.
scale
||
1
this
.
pageRange
=
argv
.
pageRange
;
this
.
landscape
=
!!
argv
.
landscape
this
.
printBackground
=
!!
argv
.
printBackground
this
.
displayHeaderFooter
=
!!
argv
.
printHeaderAndFooter
if
(
!!
argv
.
screenshot
)
this
.
captureBeyoundViewport
=
!
argv
.
clipToViewport
this
.
margin
=
{
top
:
argv
.
marginTop
||
"
18mm
"
,
left
:
argv
.
marginLeft
||
"
18mm
"
,
...
...
@@ -18,8 +24,8 @@ class PuppeteerOptions {
bottom
:
argv
.
marginBottom
||
"
18mm
"
}
this
.
viewport
=
{
width
:
argv
.
viewport
.
substring
(
0
,
viewport
.
indexOf
(
'
x
'
)),
height
:
argv
.
viewport
.
substring
(
viewport
.
indexOf
(
'
x
'
)
+
1
)
width
:
argv
.
viewport
.
substring
(
0
,
argv
.
viewport
.
indexOf
(
'
x
'
)),
height
:
argv
.
viewport
.
substring
(
argv
.
viewport
.
indexOf
(
'
x
'
)
+
1
)
}
const
template
=
new
Template
(
argv
)
if
(
template
.
hasHeader
())
...
...
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