phpnerd
phpnerd

Reputation: 926

Rtf file export leaves a first line blank

I am just trying to make .rtf file with simple following content ("eee"). When i open my file it has added one blank line before my output.

header("Content-Disposition: attachment;filename=test.rtf");
    echo 'eee'; die;

I also tried with

header("Content-type: application/rtf; charset=utf-8");
header("Content-Disposition: attachment;filename=test.rtf");
echo 'eee'; die;

But still getting blank line added before output.

When I am trying to save as .txt file it's not adding any blank line.

header("Content-Disposition: attachment;filename=test.txt");
echo 'eee'; die;

Upvotes: 0

Views: 817

Answers (3)

Steve
Steve

Reputation: 1

I was using

    ob_start('ob_gzhandler');
    ...
    if ($isDownload) {
      header("Content-type: text/rtf;  charset=UTF-8");
      header("Content-Disposition: attachment; filename=myfile.rtf");
      header("Expires: 0");
    }
    echo $rtf;

I fixed it by

    ob_start();
    ...
    if ($isDownload) {
      ob_clean()
      header("Content-type: text/rtf;  charset=UTF-8");
      header("Content-Disposition: attachment; filename=myfile.rtf");
      header("Expires: 0");
    }
    echo $rtf;

Upvotes: 0

MrTux
MrTux

Reputation: 34002

It is important that you don't have empty lines before <?php at the beginning of a line or at some other files which are included (e.g., after ?>).

Upvotes: 2

phpnerd
phpnerd

Reputation: 926

I was using codeigniter framework. On controller I have loaded a model which had blank lines after ?> closing tag. After deleting that It works fine. The reason why simple echo of text added blank space before output is RTF file viewer were expecting appropriate content encoding to be mentioned at the first line itself. So the output should commence like {\rtf1\ansi} this. Make sure no other texts or spaces inserted before.

Upvotes: 0

Related Questions