Skip to content

Conversation

@eakkew
Copy link
Contributor

@eakkew eakkew commented Apr 11, 2018

  1. beforePrintEvent: callback function printEvent in iframe
  2. beforePrint: callback function will be triggered before iframe created
  3. afterPrint: callback function will be triggered before iframe removed

i use beforePrint to make my canvas an image - in my case, chartjs in bootstrap with div class="col"
then afterPrint for removing images created

function beforePrint() {
  console.log('before')
  for (var id in Chart.instances) {
    $(Chart.instances[id].canvas).addClass('d-none').closest('.chart-container')
      .append($('<img>').attr('src', Chart.instances[id].toBase64Image()).addClass('w-100'));
    $('.chartjs-size-monitor').addClass('d-none');
  }
}

$('#report').printThis({
    pageTitle: $('#report-title').text(),
    beforePrint: beforePrint,
});

 *      beforePrintEvent: callback function printEvent in iframe
 *      beforePrint: null:   callback function will be triggered before iframe created
 *      afterPrint: null:      callback function will be triggered before iframe removed

i use beforePrint and afterPrint to make my canvas an image - in my case, chartjs in bootstrap col
@jasonday
Copy link
Owner

Thanks for the pull request. This is very similar to pull request #54 and you can read my reasoning as to why I did not merge that code.

Here's my reasoning (quoting my comment from #54):

The browser stops all processing/rendering when the print dialog is open and restarts when the print dialog is closed. With this pull request, the complete.printThis is not actually executing because it is tied to an event, it is merely in the "queue" when the browser is again active. Because it is arbitrary without specificity, I have not merged this code. However, I have left the pull request open for informative purposes, because for many users this complete event (arbitrary or not) may be useful.

Because these events are not true events (such as an actual complete event from the browser), I have concerns over actual timing, performance, and behavior of these actions because they depend on the code executing sequentially, which is fairly arbitrary.

@oculus42 - any opinion/feedback here?

@eakkew
Copy link
Contributor Author

eakkew commented Apr 19, 2018

It's quite similar but mine using callback function as a hook instead of event trigger. So, I think this pull will execute the hooks in correct sequence.

ps. i tested in chrome, will test more in firefox and safari

@oculus42
Copy link
Collaborator

It has been my experience that Firefox has not always been reliable about the timing of the print events and the state of the page.

I am working on some tests to execute against a variety of different platforms.

Copy link
Collaborator

@oculus42 oculus42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't competed the test suite, and I would like to get to a point where we can identify the behavior of the supported browsers, but I think this would be a good addition.

@oculus42 oculus42 merged commit 8755b66 into jasonday:master Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants