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
David PHAM-VAN
2020-03-13 09:18:59 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
415388078f4e8b5cd71679ccb3815dfadc031bc6
41538807
1 parent
b913ad33
Fix #243 layoutPdf does not return on Flutter Web
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
printing/lib/src/printing_web.dart
printing/lib/src/printing_web.dart
View file @
4153880
...
...
@@ -37,6 +37,8 @@ class PrintingPlugin extends PrintingPlatform {
PrintingPlatform
.
instance
=
PrintingPlugin
();
}
static
const
String
_frameId
=
'__net_nfet_printing__'
;
@override
Future
<
PrintingInfo
>
info
()
async
{
return
const
PrintingInfo
(
...
...
@@ -61,8 +63,11 @@ class PrintingPlugin extends PrintingPlatform {
}
final
bool
isChrome
=
js
.
context
[
'chrome'
]
!=
null
;
final
bool
isSafari
=
js
.
context
[
'safari'
]
!=
null
;
// Maybe Firefox 75 will support iframe printing
// https://bugzilla.mozilla.org/show_bug.cgi?id=911444
if
(!
isChrome
)
{
if
(!
isChrome
&&
!
isSafari
)
{
final
String
pr
=
'data:application/pdf;base64,
${base64.encode(result)}
'
;
final
html
.
Window
win
=
js
.
context
[
'window'
];
win
.
open
(
pr
,
name
);
...
...
@@ -77,33 +82,32 @@ class PrintingPlugin extends PrintingPlatform {
);
final
String
pdfUrl
=
html
.
Url
.
createObjectUrl
(
pdfFile
);
final
html
.
HtmlDocument
doc
=
js
.
context
[
'document'
];
final
html
.
IFrameElement
frame
=
doc
.
createElement
(
'iframe'
);
final
html
.
IFrameElement
frame
=
doc
.
getElementById
(
_frameId
)
??
doc
.
createElement
(
'iframe'
);
frame
.
setAttribute
(
'style'
,
'visibility: hidden; height: 0; width: 0; position: absolute;'
,
// 'height: 400px; width: 600px; position: absolute; z-index: 1000',
);
frame
.
setAttribute
(
'sandbox'
,
'allow-scripts'
);
frame
.
setAttribute
(
'id'
,
_frameId
);
frame
.
setAttribute
(
'src'
,
pdfUrl
);
frame
.
addEventListener
(
'load'
,
(
html
.
Event
event
)
{
html
.
EventListener
load
;
load
=
(
html
.
Event
event
)
{
frame
.
removeEventListener
(
'load'
,
load
);
final
js
.
JsObject
win
=
js
.
JsObject
.
fromBrowserObject
(
frame
)[
'contentWindow'
];
win
.
callMethod
(
'addEventListener'
,
<
dynamic
>[
'afterprint'
,
js
.
allowInterop
<
html
.
EventListener
>((
html
.
Event
event
)
{
frame
.
remove
();
completer
.
complete
(
true
);
}),
]);
frame
.
focus
();
win
.
callMethod
(
'print'
);
});
completer
.
complete
(
true
);
};
doc
.
body
.
append
(
frame
);
frame
.
addEventListener
(
'load'
,
load
);
doc
.
body
.
append
(
frame
);
return
completer
.
future
;
}
...
...
Please
register
or
login
to post a comment