Font Selection Aspose.PDF versus Words

I am getting an error trying to select a font for my Aspose.PDF document.

I have the font installed on my my machine and the font is correctly selected from Aspose.Words as a run for a TextBox:

 Run blurbText = new Run(doc);
 blurbText.Font.Name =  " CentSchbook BT";

But, when I selected the Font from within Aspose.PDF and enter the code:

 tf.TextState.Font = FontRepository.FindFont("CentSchbook BT"); 

There is an error.

Any Ideas?

How do I modify a PDF (adding some text via a floatingbox) and set the font.

@Toberville

Please use complete font name as following and in case you still face any issue, please share your sample PDF document with more details of your requirements, we will further test the scenario in our environment and address it accordingly.

TextFragment tf = new TextFragment("A quick brown fox jumps over the lazy dog.");
tf.TextState.Font = FontRepository.FindFont("Century Schoolbook BT"); 

Thank You Asad,

Is there a way to check if a Font Exists? If not, then set font to a default font. A Code Snippet would be helpful?

Regarding images, what is the difference between loading via a image stream and not loading via a image stream. I need a good general description on how to load images, perhaps resize them withing a boulding box (perhaps a floating box) and place the image in the document.

@Toberville

You can catch FontNotFoundException and implement setting of default font in catch block as following:

try
{
 tf.TextState.Font = FontRepository.FindFont("CentSchbook BT");
}
catch(FontNotFoundException ex)
{
 tf.TextState.Font = FontRepository.FindFont("Century Schoolbook BT");
} 

Loading images from file or stream is not any different. You can load image using both ways depending upon how input image is getting pass into your program. Furthermore, you can set the image size after loading it (either via file path or stream) by setting its Height and Width as following:

Aspose.Pdf.Image img = new Aspose.Pdf.Image();
img.File = dataDir + "internet.png";
img.FixWidth = 220;
img.FixHeight = 250;

Thank You Asad,

Good feedback! I have the image read with new Aspose.Pdf.Image() and inserted into a floating box, however I think the aspect ratio is not maintained. How do I keep the image within the boundaries of the Floating box and aspect ration intact – in other words imaged resized if necessary. I would also like the image horizontally and vertically aligned within the box.

Best,
Royn

@Toberville

Thank you for your kind feedback.

We have explained in the other thread created by you, that how image can be inserted and aligned as per your requirements. Where Aspose.PDF API mimics the behavior of Adobe Acrobat so the resize algorithm works the same way.

In case you are getting different resized image, with aspect ratio, by Adobe Acrobat then please share the PDF document with us so that we may investigate further.

My apologies Farhan,

I posted my solution to the other thread for sharing. problem solved thanks to you.

@Toberville

Thank you for your kind feedback.

We are pleased to know that your problem has been resolved. Please keep using our API and in event of any further query, feel free to ask.