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
2021-11-21 08:50:05 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a0925437b5b2f334c8d886471831dab81d031e38
a0925437
1 parent
22432da4
Fix macOS printing
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
11 deletions
printing/CHANGELOG.md
printing/macos/Classes/PrintJob.swift
printing/macos/Classes/PrintingPlugin.swift
printing/CHANGELOG.md
View file @
a092543
...
...
@@ -4,6 +4,7 @@
-
Fix Windows string encoding
-
Fix Windows print margins
-
Fix macOS printing
## 5.6.2
...
...
printing/macos/Classes/PrintJob.swift
View file @
a092543
...
...
@@ -31,6 +31,7 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
private
var
page
:
CGPDFPage
?
private
let
semaphore
=
DispatchSemaphore
(
value
:
0
)
private
var
dynamic
=
false
private
var
_window
:
NSWindow
?
public
init
(
printing
:
PrintingPlugin
,
index
:
Int
)
{
self
.
printing
=
printing
...
...
@@ -100,8 +101,7 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
}
DispatchQueue
.
main
.
async
{
let
window
=
NSApplication
.
shared
.
mainWindow
!
self
.
printOperation
!.
runModal
(
for
:
window
,
delegate
:
self
,
didRun
:
#selector(
self.printOperationDidRun(printOperation:success:contextInfo:)
)
,
contextInfo
:
nil
)
self
.
printOperation
!.
runModal
(
for
:
self
.
_window
!
,
delegate
:
self
,
didRun
:
#selector(
self.printOperationDidRun(printOperation:success:contextInfo:)
)
,
contextInfo
:
nil
)
}
}
...
...
@@ -130,8 +130,9 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
return
printers
}
public
func
printPdf
(
name
:
String
,
withPageSize
size
:
CGSize
,
andMargin
_
:
CGRect
,
withPrinter
printer
:
String
?,
dynamically
dyn
:
Bool
)
{
public
func
printPdf
(
name
:
String
,
withPageSize
size
:
CGSize
,
andMargin
_
:
CGRect
,
withPrinter
printer
:
String
?,
dynamically
dyn
:
Bool
,
andWindow
window
:
NSWindow
)
{
dynamic
=
dyn
_window
=
window
let
sharedInfo
=
NSPrintInfo
.
shared
let
sharedDict
=
sharedInfo
.
dictionary
()
let
printInfoDict
=
NSMutableDictionary
(
dictionary
:
sharedDict
)
...
...
@@ -153,9 +154,8 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
}
if
dynamic
{
let
window
=
NSApplication
.
shared
.
mainWindow
!
printOperation
!.
printPanel
.
options
=
[
.
showsPreview
,
.
showsPaperSize
,
.
showsOrientation
]
printOperation
!.
runModal
(
for
:
window
,
delegate
:
self
,
didRun
:
#selector(
printOperationDidRun(printOperation:success:contextInfo:)
)
,
contextInfo
:
nil
)
printOperation
!.
runModal
(
for
:
_window
!
,
delegate
:
self
,
didRun
:
#selector(
printOperationDidRun(printOperation:success:contextInfo:)
)
,
contextInfo
:
nil
)
return
}
...
...
@@ -179,7 +179,7 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
}
}
public
static
func
sharePdf
(
data
:
Data
,
withSourceRect
rect
:
CGRect
,
andName
name
:
String
)
{
public
static
func
sharePdf
(
data
:
Data
,
withSourceRect
rect
:
CGRect
,
andName
name
:
String
,
andWindow
view
:
NSView
)
{
let
tempFile
=
NSTemporaryDirectory
()
+
name
let
file
=
NSURL
(
fileURLWithPath
:
tempFile
)
...
...
@@ -190,7 +190,6 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
return
}
let
view
=
NSApplication
.
shared
.
mainWindow
!.
contentView
!
let
sharingServicePicker
=
NSSharingServicePicker
(
items
:
[
file
])
sharingServicePicker
.
show
(
relativeTo
:
rect
,
of
:
view
,
preferredEdge
:
NSRectEdge
.
maxY
)
...
...
printing/macos/Classes/PrintingPlugin.swift
View file @
a092543
...
...
@@ -22,9 +22,11 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
private
static
var
instance
:
PrintingPlugin
?
private
var
channel
:
FlutterMethodChannel
public
var
jobs
=
[
UInt32
:
PrintJob
]()
private
var
registrar
:
FlutterPluginRegistrar
init
(
_
channel
:
FlutterMethodChannel
)
{
init
(
_
channel
:
FlutterMethodChannel
,
_
registrar
:
FlutterPluginRegistrar
)
{
self
.
channel
=
channel
self
.
registrar
=
registrar
super
.
init
()
PrintingPlugin
.
instance
=
self
}
...
...
@@ -42,7 +44,7 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
/// Entry point
public
static
func
register
(
with
registrar
:
FlutterPluginRegistrar
)
{
let
channel
=
FlutterMethodChannel
(
name
:
"net.nfet.printing"
,
binaryMessenger
:
registrar
.
messenger
)
let
instance
=
PrintingPlugin
(
channel
)
let
instance
=
PrintingPlugin
(
channel
,
registrar
)
registrar
.
addMethodCallDelegate
(
instance
,
channel
:
channel
)
}
...
...
@@ -61,6 +63,13 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
let
printJob
=
PrintJob
(
printing
:
self
,
index
:
args
[
"job"
]
as!
Int
)
let
dynamic
=
args
[
"dynamic"
]
as!
Bool
jobs
[
args
[
"job"
]
as!
UInt32
]
=
printJob
guard
let
window
=
registrar
.
view
?
.
window
else
{
result
(
NSNumber
(
value
:
0
))
onCompleted
(
printJob
:
printJob
,
completed
:
false
,
error
:
"Unable to find the main window"
)
return
}
printJob
.
printPdf
(
name
:
name
,
withPageSize
:
CGSize
(
width
:
width
,
...
...
@@ -72,7 +81,7 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
width
:
width
-
marginRight
-
marginLeft
,
height
:
height
-
marginBottom
-
marginTop
),
withPrinter
:
printer
,
dynamically
:
dynamic
)
dynamically
:
dynamic
,
andWindow
:
window
)
result
(
NSNumber
(
value
:
1
))
}
else
if
call
.
method
==
"listPrinters"
{
let
printJob
=
PrintJob
(
printing
:
self
,
index
:
-
1
)
...
...
@@ -80,6 +89,12 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
result
(
r
)
}
else
if
call
.
method
==
"sharePdf"
{
let
object
=
args
[
"doc"
]
as!
FlutterStandardTypedData
guard
let
view
=
registrar
.
view
else
{
result
(
NSNumber
(
value
:
0
))
return
}
PrintJob
.
sharePdf
(
data
:
object
.
data
,
withSourceRect
:
CGRect
(
...
...
@@ -88,7 +103,7 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
width
:
CGFloat
((
args
[
"w"
]
as?
NSNumber
)?
.
floatValue
??
0.0
),
height
:
CGFloat
((
args
[
"h"
]
as?
NSNumber
)?
.
floatValue
??
0.0
)
),
andName
:
args
[
"name"
]
as!
String
andName
:
args
[
"name"
]
as!
String
,
andWindow
:
view
)
result
(
NSNumber
(
value
:
1
))
}
else
if
call
.
method
==
"convertHtml"
{
...
...
Please
register
or
login
to post a comment