public static void Run() { //ExStart: GetWidthOfTextDynamically // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); Aspose.Pdf.Text.Font font = FontRepository.FindFont("Arial"); TextState ts = new TextState(); ts.Font = font; ts.FontSize = 14; if (Math.Abs(font.MeasureString("A", 14) - 9.337) > 0.001) { Console.WriteLine("Unexpected font string measure!"); } if (Math.Abs(ts.MeasureString("z") - 7.0) > 0.001) { Console.WriteLine("Unexpected font string measure!"); } for (char c = 'A'; c <= 'z'; c++) { double fnMeasure = font.MeasureString(c.ToString(), 14); double tsMeasure = ts.MeasureString(c.ToString()); if (Math.Abs(fnMeasure - tsMeasure) > 0.001) { Console.WriteLine("Font and state string measuring doesn't match!"); } } //ExEnd: GetWidthOfTextDynamically }
public static Aspose.Pdf.Text.Font GetFont(string strFont) { Aspose.Pdf.Text.Font font = FontRepository.FindFont("Times"); try { font = FontRepository.FindFont(strFont, true); } catch { } return font; }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Open document Document pdfDocument = new Document(dataDir + "FormFieldFont14.pdf"); // Get particular form field from document Aspose.Pdf.InteractiveFeatures.Forms.Field field = pdfDocument.Form["textbox1"] as Aspose.Pdf.InteractiveFeatures.Forms.Field; // Create font object Aspose.Pdf.Text.Font font = FontRepository.FindFont("ComicSansMS"); // Set the font information for form field field.DefaultAppearance = new Aspose.Pdf.InteractiveFeatures.DefaultAppearance(font, 10, System.Drawing.Color.Black); // Save updated document pdfDocument.Save(dataDir + "FormFieldFont14_out.pdf"); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); // Open document Document pdfDocument = new Document(dataDir + "input.pdf"); // Get particular form field from document Aspose.Pdf.InteractiveFeatures.Forms.Field field = pdfDocument.Form["textbox1"] as Aspose.Pdf.InteractiveFeatures.Forms.Field; // Create font object Aspose.Pdf.Text.Font font = FontRepository.FindFont("ComicSansMS"); // Set the font information for form field field.DefaultAppearance = new Aspose.Pdf.InteractiveFeatures.DefaultAppearance(font, 10, System.Drawing.Color.Black); // Save updated document pdfDocument.Save(dataDir + "output.pdf"); }
public static void Run() { // ExStart:ReplaceMissingFonts // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion(); Aspose.Pdf.Text.Font originalFont = null; try { originalFont = FontRepository.FindFont("AgencyFB"); } catch (Exception) { // Font is missing on destination machine FontRepository.Substitutions.Add(new SimpleFontSubstitution("AgencyFB", "Arial")); } var fileNew = new FileInfo(dataDir + "newfile_out.pdf"); var pdf = new Document(dataDir + "input.pdf"); pdf.Convert(dataDir + "log.xml", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete); pdf.Save(fileNew.FullName); // ExEnd:ReplaceMissingFonts }
public static void Run() { // ExStart:FormFieldFont14 // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Open document Document pdfDocument = new Document(dataDir + "FormFieldFont14.pdf"); // Get particular form field from document Aspose.Pdf.Forms.Field field = pdfDocument.Form["textbox1"] as Aspose.Pdf.Forms.Field; // Create font object Aspose.Pdf.Text.Font font = FontRepository.FindFont("ComicSansMS"); // Set the font information for form field // Field.DefaultAppearance = new Aspose.Pdf.Forms.in.DefaultAppearance(font, 10, System.Drawing.Color.Black); dataDir = dataDir + "FormFieldFont14_out.pdf"; // Save updated document pdfDocument.Save(dataDir); // ExEnd:FormFieldFont14 Console.WriteLine("\nForm field font setup successfully.\nFile saved at " + dataDir); }