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

Free Support Forum - aspose.com

Aspose.Words - shrink to fit one page

I'm am trying to mimic Word's ability to shrink the content of a document, that should be one page, to one page if it bleeds over into a second page.

What I've done is use the documentbuilder object to determine my page count and if over 1, reduce the font of everything in the document.

I loop through the childnodes of node type run and set the font size to 9.

I save the document as a word document.

I save the document as a pdf.

My results:

Word document looks right.

Pdf is the original font size before I looped through the childnodes and set their font sizes smaller.

It's as if the save to pdf ignored this font sizing update.

Hi Scott,


Thanks
for your inquiry.

If you would like to change font (name and size) of the entire document, you should loop through all nodes and change font. You can use DocumentVisitor to achieve this. Please use the following code example to change the font of entire document.

If you still face problem, please share your input document here for testing. I will investigate the issue and provide you more information.


Document doc = new Document(@“C:\Temp\input.docx”);

FontChanger changer = new FontChanger();

doc.Accept(changer);

doc.Save(@“C:\Temp\out.docx”);

doc.Save(@“C:\Temp\out.pdf”);

///

/// Class inherited from DocumentVisitor, that chnges font.

///

class FontChanger : DocumentVisitor

{

///

/// Called when a FieldEnd node is encountered in the document.

///

public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd)

{

//Simply change font name

ResetFont(fieldEnd.Font);

return VisitorAction.Continue;

}

///

/// Called when a FieldSeparator node is encountered in the document.

///

public override VisitorAction VisitFieldSeparator(FieldSeparator fieldSeparator)

{

ResetFont(fieldSeparator.Font);

return VisitorAction.Continue;

}

///

/// Called when a FieldStart node is encountered in the document.

///

public override VisitorAction VisitFieldStart(FieldStart fieldStart)

{

ResetFont(fieldStart.Font);

return VisitorAction.Continue;

}

///

/// Called when a Footnote end is encountered in the document.

///

public override VisitorAction VisitFootnoteEnd(Footnote footnote)

{

ResetFont(footnote.Font);

return VisitorAction.Continue;

}

///

/// Called when a FormField node is encountered in the document.

///

public override VisitorAction VisitFormField(FormField formField)

{

ResetFont(formField.Font);

return VisitorAction.Continue;

}

///

/// Called when a Paragraph end is encountered in the document.

///

public override VisitorAction VisitParagraphEnd(Paragraph paragraph)

{

ResetFont(paragraph.ParagraphBreakFont);

return VisitorAction.Continue;

}

///

/// Called when a Run node is encountered in the document.

///

public override VisitorAction VisitRun(Run run)

{

ResetFont(run.Font);

return VisitorAction.Continue;

}

///

/// Called when a SpecialChar is encountered in the document.

///

public override VisitorAction VisitSpecialChar(SpecialChar specialChar)

{

ResetFont(specialChar.Font);

return VisitorAction.Continue;

}

private void ResetFont(Aspose.Words.Font font)

{

font.Name = mNewFontSize;

}

private double mNewFontSize= 24;

}


I hope, this helps.