diff --git a/printing/ios/printing/Sources/printing/PrintJob.swift b/printing/ios/printing/Sources/printing/PrintJob.swift index af87b263..b7c9a224 100644 --- a/printing/ios/printing/Sources/printing/PrintJob.swift +++ b/printing/ios/printing/Sources/printing/PrintJob.swift @@ -84,7 +84,8 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate controller.delegate = self let printInfo = UIPrintInfo.printInfo() - printInfo.jobName = jobName! + let strippedJobName = jobName!.hasSuffix(".pdf") ? String(jobName!.dropLast(4)) : jobName! + printInfo.jobName = strippedJobName printInfo.outputType = .general if orientation != nil { printInfo.orientation = orientation! @@ -185,7 +186,8 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate orientation = UIPrintInfo.Orientation.landscape } - jobName = name + // Strip .pdf extension as UIPrintInteractionController appends it automatically + jobName = name.hasSuffix(".pdf") ? String(name.dropLast(4)) : name printerName = printerID let controller = UIPrintInteractionController.shared diff --git a/printing/ios/printing/Sources/printing/PrintingPlugin.swift b/printing/ios/printing/Sources/printing/PrintingPlugin.swift index 57641ece..1a993cbf 100644 --- a/printing/ios/printing/Sources/printing/PrintingPlugin.swift +++ b/printing/ios/printing/Sources/printing/PrintingPlugin.swift @@ -185,7 +185,9 @@ public class PrintingPlugin: NSObject, FlutterPlugin { "job": printJob.index, ] as [String: Any] - channel.invokeMethod("onLayout", arguments: arg) + DispatchQueue.main.async { + self.channel.invokeMethod("onLayout", arguments: arg) + } } /// send completion status to flutter @@ -195,8 +197,10 @@ public class PrintingPlugin: NSObject, FlutterPlugin { "error": error as Any, "job": printJob.index, ] - channel.invokeMethod("onCompleted", arguments: data) jobs.removeValue(forKey: UInt32(printJob.index)) + DispatchQueue.main.async { + self.channel.invokeMethod("onCompleted", arguments: data) + } } /// send html to pdf data result to flutter @@ -205,7 +209,9 @@ public class PrintingPlugin: NSObject, FlutterPlugin { "doc": FlutterStandardTypedData(bytes: pdfData), "job": printJob.index, ] - channel.invokeMethod("onHtmlRendered", arguments: data) + DispatchQueue.main.async { + self.channel.invokeMethod("onHtmlRendered", arguments: data) + } } /// send html to pdf conversion error to flutter @@ -214,7 +220,9 @@ public class PrintingPlugin: NSObject, FlutterPlugin { "error": error, "job": printJob.index, ] - channel.invokeMethod("onHtmlError", arguments: data) + DispatchQueue.main.async { + self.channel.invokeMethod("onHtmlError", arguments: data) + } } /// send pdf to raster data result to flutter @@ -225,7 +233,9 @@ public class PrintingPlugin: NSObject, FlutterPlugin { "height": height, "job": printJob.index, ] - channel.invokeMethod("onPageRasterized", arguments: data) + DispatchQueue.main.async { + self.channel.invokeMethod("onPageRasterized", arguments: data) + } } public func onPageRasterEnd(printJob: PrintJob, error: String?) { @@ -233,6 +243,8 @@ public class PrintingPlugin: NSObject, FlutterPlugin { "job": printJob.index, "error": error as Any, ] - channel.invokeMethod("onPageRasterEnd", arguments: data) + DispatchQueue.main.async { + self.channel.invokeMethod("onPageRasterEnd", arguments: data) + } } } diff --git a/printing/lib/printing_web.dart b/printing/lib/printing_web.dart index 124f1505..045af18e 100644 --- a/printing/lib/printing_web.dart +++ b/printing/lib/printing_web.dart @@ -99,10 +99,10 @@ class PrintingPlugin extends PrintingPlatform { } else { final pdfJsVersion = web.window.hasProperty(_dartPdfJsVersion.toJS).toDart - ? web.window - .getProperty(_dartPdfJsVersion.toJS)! - .toDart - : _pdfJsVersion; + ? web.window + .getProperty(_dartPdfJsVersion.toJS)! + .toDart + : _pdfJsVersion; _pdfJsUrlBase = '$_pdfJsCdnPath@$pdfJsVersion/build/'; } @@ -159,6 +159,7 @@ class PrintingPlugin extends PrintingPlatform { bool usePrinterSettings, OutputType outputType, bool forceCustomPrintPaper, + bool windowsModernDialog, ) async { late Uint8List result; try { @@ -406,7 +407,7 @@ class PrintingPlugin extends PrintingPlatform { class _WebPdfRaster extends PdfRaster { _WebPdfRaster(int width, int height, this.png) - : super(width, height, Uint8List(0)); + : super(width, height, Uint8List(0)); final Uint8List png; diff --git a/printing/lib/src/interface.dart b/printing/lib/src/interface.dart index 4336eda1..ea524022 100644 --- a/printing/lib/src/interface.dart +++ b/printing/lib/src/interface.dart @@ -69,6 +69,7 @@ abstract class PrintingPlatform extends PlatformInterface { bool usePrinterSettings, OutputType outputType, bool forceCustomPrintPaper, + bool windowsModernDialog, ); /// Enumerate the available printers on the system. diff --git a/printing/lib/src/method_channel.dart b/printing/lib/src/method_channel.dart index 9882d683..2f0b5b81 100644 --- a/printing/lib/src/method_channel.dart +++ b/printing/lib/src/method_channel.dart @@ -180,6 +180,7 @@ class MethodChannelPrinting extends PrintingPlatform { bool usePrinterSettings, OutputType outputType, bool forceCustomPrintPaper, + bool windowsModernDialog, ) async { final job = _printJobs.add( onCompleted: Completer(), @@ -200,6 +201,7 @@ class MethodChannelPrinting extends PrintingPlatform { 'usePrinterSettings': usePrinterSettings, 'outputType': outputType.index, 'forceCustomPrintPaper': forceCustomPrintPaper, + if (windowsModernDialog) 'windowsModernDialog': windowsModernDialog, }; await _channel.invokeMethod('printPdf', params); diff --git a/printing/lib/src/print_job.dart b/printing/lib/src/print_job.dart index 7209d547..26ee2e56 100644 --- a/printing/lib/src/print_job.dart +++ b/printing/lib/src/print_job.dart @@ -15,6 +15,7 @@ */ import 'dart:async'; +import 'dart:math'; import 'dart:typed_data'; import 'callback.dart'; @@ -57,7 +58,7 @@ class PrintJobs { /// Create a list print jobs PrintJobs(); - static var _currentIndex = 0; + static int _currentIndex = Random().nextInt(0x7FFFFFFF); final _printJobs = {}; diff --git a/printing/lib/src/printing.dart b/printing/lib/src/printing.dart index caa6ae75..ac0f387a 100644 --- a/printing/lib/src/printing.dart +++ b/printing/lib/src/printing.dart @@ -57,6 +57,7 @@ mixin Printing { bool usePrinterSettings = false, OutputType outputType = OutputType.generic, bool forceCustomPrintPaper = false, + bool windowsModernDialog = false, }) { return PrintingPlatform.instance.layoutPdf( null, @@ -67,6 +68,7 @@ mixin Printing { usePrinterSettings, outputType, forceCustomPrintPaper, + windowsModernDialog, ); } @@ -164,6 +166,7 @@ mixin Printing { bool usePrinterSettings = false, OutputType outputType = OutputType.generic, bool forceCustomPrintPaper = false, + bool windowsModernDialog = false, }) { return PrintingPlatform.instance.layoutPdf( printer, @@ -174,6 +177,7 @@ mixin Printing { usePrinterSettings, outputType, forceCustomPrintPaper, + windowsModernDialog, ); } diff --git a/printing/macos/printing/Sources/printing/PrintJob.swift b/printing/macos/printing/Sources/printing/PrintJob.swift index ebca1799..8a9f41c5 100644 --- a/printing/macos/printing/Sources/printing/PrintJob.swift +++ b/printing/macos/printing/Sources/printing/PrintJob.swift @@ -29,9 +29,11 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { private var printOperation: NSPrintOperation? private var pdfDocument: CGPDFDocument? private var page: CGPDFPage? - private let semaphore = DispatchSemaphore(value: 0) + private var isWaitingForDocument = false + private var documentReceived = false private var dynamic = false private var _window: NSWindow? + private var lastLayoutParams: (width: CGFloat, height: CGFloat, marginLeft: CGFloat, marginTop: CGFloat, marginRight: CGFloat, marginBottom: CGFloat)? public init(printing: PrintingPlugin, index: Int) { self.printing = printing @@ -44,6 +46,13 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { fatalError("init(coder:) has not been implemented") } + private func layoutParamsChanged(_ new: (width: CGFloat, height: CGFloat, marginLeft: CGFloat, marginTop: CGFloat, marginRight: CGFloat, marginBottom: CGFloat)) -> Bool { + guard let last = lastLayoutParams else { return true } + return last.width != new.width || last.height != new.height || + last.marginLeft != new.marginLeft || last.marginTop != new.marginTop || + last.marginRight != new.marginRight || last.marginBottom != new.marginBottom + } + // Return the number of pages available for printing override public func knowsPageRange(_ range: NSRangePointer) -> Bool { let size = printOperation!.showsPrintPanel ? printOperation!.printPanel.printInfo.paperSize : printOperation!.printInfo.paperSize @@ -52,8 +61,7 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { setBoundsSize(size) if dynamic { - printing.onLayout( - printJob: self, + let currentParams = ( width: printOperation!.printInfo.paperSize.width, height: printOperation!.printInfo.paperSize.height, marginLeft: printOperation!.printInfo.leftMargin, @@ -61,9 +69,30 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { marginRight: printOperation!.printInfo.rightMargin, marginBottom: printOperation!.printInfo.bottomMargin ) - - // Block the main thread, waiting for a document - semaphore.wait() + + if layoutParamsChanged(currentParams) { + lastLayoutParams = currentParams + + printing.onLayout( + printJob: self, + width: currentParams.width, + height: currentParams.height, + marginLeft: currentParams.marginLeft, + marginTop: currentParams.marginTop, + marginRight: currentParams.marginRight, + marginBottom: currentParams.marginBottom + ) + + // Wait for document using RunLoop to keep main thread responsive + isWaitingForDocument = true + documentReceived = false + let runLoop = RunLoop.current + let timeout = Date(timeIntervalSinceNow: 30.0) + while !documentReceived && Date() < timeout { + runLoop.run(mode: .default, before: Date(timeIntervalSinceNow: 0.1)) + } + isWaitingForDocument = false + } } if pdfDocument != nil { @@ -95,8 +124,8 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { pdfDocument = CGPDFDocument(dataProvider!) if dynamic { - // Unblock the main thread - semaphore.signal() + // Signal that document is ready + documentReceived = true return } @@ -136,6 +165,7 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { public func printPdf(name: String, withPageSize size: CGSize, andMargin _: CGRect, withPrinter printer: String?, dynamically dyn: Bool, andWindow window: NSWindow) { dynamic = dyn _window = window + lastLayoutParams = nil let sharedInfo = NSPrintInfo.shared let sharedDict = sharedInfo.dictionary() let printInfoDict = NSMutableDictionary(dictionary: sharedDict) @@ -184,8 +214,9 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate { func cancelJob(_ error: String?) { pdfDocument = nil + lastLayoutParams = nil if dynamic { - semaphore.signal() + documentReceived = true } else { printing.onCompleted(printJob: self, completed: false, error: error as NSString?) } diff --git a/printing/macos/printing/Sources/printing/PrintingPlugin.swift b/printing/macos/printing/Sources/printing/PrintingPlugin.swift index 0d9cfed2..6d384b22 100644 --- a/printing/macos/printing/Sources/printing/PrintingPlugin.swift +++ b/printing/macos/printing/Sources/printing/PrintingPlugin.swift @@ -37,7 +37,9 @@ public func net_nfet_printing_set_error(job: UInt32, message: UnsafePointer, size: UInt64) { - instance!.jobs[job]?.setDocument(Data(bytes: doc, count: Int(size))) + jobsLock.lock() + let printJob = sharedJobs[job] + jobsLock.unlock() + printJob?.setDocument(Data(bytes: doc, count: Int(size))) } @objc public static func setError(job: UInt32, message: UnsafePointer) { - instance!.jobs[job]?.cancelJob(String(cString: message)) + jobsLock.lock() + let printJob = sharedJobs[job] + jobsLock.unlock() + printJob?.cancelJob(String(cString: message)) } /// Entry point @@ -78,7 +86,10 @@ public class PrintingPlugin: NSObject, FlutterPlugin { let marginBottom = CGFloat((args["marginBottom"] as! NSNumber).floatValue) let printJob = PrintJob(printing: self, index: args["job"] as! Int) let dynamic = args["dynamic"] as! Bool - jobs[args["job"] as! UInt32] = printJob + + PrintingPlugin.jobsLock.lock() + PrintingPlugin.sharedJobs[args["job"] as! UInt32] = printJob + PrintingPlugin.jobsLock.unlock() guard let window = registrar.view?.window else { result(NSNumber(value: 0)) @@ -191,7 +202,10 @@ public class PrintingPlugin: NSObject, FlutterPlugin { "job": printJob.index, ] channel.invokeMethod("onCompleted", arguments: data) - jobs.removeValue(forKey: UInt32(printJob.index)) + + PrintingPlugin.jobsLock.lock() + PrintingPlugin.sharedJobs.removeValue(forKey: UInt32(printJob.index)) + PrintingPlugin.jobsLock.unlock() } /// send html to pdf data result to flutter diff --git a/printing/pubspec.yaml b/printing/pubspec.yaml index bc3c19a4..af32d7d9 100644 --- a/printing/pubspec.yaml +++ b/printing/pubspec.yaml @@ -30,7 +30,7 @@ dependencies: http: ">=0.13.0 <2.0.0" image: ">=4.1.0 <=5.0.0" meta: ">=1.3.0 <2.0.0" - pdf: ^3.10.0 + pdf: ^3.12.0 pdf_widget_wrapper: '>=1.0.4 <2.0.0' plugin_platform_interface: ^2.1.0 web: ^1.0.0 @@ -45,7 +45,7 @@ dependency_overrides: pdf: path: ../pdf pdf_widget_wrapper: - path: ../widget_wrapper + path: ../widget_wrapper flutter: plugin: diff --git a/printing/test/printing_test.dart b/printing/test/printing_test.dart index d18333c1..bf84dc41 100644 --- a/printing/test/printing_test.dart +++ b/printing/test/printing_test.dart @@ -99,7 +99,9 @@ class MockPrinting extends Mock bool usePrinterSettings, OutputType outputType, bool forceCustomPrintPaper, - ) async => true; + bool windowsModernDialog, + ) async => + true; @override Future sharePdf( @@ -109,7 +111,8 @@ class MockPrinting extends Mock String? subject, String? body, List? emails, - ) async => true; + ) async => + true; @override Future pickPrinter(Rect bounds) async => null; diff --git a/printing/windows/print_job.cpp b/printing/windows/print_job.cpp index 457a3328..c96838c6 100644 --- a/printing/windows/print_job.cpp +++ b/printing/windows/print_job.cpp @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,7 +15,6 @@ */ #include "print_job.h" - #include "printing.h" #include @@ -58,7 +57,7 @@ std::string toUtf8(TCHAR* tstr) { std::wstring fromUtf8(std::string str) { auto len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), - static_cast(str.length()), nullptr, 0); + static_cast(str.length()), nullptr, 0); if (len <= 0) { return L""; } @@ -78,7 +77,9 @@ bool PrintJob::printPdf(const std::string& name, std::string printer, double width, double height, - bool usePrinterSettings) { + bool usePrinterSettings, + bool windowsModernDialog) { + documentName = name; std::size_t dmSize = sizeof(DEVMODE); @@ -86,7 +87,7 @@ bool PrintJob::printPdf(const std::string& name, if (!printer.empty()) { dmExtra = DeviceCapabilities(fromUtf8(printer).c_str(), NULL, DC_EXTRA, - NULL, NULL); + NULL, NULL); } auto dm = static_cast(GlobalAlloc(0, dmSize + dmExtra)); @@ -112,39 +113,71 @@ bool PrintJob::printPdf(const std::string& name, } if (printer.empty()) { - PRINTDLG pd; - - // Initialize PRINTDLG - ZeroMemory(&pd, sizeof(pd)); - pd.lStructSize = sizeof(pd); - - // Initialize PRINTDLG - pd.hwndOwner = nullptr; - pd.hDevMode = dm; - pd.hDevNames = nullptr; // Don't forget to free or store hDevNames. - pd.hDC = nullptr; - pd.Flags = PD_USEDEVMODECOPIES | PD_RETURNDC | PD_PRINTSETUP | - PD_NOSELECTION | PD_NOPAGENUMS; - pd.nCopies = 1; - pd.nFromPage = 0xFFFF; - pd.nToPage = 0xFFFF; - pd.nMinPage = 1; - pd.nMaxPage = 0xFFFF; - - auto r = PrintDlg(&pd); - - if (r != 1) { - printing->onCompleted(this, false, ""); - DeleteDC(hDC); - GlobalFree(hDevNames); - ClosePrinter(hDevMode); - return true; - } - - hDC = pd.hDC; - hDevMode = pd.hDevMode; - hDevNames = pd.hDevNames; + if (windowsModernDialog) { + // --- MODERN OPTION (PrintDlgEx) --- + PRINTDLGEX pdx = {0}; + pdx.lStructSize = sizeof(PRINTDLGEX); + pdx.hwndOwner = GetActiveWindow(); + pdx.hDevMode = dm; + dm = nullptr; // dialog takes ownership; may replace with new alloc + pdx.hDevNames = nullptr; + pdx.hDC = nullptr; + + // Flags: Use PD_RETURNDC to get the context we need for PDFium + pdx.Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE | PD_NOPAGENUMS | PD_NOSELECTION; + + pdx.nStartPage = START_PAGE_GENERAL; + pdx.nMaxPageRanges = 1; + PRINTPAGERANGE ranges[1] = {{1, 1}}; // Required structure for PDX + pdx.lpPageRanges = ranges; + + HRESULT hr = PrintDlgEx(&pdx); + + // Check if the user actually clicked "Print" + if (hr == S_OK && pdx.dwResultAction == PD_RESULT_PRINT) { + this->hDC = pdx.hDC; + this->hDevMode = pdx.hDevMode; + this->hDevNames = pdx.hDevNames; + //success = true; + } else { + // User cancelled or error occurred — notify Dart so its future completes. + if (pdx.hDC) DeleteDC(pdx.hDC); + if (pdx.hDevMode) GlobalFree(pdx.hDevMode); + if (pdx.hDevNames) GlobalFree(pdx.hDevNames); + printing->onCompleted(this, false, ""); + return false; + } + } else { + // --- CLASSIC DEFAULT --- + PRINTDLG pd; + ZeroMemory(&pd, sizeof(pd)); + pd.lStructSize = sizeof(pd); + pd.hwndOwner = nullptr; + pd.hDevMode = dm; + pd.hDevNames = nullptr; + pd.hDC = nullptr; + pd.Flags = PD_USEDEVMODECOPIES | PD_RETURNDC | PD_PRINTSETUP | + PD_NOSELECTION | PD_NOPAGENUMS; + pd.nCopies = 1; + pd.nFromPage = 0xFFFF; + pd.nToPage = 0xFFFF; + pd.nMinPage = 1; + pd.nMaxPage = 0xFFFF; + + auto r = PrintDlg(&pd); + + if (r != 1) { + printing->onCompleted(this, false, ""); + if (pd.hDC) DeleteDC(pd.hDC); + if (pd.hDevNames) GlobalFree(pd.hDevNames); + if (pd.hDevMode) GlobalFree(pd.hDevMode); + return true; + } + hDC = pd.hDC; + hDevMode = pd.hDevMode; + hDevNames = pd.hDevNames; + } } else { hDC = CreateDC(TEXT("WINSPOOL"), fromUtf8(printer).c_str(), nullptr, dm); if (!hDC) { @@ -171,7 +204,7 @@ bool PrintJob::printPdf(const std::string& name, auto marginBottom = pageHeight - printableHeight - marginTop; printing->onLayout(this, pageWidth, pageHeight, marginLeft, marginTop, - marginRight, marginBottom); + marginRight, marginBottom); return true; } @@ -198,7 +231,7 @@ std::vector PrintJob::listPrinters() { } auto result = EnumPrinters(flags, nullptr, 2, (LPBYTE)buffer, needed, &needed, - &returned); + &returned); if (result == 0) { free(buffer); @@ -235,16 +268,8 @@ void PrintJob::writeJob(std::vector data) { auto r = StartDoc(hDC, &docInfo); - FPDF_LIBRARY_CONFIG config; - config.version = 2; - config.m_pUserFontPaths = nullptr; - config.m_pIsolate = nullptr; - config.m_v8EmbedderSlot = 0; - FPDF_InitLibraryWithConfig(&config); - auto doc = FPDF_LoadMemDocument64(data.data(), data.size(), nullptr); if (!doc) { - FPDF_DestroyLibrary(); return; } @@ -274,13 +299,12 @@ void PrintJob::writeJob(std::vector data) { } FPDF_CloseDocument(doc); - FPDF_DestroyLibrary(); EndDoc(hDC); DeleteDC(hDC); GlobalFree(hDevNames); - ClosePrinter(hDevMode); + GlobalFree(hDevMode); printing->onCompleted(this, true, ""); } @@ -321,18 +345,10 @@ bool PrintJob::sharePdf(std::vector data, const std::string& name) { void PrintJob::pickPrinter(void* result) {} void PrintJob::rasterPdf(std::vector data, - std::vector pages, - double scale) { - FPDF_LIBRARY_CONFIG config; - config.version = 2; - config.m_pUserFontPaths = nullptr; - config.m_pIsolate = nullptr; - config.m_v8EmbedderSlot = 0; - FPDF_InitLibraryWithConfig(&config); - + std::vector pages, + double scale) { auto doc = FPDF_LoadMemDocument64(data.data(), data.size(), nullptr); if (!doc) { - FPDF_DestroyLibrary(); printing->onPageRasterEnd(this, "Cannot raster a malformed PDF file"); return; } @@ -383,7 +399,7 @@ void PrintJob::rasterPdf(std::vector data, } printing->onPageRasterized(std::vector{p, p + l}, bWidth, bHeight, - this); + this); FPDFBitmap_Destroy(bitmap); FPDF_ClosePage(page); @@ -391,16 +407,14 @@ void PrintJob::rasterPdf(std::vector data, FPDF_CloseDocument(doc); - FPDF_DestroyLibrary(); - printing->onPageRasterEnd(this, ""); } std::map PrintJob::printingInfo() { return std::map{ {"directPrint", true}, {"dynamicLayout", true}, {"canPrint", true}, - {"canListPrinters", true}, {"canShare", true}, {"canRaster", true}, + {"canListPrinters", true}, {"canShare", true}, {"canRaster", true}, }; } -} // namespace nfet +} // namespace nfet \ No newline at end of file diff --git a/printing/windows/print_job.h b/printing/windows/print_job.h index b2e421b6..99f33b35 100644 --- a/printing/windows/print_job.h +++ b/printing/windows/print_job.h @@ -75,7 +75,8 @@ class PrintJob { std::string printer, double width, double height, - bool usePrinterSettings); + bool usePrinterSettings, + bool windowsModernDialog); void writeJob(std::vector data); diff --git a/printing/windows/printing.cpp b/printing/windows/printing.cpp index 2a7a86b0..28c5853c 100644 --- a/printing/windows/printing.cpp +++ b/printing/windows/printing.cpp @@ -17,14 +17,24 @@ #include "printing.h" #include "print_job.h" +#include namespace nfet { extern std::unique_ptr> channel; -Printing::Printing() {} +Printing::Printing() { + FPDF_LIBRARY_CONFIG config; + config.version = 2; + config.m_pUserFontPaths = nullptr; + config.m_pIsolate = nullptr; + config.m_v8EmbedderSlot = 0; + FPDF_InitLibraryWithConfig(&config); +} -Printing::~Printing() {} +Printing::~Printing() { + FPDF_DestroyLibrary(); +} void Printing::onPageRasterized(std::vector data, int width, diff --git a/printing/windows/printing_plugin.cpp b/printing/windows/printing_plugin.cpp index f44cc832..3333b43e 100644 --- a/printing/windows/printing_plugin.cpp +++ b/printing/windows/printing_plugin.cpp @@ -81,11 +81,16 @@ class PrintingPlugin : public flutter::Plugin { auto usePrinterSettings = std::get( arguments->find(flutter::EncodableValue("usePrinterSettings")) ->second); + bool windowsModernDialog = false; + auto it = arguments->find(flutter::EncodableValue("windowsModernDialog")); + if (it != arguments->end() && !it->second.IsNull()) { + windowsModernDialog = std::get(it->second); + } auto vJob = arguments->find(flutter::EncodableValue("job")); auto jobNum = vJob != arguments->end() ? std::get(vJob->second) : -1; auto job = new PrintJob{&printing, jobNum}; auto res = - job->printPdf(name, printer, width, height, usePrinterSettings); + job->printPdf(name, printer, width, height, usePrinterSettings, windowsModernDialog); if (!res) { delete job; } diff --git a/widget_wrapper/pubspec.yaml b/widget_wrapper/pubspec.yaml index c2c638f3..5fe4271e 100644 --- a/widget_wrapper/pubspec.yaml +++ b/widget_wrapper/pubspec.yaml @@ -13,7 +13,7 @@ environment: dependencies: flutter: sdk: flutter - pdf: ^3.10.0 + pdf: ^3.12.0 dependency_overrides: pdf: