Hello, I would like to report a problem that occurred in an implementation, I used the latest version of aspose until 20.10.0, in the pro version. When deploying to an aws linux machine the project cannot find the font to use, in this sense, I inserted a script to install the font on the machine and tried in some ways to use it. however, it always gave an error that the source had not been found.
I tried to update the fonts folder using:
first example :
font = Aspose.Pdf.Text.FontRepository.OpenFont("~/.fonts/arial.ttf"); this not working.
second example:
FormattedText formatText = new FormattedText(string.Empty, System.Drawing.Color.Gray, System.Drawing.Color.Transparent, Path.Combine(path, “arial.ttf”), EncodingType.Identity_h, false, 7F); this not working.
third example:
this not working
namespace AsposeUtil.PDF
{
internal class PdfDocumentManager : PdfBaseClass
{
internal void AddFooterText(Stream outputStream, Stream inputStream, string footerText)
{
StringBuilder text = new StringBuilder();
foreach (string lineText in footerText.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
text.Append(lineText);
// Open document
Document pdfDocument = new Document(inputStream);
// Create footer
TextStamp textStamp = new TextStamp(text.ToString());
// Set properties of the stamp
Aspose.Pdf.Text.Font font = Aspose.Pdf.Text.FontRepository.OpenFont("~/.fonts/arial.ttf");
textStamp.TextState.Font = font;
textStamp.BottomMargin = 10;
textStamp.TextState.FontSize = 7F;
textStamp.TextState.BackgroundColor = Color.Transparent;
textStamp.TextState.ForegroundColor = Color.Gray;
textStamp.WordWrap = true;
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.VerticalAlignment = VerticalAlignment.Bottom;
// Add footer on all pages
foreach (Page page in pdfDocument.Pages)
{
page.AddStamp(textStamp);
}
// Save updated PDF file
pdfDocument.Save(outputStream);
}
}
}
fourth example:
this not work
namespace AsposeUtil.PDF
{
internal class PdfDocumentManager : PdfBaseClass
{
internal void AddFooterText(Stream outputStream, Stream inputStream, string footerText)
{
using (PdfFileMend pdfFileMend = new PdfFileMend())
{
pdfFileMend.BindPdf(inputStream);
pdfFileMend.IsWordWrap = true;
pdfFileMend.WrapMode = WordWrapMode.ByWords;
Aspose.Pdf.Text.Font myFont = Aspose.Pdf.Text.FontRepository.OpenFont('caminho fonte');
customFont.IsEmbedded = true;
Aspose.Pdf.Text.TextState style = new Aspose.Pdf.Text.TextState();
style.Font = customFont;
style.FontSize = 10F;
style.FontStyle = FontStyles.Regular;
style.LineSpacing = 1;
style.BackgroundColor = Aspose.Pdf.Color.Transparent;
style.ForegroundColor = Aspose.Pdf.Color.Gray;
StringBuilder text = new StringBuilder();
foreach (string lineText in footerText.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
text.Append(lineText);
Aspose.Pdf.Text.TextFragment frag = new Aspose.Pdf.Text.TextFragment(text.ToString());
frag.IsInLineParagraph = true;
frag.TextState.ApplyChangesFrom(style);
foreach (Page page in pdfFileMend.Document.Pages)
{
if (page.Footer == null)
page.Footer = new Aspose.Pdf.HeaderFooter();
page.Footer.Paragraphs.Add(frag);
}
pdfFileMend.Save(outputStream);
}
}
}
}
fifth example:
this not work
Aspose.Pdf.Text.FontRepository.Sources.Add(new FolderFontSource("~/.fonts"));
this not work
using (MemoryStream ms = new MemoryStream(Properties.Resources.Aspose_Total)) {
Aspose.Pdf.Text.Font myFont = Aspose.Pdf.Text.FontRepository.OpenFont(ms, Aspose.Pdf.Text.FontTypes.TTF);
myFont.IsEmbedded = true;
}