Example #1
0
        /// <summary>
        /// Prints window's web page as PDF with Chromium's preview printing custom
        /// settings.The landscape will be ignored if @page CSS at-rule is used in the web page.
        /// By default, an empty options will be regarded as: Use page-break-before: always;
        /// CSS style to force to print to a new page.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="options"></param>
        /// <returns>success</returns>
        public Task <bool> PrintToPDFAsync(string path, PrintToPDFOptions options = null)
        {
            var taskCompletionSource = new TaskCompletionSource <bool>();

            BridgeConnector.Socket.On("webContents-printToPDF-completed", (success) =>
            {
                BridgeConnector.Socket.Off("webContents-printToPDF-completed");
                taskCompletionSource.SetResult((bool)success);
            });

            if (options == null)
            {
                BridgeConnector.Socket.Emit("webContents-printToPDF", Id, "", path);
            }
            else
            {
                BridgeConnector.Socket.Emit("webContents-printToPDF", Id, JObject.FromObject(options, _jsonSerializer), path);
            }

            return(taskCompletionSource.Task);
        }
Example #2
0
 /// <summary>
 /// Prints window's web page as PDF with Chromium's preview printing custom
 /// settings.The landscape will be ignored if @page CSS at-rule is used in the web page.
 /// By default, an empty options will be regarded as: Use page-break-before: always;
 /// CSS style to force to print to a new page.
 /// </summary>
 /// <param name="path"></param>
 /// <param name="options"></param>
 /// <returns>success</returns>
 public Task <bool> PrintToPDFAsync(string path, PrintToPDFOptions options = null) => options is null?BridgeConnector.OnResult <bool>("webContents-printToPDF", "webContents-printToPDF-completed" + Id, Id, "", path)
     : BridgeConnector.OnResult <bool>("webContents-printToPDF", "webContents-printToPDF-completed" + Id, Id, options, path);