Write several texts on the same page with defined Y position

オープン
#1,556 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript
領域
tooling

調査の方向性

提供された writeLine の例を使用して PDFKit 0.15.0 で問題を再現し、doc.text、heightOfString、および長い最初の列によって発生する改ページに焦点を当てます。列が複数ページにまたがるときに、テキストの位置がどのように変化するかを追跡します。完了の条件は、行内のすべての列が同じ開始ページから整列したまま、重ならないことです。

索引モデルが issue の本文から書いたものです。

説明

Hello ! This question is quite important i'm stuck for a professionnal work.

How can I write several texts on the same page with a defined Y position ?
My goal is to create a table and then write the content of the columns on the same line.
Like this : column1 | column2 | column3

Easy you would say :

export type PDFTableLine = { text: string; width: number }

    private writeLine = (content: PDFTableLine[]) => 
    {
        let offsetX = this.doc.page.margins.left;
        const startY = this.doc.y;
        let maxLineHeight = 0;
    
        //checking what column will be the tallest
        for (let i = 0; i < content.length; i++) {
            const textHeight = this.doc.heightOfString(content[i].text, {
                width: content[i].width,
            });
            maxLineHeight = Math.max(maxLineHeight, textHeight);
        }
        
        //write all the content of columns
        for (let i = 0; i < content.length; i++) 
        {
            this.doc.text(content[i].text, offsetX, startY, {
                width: content[i].width,
            })
    
            offsetX += content[i].width;//set the offset so the next text will be displayed on the next column
        }
    
        //avoid overlap text with setting the next line below the tallest column
        this.doc.y = startY + maxLineHeight;
    
        this.writeLineSeparator(); //basically create a line with stroke()
    }

It's working perfectly ! Unless... If the first text is quite long and pdfkit creates a page to write the rest of the text, then the others column will be displayed on the next page from the Y position from the top of the page. I want all my columns to starts on the same page even if the first text creates a new page. How can I achieve that ?

(Ps: the issue also exist in pdfkit-table package) that's why i'm creating my own class to build tables

  • pdfkit version: 0.15.0
  • Node version: v20.15.1
  • Operating System: Ubuntu linux
主要言語
JavaScript
スター
10.7k
フォーク
1.2k
平均マージ
21時間 41分
マージ済み PR(30日)
27

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

foliojs/pdfkit のほかの issue

foliojs/pdfkit の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。