code: def download_as_pdf(self, target_dir=None, pdf_filename=None, paper_size=PaperSize.A4,
                          paper_orientation=PaperOrientation.PORTRAIT, include_appendices=False):
          if not pdf_filename:
              pdf_filename = self.name + '.pdf'
          if not pdf_filename.endswith('.pdf'):
              pdf_filename += '.pdf'
          full_path = os.path.join(target_dir or os.getcwd(), pdf_filename)
          request_params = {
              'papersize': paper_size,
              'orientation': paper_orientation,
              'appendices': include_appendices
          }
          url = self._client._build_url('activity_export', activity_id=self.id)
          response = self._client._request('GET', url, params=request_params)
          if response.status_code != requests.codes.ok:
              raise APIError("Could not download PDF of activity {}".format(self.name))
          if include_appendices:
              data = response.json()
              url = urljoin(self._client.api_root, data['download_url'])
              count = 0
              while count <= ASYNC_TIMEOUT_LIMIT:
                  response = self._client._request('GET', url=url)
                  if response.status_code == requests.codes.ok:
                      with open(full_path, 'wb') as f:
                          for chunk in response.iter_content(1024):
                              f.write(chunk)
                      return
                  count += ASYNC_REFRESH_INTERVAL
                  time.sleep(ASYNC_REFRESH_INTERVAL)
              raise APIError("Could not download PDF of activity {} within the time-out limit of {} "
                             "seconds".format(self.name, ASYNC_TIMEOUT_LIMIT))
          with open(full_path, 'wb') as f:
              for chunk in response.iter_content(1024):
                  f.write(chunk)