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
2023-04-29 08:54:12 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9f213a870ef4cad459f26da9b33faeda42875155
9f213a87
1 parent
f4f8a5ed
Use WKWebView on macOS
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
13 deletions
printing/CHANGELOG.md
printing/macos/Classes/PrintJob.swift
printing/macos/Classes/PrintingPlugin.swift
printing/pubspec.yaml
printing/CHANGELOG.md
View file @
9f213a8
# Changelog
## 5.14.0
-
Replace WebView with WKWebView on macOS
## 5.13.4
-
Improve Web Browser detection logic
...
...
printing/macos/Classes/PrintJob.swift
View file @
9f213a8
...
...
@@ -215,6 +215,7 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
// }
}
@available(macOS 11.0, *)
public
func
convertHtml
(
_
data
:
String
,
withPageSize
size
:
CGRect
,
andMargin
margin
:
CGRect
,
andBaseUrl
baseUrl
:
URL
?)
{
let
tempFile
=
NSTemporaryDirectory
()
+
NSUUID
()
.
uuidString
let
directoryURL
=
URL
(
fileURLWithPath
:
tempFile
)
...
...
@@ -230,23 +231,20 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
printInfo
.
rightMargin
=
size
.
width
-
margin
.
maxX
printInfo
.
bottomMargin
=
size
.
height
-
margin
.
maxY
let
webView
=
WebView
()
webView
.
mainFrame
.
loadHTMLString
(
data
,
baseURL
:
baseUrl
)
let
webView
=
WKWebView
(
frame
:
CGRect
.
zero
)
webView
.
loadHTMLString
(
data
,
baseURL
:
baseUrl
)
let
when
=
DispatchTime
.
now
()
+
1
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
when
)
{
let
printOperation
=
NSPrintOperation
(
view
:
webView
.
mainFrame
.
frameView
.
documentView
,
printInfo
:
printInfo
)
printOperation
.
showsPrintPanel
=
false
printOperation
.
showsProgressPanel
=
false
printOperation
.
run
()
do
{
let
data
=
try
Data
(
contentsOf
:
directoryURL
)
webView
.
createPDF
{
result
in
switch
result
{
case
.
success
(
let
data
):
self
.
printing
.
onHtmlRendered
(
printJob
:
self
,
pdfData
:
data
)
let
fileManager
=
FileManager
.
default
try
fileManager
.
removeItem
(
atPath
:
tempFile
)
}
catch
{
self
.
printing
.
onHtmlError
(
printJob
:
self
,
error
:
"Unable to load the pdf file from
\(
tempFile
)
"
)
try
?
fileManager
.
removeItem
(
atPath
:
tempFile
)
case
.
failure
(
let
error
):
self
.
printing
.
onHtmlError
(
printJob
:
self
,
error
:
"Unable to create PDF:
\(
error
.
localizedDescription
)
"
)
}
}
}
}
...
...
@@ -305,10 +303,15 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
}
public
static
func
printingInfo
()
->
NSDictionary
{
var
html
=
false
if
#available(macOS 11.0, *)
{
html
=
true
}
let
data
:
NSDictionary
=
[
"directPrint"
:
true
,
"dynamicLayout"
:
true
,
"canPrint"
:
true
,
"canConvertHtml"
:
html
,
"canShare"
:
true
,
"canRaster"
:
true
,
"canListPrinters"
:
true
,
...
...
printing/macos/Classes/PrintingPlugin.swift
View file @
9f213a8
...
...
@@ -115,6 +115,7 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
let
marginBottom
=
CGFloat
((
args
[
"marginBottom"
]
as?
NSNumber
)?
.
floatValue
??
0.0
)
let
printJob
=
PrintJob
(
printing
:
self
,
index
:
args
[
"job"
]
as!
Int
)
if
#available(macOS 11.0, *)
{
printJob
.
convertHtml
(
args
[
"html"
]
as!
String
,
withPageSize
:
CGRect
(
...
...
@@ -132,6 +133,9 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
andBaseUrl
:
args
[
"baseUrl"
]
as?
String
==
nil
?
nil
:
URL
(
string
:
args
[
"baseUrl"
]
as!
String
)
)
result
(
NSNumber
(
value
:
1
))
}
else
{
result
(
NSNumber
(
value
:
0
))
}
}
else
if
call
.
method
==
"printingInfo"
{
result
(
PrintJob
.
printingInfo
())
}
else
if
call
.
method
==
"rasterPdf"
{
...
...
printing/pubspec.yaml
View file @
9f213a8
...
...
@@ -15,7 +15,7 @@ topics:
-
print
-
printing
-
report
version
:
5.1
3.4
version
:
5.1
4.0
environment
:
sdk
:
"
>=3.3.0
<4.0.0"
...
...
Please
register
or
login
to post a comment