font can't display Complete when text length greater than pdf edit box length

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

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
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
backend

Hướng nghiên cứu

The report uses AcroFields#setFieldProperty and AcroFields#setField to fill and flatten a PDF form field. Start by reading those APIs and the tests covering AcroFields text fitting or field appearance generation; the issue does not name a test or source file. Done means long Chinese text is fully visible, with a reduced font size if needed.

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

Mô tả

bug

when text length is longger, same text can't display ,
such as my text is "这是一段非常长的文字这是一段非常长的文字这是一段非常长的文字",
but pdf may be only show "这是一段非常长的文字这是一段" ,
I don't find api or code how to slove it , in AcroFields#setFieldProperty , can't find "fontsize" .
may I have some other way to slove it ? I hope can display complete ,although the font size may be small.

there is my demo code:

`

// load pdf file
ClassPathResource resource = new ClassPathResource("my.pdf");
InputStream inputStream = resource.getInputStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);

    com.lowagie.text.pdf.PdfReader reader = null;
    ByteArrayOutputStream bos = null;
    try {
        reader = new com.lowagie.text.pdf.PdfReader(bufferedInputStream);
        bos = new ByteArrayOutputStream();
        com.lowagie.text.pdf.PdfStamper pdfStamper = new com.lowagie.text.pdf.PdfStamper(reader, bos);
        com.lowagie.text.pdf.AcroFields acroFields = pdfStamper.getAcroFields();

        // chinese font
        com.lowagie.text.pdf.BaseFont font = com.lowagie.text.pdf.BaseFont.createFont("simsun.ttc,0", com.lowagie.text.pdf.BaseFont.IDENTITY_H, com.lowagie.text.pdf.BaseFont.EMBEDDED);

        for (Map.Entry<String, String> param : params1.entrySet()) {
            // set text font 
            acroFields.setFieldProperty(param.getKey().trim(), "textfont", font, null);

            // replace map content to pdf (write content from map value, map defined by self)
           //  and the problems occur here
            acroFields.setField(param.getKey().trim(), param.getValue());
        }

        //  set pdf edit box can't edit after replacing map value
        pdfStamper.setFormFlattening(true);
        pdfStamper.close();
        // return
        PdfServiceController.ServletUtils.writeAttachment(response, "简单劳动合同模板.pdf", bos.toByteArray());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            assert bos != null;
            bos.close();
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    `
Ngôn ngữ chính
Java
Star
4.4k
Fork
714
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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 LibrePDF/OpenPDF

Tất cả issue của LibrePDF/OpenPDF

Issue tương tự

Thêm issue về Java

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.