---
title: "Comment by Fernando Lam on \"Flutter: Unblocking UI thread with Isolates compute function\" | Hashnode"
description: "I do something different which is exporting the created pdf into png files which takes a heavy toll on the main thread. Do you know if there is a way to compute"
url: "https://hashnode.com/posts/flutter-unblocking-ui-thread-with-isolates-compute-function/5d6e4c943e3f2adc43b93fc1/comment/5f7b1685a4bdec5ef0a751f2"
---

[Discussion](https://hashnode.com/posts/flutter-unblocking-ui-thread-with-isolates-compute-function/5d6e4c943e3f2adc43b93fc1)

Comment [Flutter: Unblocking UI thread with Isolates compute function](https://hashnode.com/posts/flutter-unblocking-ui-thread-with-isolates-compute-function/5d6e4c943e3f2adc43b93fc1)

[Fernando Lam](https://hashnode.com/@fenchai)

[Oct 5, 2020](https://hashnode.com/posts/flutter-unblocking-ui-thread-with-isolates-compute-function/5d6e4c943e3f2adc43b93fc1/comment/5f7b1685a4bdec5ef0a751f2)

I do something different which is exporting the created pdf into png files which takes a heavy toll on the main thread. Do you know if there is a way to compute the below?

```
if (!isPdf) {
  int pageIndex = 1;

  await for (var page in Printing.raster(pdf.save(), dpi: 300)) {
    final image = await page.toPng();

    final String pageQty =
        (pagesToPrint > 1) ? '$pageIndex-$pagesToPrint' : '1-1';

    file = File("${output.path}/$fileName--$pageQty.png");

    await file.writeAsBytes(image);

    imageList.add(file);

    pageIndex++;
  }
} else {
  file = File("${output.path}/$fileName.pdf");

  await file.writeAsBytes(pdf.save());

  imageList.add(file);
}
```

[Dmytro Gladkyi](https://hashnode.com/@dmytrogladkyi)

[Oct 5, 2020](https://hashnode.com/posts/flutter-unblocking-ui-thread-with-isolates-compute-function/5d6e4c943e3f2adc43b93fc1/comment/5f7b1685a4bdec5ef0a751f2#reply-5f7b3ce7e93896601dd28ba7)

I think you need to check what is going on in pdf.toPng method call. Maybe it is possible to move that code inside compute function :)
