ralfstuckert / pdfbox-layout

MIT License
156 stars 74 forks source link

Indentation damaged? #19

Open Parz90 opened 7 years ago

Parz90 commented 7 years ago

As soon as I use the following method, the corresponding paragraph seems to be damaged and is empty:

Paragraph paragraph = new Paragraph(); paragraph.add(new Indent(50, SpaceUnit.pt)); paragraph.addMarkup(content, fontSize, resolvedBaseFont);

Is there maybe something damaged?

Thank you.

ralfstuckert commented 7 years ago

Well, I guess it is not generally damaged, since this is exactly what is done in the indentation example...

Maybe you can pass me some example code to reproduce the problem, so I can analyze it. Thank you

Parz90 commented 7 years ago

It's difficult to sort out the code, while several steps are splitted in different classes. I will try to simply explain my code:

public File producePdf(File pdfFile, LetterDTO letter, IPseudoPropertyContainer propertyContainer)  {

        DomtracPdfDocument doc = new DomtracPdfDocument();
        doc = addLetterContent(doc, letter, propertyContainer);
        try {
            doc.save(pdfFile);
        } catch(IOException e) {
            e.printStackTrace();
        }
        return pdfFile;
    }
public void startNewParagraph(InlineCompositeSection currentParagraph) {
        currentParagraphHelper = new DomtracParagraphHelper(currentParagraph, defaultParagraphStyle);
        pg = new DomtracPdfParagraph();
        pg = currentParagraphHelper.getIndent(pg);
    public void producePdfForStyledText(HasLetterCharacterStyle section, String content) {
        pg = resolveStyledText(section.getCharacterStyle(), content);
    }
    public DomtracPdfParagraph getIndent(DomtracPdfParagraph pg) {
        this.pg = pg;
        parStyle = getEffectiveParagraphStyle();
        String bulletOdd = CompatibilityHelper.getBulletCharacter(1) + " ";
        String bulletEven = CompatibilityHelper.getBulletCharacter(2) + " ";
        String bullet = "";
        if(parStyle.getBulletSymbol() == "*") {
            bullet = bulletOdd;
        }
        else {
            bullet = bulletEven;
        }
        if(parStyle.getIndentText() > 0) {
            try {
                if(parStyle.getIndentTextUnit() == SizeUnit.EM) {
                    pg.add(new Indent(bullet, parStyle.getIndentText().floatValue(), SpaceUnit.em, 11,
                            PDType1Font.TIMES_BOLD, Alignment.Left));
                }
                else {
                    pg.add(new Indent(bullet, parStyle.getIndentText().floatValue(), SpaceUnit.pt, 11,
                            PDType1Font.TIMES_BOLD, Alignment.Left));
                }
            } catch(IOException e) {
                e.printStackTrace();
            }
        }
        return pg;
    }