###前提・実現したいこと
text2pdfというものを改変し、「1行毎に文字を控えて」そのあと、「1行分の文字を出力させる」という動作を行おうとしたのですが、何度やっても真っ白なページのPDFしか出力されず困っています。これを修正し、「文字が出力されるように」したいのです。
###発生している問題・エラーメッセージ
エラーメッセージはなく、出力が真っ白なページになっている
###ソースコード
void WritePages(){ int atEOF = 0; int atFF; int atBOP; long beginstream; int lineNo, charNo; int ch, column; int padding, i; int y = 0; //strを控える手助け char str[1024]; //各行の文字を控える 文字数はcols分にする 参考サイトhttp://9cguide.appspot.com/14-02.html 12/23アクセス int x = 0; int z = 0; while (!atEOF) { beginstream = StartPage(); column = 1; while (column++ <= columns) { atFF = 0; atBOP = 0; lineNo = 0; while (lineNo++ < lines && !atEOF && !atFF) { str[x] = '('; x = x + 1; //writestr("("); charNo = 0; while (charNo++ < cols && (ch = getc(infile)) != EOF &&!(ch == FF && doFFs) && ch != '\n') { if (ch >= 32 && ch <= 127) { if (ch == '(' || ch == ')' || ch == '\\') str[x] = '\\'; x = x + 1; //配列に控えず書き込む //writestr("\\"); sprintf(buf, "%c", (char)ch); str[x] = buf[0]; x = x + 1; //配列に文字を保存する、writestr(buf);から変更 } else { if (ch == 9) { padding = tab - ((charNo - 1) % tab); for (i = 1; i <= padding; i++) str[x] = ' '; x = x + 1; //配列に控えず書き込む、writestr(" ");から変更 charNo += (padding - 1); } else { if (ch != FF) { /* write \xxx form for dodgy character */ sprintf(buf, "\\%.3o", ch); for (y = 0; y < 4; y++){ str[x] = buf[y]; x = x + 1; //まとめて出力されたものを1文字ずつ配列に書き込む、\\%.3o=「「3ケタ」の8進数」。writestr(buf);から変更。 } } else { /* don't print anything for a FF */ charNo--; } } } } str[x] = ')'; x = x + 1; str[x] = '\''; x = x + 1; str[x] = '\n'; x = x + 1; //writestr(")'\n");から変更、実は3文字分。 str[x] = '\0'; //x=x+1は最後の文字なので行わない。 writestr(str); x = 0; //配列に控えた分をここでPDFファイルとして出力 /* messy stuff to handle formfeeds. Yuk! */ if (ch == EOF) atEOF = 1; //EOF=ファイルを読み切ったら ループ全体の終了! if (ch == FF) atFF = 1; //改ページを見つけたら atFFへ if (lineNo == lines) atBOP = 1; //1ページぎりぎりまで文字を書いたら atBOPへ if (atBOP) { ch = getc(infile); if (ch == FF) ch = getc(infile);//1文字飛ばしの必要があるか(1ページが無駄にならないように) if (ch == EOF) atEOF = 1; else ungetc(ch, infile); //適切な改ページ位置なら何もしない! } else if (atFF) { ch = getc(infile); if (ch == EOF) atEOF = 1; else ungetc(ch, infile); } } if (column <= columns) { sprintf(buf, "1 0 0 1 %d %d Tm\n", (pageWidth / 2) + 25, pageHeight - 40); writestr(buf); } } EndPage(beginstream); } }
###補足情報(言語/FW/ツール等のバージョンなど)
言語は「C言語」です。
開発者コマンド プロンプト for VS2013 を使ってコンパイルしました。
手を加えたのは上記のWritePages内です。
書き込みの動作は次の通りです。
void writestr(char *str) {//配列に対応 /* Everything written to the PDF file goes through this function. */ /* This means we can keep track of the file position without using */ /* ftell on a real (tmp) file. However, PCs write out 2 characters */ /* for \n, so we need this ugly loop to keep fpos correct */ fpos += strlen(str); while (*str) { //文字コードが0になるNULL,終端文字で終了 if (*str == '\n') fpos += LF_EXTRA; putchar(*str++); } }
回答2件
あなたの回答
tips
プレビュー