Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#1,172 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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();
        }
    }
    `
Lingua principale
Java
Stelle
4.4k
Fork
714
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di LibrePDF/OpenPDF

Tutte le issue di LibrePDF/OpenPDF

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.