Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
dart_pdf
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Koji Wakamiya
2023-01-10 23:20:30 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
David PHAM-VAN
2023-01-15 16:41:19 -0400
Commit
982ae5c77e120b0b3192c628addab1b70850be4f
982ae5c7
1 parent
4cda7b84
Add cMapUrl and cMapPacked property
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
19 deletions
printing/CHANGELOG.md
printing/README.md
printing/lib/printing_web.dart
printing/lib/src/pdfjs.dart
printing/CHANGELOG.md
View file @
982ae5c
...
...
@@ -6,6 +6,7 @@
-
Add custom pages builder to PdfPreview widget
[
Milad akarie
]
-
Update Image dependency
-
Fix canChangeOrientation option not appearing bug
[
Bilal Raja
]
-
Add Support cmaps option on printing web
[
Koji Wakamiya
]
## 5.9.3
...
...
printing/README.md
View file @
982ae5c
...
...
@@ -43,14 +43,13 @@ for documentation.
<true/>
```
5.
If you want to manually set the PdfJs library version for the web, a javascript
library and a small script has to be added to your
`web/index.html`
file, just
before
`</head>`
. Otherwise it is loaded automatically:
5.
If you want to manually set the PdfJs library version for the web, a small script
has to be added to your
`web/index.html` file, just before `</head>`
.
Otherwise it is loaded automatically:
```
html
<script
src=
"//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.8.335/pdf.min.js"
></script>
<script
type=
"text/javascript"
>
pdfjsLib
.
GlobalWorkerOptions
.
workerSrc
=
"//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.8.335/pdf.worker.min.js"
;
<script>
var
dartPdfJsVersion
=
"3.2.146"
;
</script>
```
...
...
printing/lib/printing_web.dart
View file @
982ae5c
...
...
@@ -45,8 +45,9 @@ class PrintingPlugin extends PrintingPlatform {
static
const
String
_frameId
=
'__net_nfet_printing__'
;
static
const
_pdfJsVersion
=
'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.13.216'
;
static
const
_pdfJsCdnPath
=
'https://unpkg.com/pdfjs-dist'
;
static
const
_pdfJsVersion
=
'3.2.146'
;
final
_loading
=
Mutex
();
...
...
@@ -54,6 +55,12 @@ class PrintingPlugin extends PrintingPlatform {
'typeof pdfjsLib !== "undefined" && pdfjsLib.GlobalWorkerOptions.workerSrc!="";'
]);
String
get
_selectPdfJsVersion
=>
js
.
context
.
hasProperty
(
'dartPdfJsVersion'
)
?
js
.
context
[
'dartPdfJsVersion'
]
:
_pdfJsVersion
;
String
get
_pdfJsUrlBase
=>
'
$_pdfJsCdnPath
@
$_selectPdfJsVersion
/'
;
Future
<
void
>
_initPlugin
()
async
{
await
_loading
.
acquire
();
...
...
@@ -61,7 +68,7 @@ class PrintingPlugin extends PrintingPlatform {
final
script
=
ScriptElement
()
..
type
=
'text/javascript'
..
async
=
true
..
src
=
'
$_pdfJs
Version
/pdf.min.js'
;
..
src
=
'
$_pdfJs
UrlBase
/build
/pdf.min.js'
;
assert
(
document
.
head
!=
null
);
document
.
head
!.
append
(
script
);
await
script
.
onLoad
.
first
;
...
...
@@ -72,8 +79,9 @@ class PrintingPlugin extends PrintingPlatform {
require
.
callMethod
(
'config'
,
<
dynamic
>[
js
.
JsObject
.
jsify
({
'paths'
:
{
'pdfjs-dist/build/pdf'
:
'
$_pdfJsVersion
/pdf.min'
,
'pdfjs-dist/build/pdf.worker'
:
'
$_pdfJsVersion
/pdf.worker.min'
,
'pdfjs-dist/build/pdf'
:
'
$_pdfJsUrlBase
/build/pdf.min'
,
'pdfjs-dist/build/pdf.worker'
:
'
$_pdfJsUrlBase
/build/pdf.worker.min'
,
}
})
]);
...
...
@@ -82,7 +90,11 @@ class PrintingPlugin extends PrintingPlatform {
js
.
context
.
callMethod
(
'require'
,
<
dynamic
>[
js
.
JsObject
.
jsify
(
[
'pdfjs-dist/build/pdf'
,
'pdfjs-dist/build/pdf.worker'
]),
[
'pdfjs-dist/build/pdf'
,
'pdfjs-dist/build/pdf.worker'
,
],
),
(
dynamic
app
)
{
js
.
context
[
'pdfjsLib'
]
=
app
;
completer
.
complete
();
...
...
@@ -93,7 +105,7 @@ class PrintingPlugin extends PrintingPlatform {
}
js
.
context
[
'pdfjsLib'
][
'GlobalWorkerOptions'
][
'workerSrc'
]
=
'
$_pdfJs
Version
/pdf.worker.min.js'
;
'
$_pdfJs
UrlBase
/build
/pdf.worker.min.js'
;
}
_loading
.
release
();
...
...
@@ -288,10 +300,18 @@ class PrintingPlugin extends PrintingPlatform {
)
async
*
{
await
_initPlugin
();
final
t
=
PdfJs
.
getDocument
(
Settings
()..
data
=
document
);
final
settings
=
Settings
()..
data
=
document
;
if
(!
_hasPdfJsLib
)
{
settings
..
cMapUrl
=
'
$_pdfJsUrlBase
/cmaps/'
..
cMapPacked
=
true
;
}
final
jsDoc
=
PdfJs
.
getDocument
(
settings
);
try
{
final
d
=
await
promiseToFuture
<
PdfJsDoc
>(
t
.
promise
);
final
numPages
=
d
.
numPages
;
final
doc
=
await
promiseToFuture
<
PdfJsDoc
>(
jsDoc
.
promise
);
final
numPages
=
doc
.
numPages
;
final
html
.
CanvasElement
canvas
=
js
.
context
[
'document'
].
createElement
(
'canvas'
);
...
...
@@ -300,8 +320,9 @@ class PrintingPlugin extends PrintingPlatform {
final
_pages
=
pages
??
Iterable
<
int
>.
generate
(
numPages
,
(
index
)
=>
index
);
for
(
final
i
in
_pages
)
{
final
page
=
await
promiseToFuture
<
PdfJsPage
>(
d
.
getPage
(
i
+
1
));
for
(
final
pageIndex
in
_pages
)
{
final
page
=
await
promiseToFuture
<
PdfJsPage
>(
doc
.
getPage
(
pageIndex
+
1
));
try
{
final
viewport
=
page
.
getViewport
(
Settings
()..
scale
=
dpi
/
PdfPageFormat
.
inch
);
...
...
@@ -339,7 +360,7 @@ class PrintingPlugin extends PrintingPlatform {
}
}
}
finally
{
t
.
destroy
();
jsDoc
.
destroy
();
}
}
}
...
...
printing/lib/src/pdfjs.dart
View file @
982ae5c
...
...
@@ -37,6 +37,8 @@ class Settings {
external
set
scale
(
double
value
);
external
set
canvasContext
(
CanvasRenderingContext2D
value
);
external
set
viewport
(
PdfJsViewport
value
);
external
set
cMapUrl
(
String
value
);
external
set
cMapPacked
(
bool
value
);
}
@anonymous
...
...
Please
register
or
login
to post a comment