Write several texts on the same page with defined Y position

Đang mở
#1,556 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
tooling

Hướng nghiên cứu

Tái hiện sự cố với PDFKit 0.15.0 bằng ví dụ writeLine được cung cấp, tập trung vào doc.text, heightOfString và việc ngắt trang do cột đầu tiên quá dài gây ra. Theo dõi cách vị trí văn bản thay đổi khi một cột trải dài qua nhiều trang. Được xem là hoàn tất khi tất cả các cột trong một hàng vẫn được căn chỉnh từ cùng một trang bắt đầu mà không bị chồng lấn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
JavaScript
Star
10.7k
Fork
1.2k
Merge trung bình
21 giờ 41 phút
Pull request đã merge (30 ngày)
27

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của foliojs/pdfkit

Tất cả issue của foliojs/pdfkit

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.