We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose word scale font size

I am converting text to pdf using aspose-words(Java)
I also want to increase the page size,which i am doing using following call.

Document document = new Document(filePath);

DocumentBuilder builder = new DocumentBuilder(document);
builder.getPageSetup().setPageWidth(Double.parseDouble(pageWidth));
builder.getPageSetup().setPageHeight(Double.parseDouble(pageWidth));

But the font size is not scaling up with the page size what can be done.

This query is on the similar line as following query posted by me:

@pranavkhedkar1512 You can use DocumentVisitor to change font in the whole document. For example see the following simple code:

Document doc = new Document("C:\\Temp\\in.txt");

FontChanger fontChanger = new FontChanger(2.0f);
doc.accept(fontChanger);

doc.save("C:\\Temp\\out.pdf");
private static class FontChanger extends DocumentVisitor
{
    public FontChanger(float fontScaleFactor)
    {
        mFontScaleFactor = fontScaleFactor;
    }

    /**
    * Called when a FieldEnd node is encountered in the document.
    */
    public int visitFieldEnd(FieldEnd fieldEnd)
    {
        //Simply change font name
        ResetFont(fieldEnd.getFont());
        return VisitorAction.CONTINUE;
    }

    /**
    * Called when a FieldSeparator node is encountered in the document.
    */
    public int visitFieldSeparator(FieldSeparator fieldSeparator)
    {
        ResetFont(fieldSeparator.getFont());
        return VisitorAction.CONTINUE;
    }

    /**
    * Called when a FieldStart node is encountered in the document.
    */
    public int visitFieldStart(FieldStart fieldStart)
    {
        ResetFont(fieldStart.getFont());
        return VisitorAction.CONTINUE;
    }

    /**
    * Called when a Footnote end is encountered in the document.
    */
    public int visitFootnoteEnd(Footnote footnote)
    {
        ResetFont(footnote.getFont());
        return VisitorAction.CONTINUE;
    }

    /**
    * Called when a FormField node is encountered in the document.
    */
    public int visitFormField(FormField formField)
    {
        ResetFont(formField.getFont());
        return VisitorAction.CONTINUE;
    }

    /**
    * Called when a Paragraph end is encountered in the document.
    */
    public int visitParagraphEnd(Paragraph paragraph)
    {
        ResetFont(paragraph.getParagraphBreakFont());
        return VisitorAction.CONTINUE;
    }

    /**
    * Called when a Run node is encountered in the document.
    */
    public int visitRun(Run run)
    {
        ResetFont(run.getFont());
        return VisitorAction.CONTINUE;
    }

    /**
    * Called when a SpecialChar is encountered in the document.
    */
    public int visitSpecialChar(SpecialChar specialChar)
    {
        ResetFont(specialChar.getFont());
        return VisitorAction.CONTINUE;
    }

    private void ResetFont(com.aspose.words.Font font)
    {
        font.setSize(font.getSize() * mFontScaleFactor);
    }

    private float mFontScaleFactor = 1.0f;
}

This seems to be working.
Thank you.