Hi,
Hi Devinder,
Thanks for your inquiry.
In reference to your inquiry, you can get fonts from the Resource collection of the Page object and forms(XObject). Please note that the Page object provides the Resources collection and Resources provide the Fonts collection. Enumerate all pages and then all fonts on the pages. Some fonts may be found in forms (XObjects), so also enumerate all the Forms in the Page.Resources and then enumerate xForm.Resources.Fonts. The XForm may contain another form inside the resources, so it is a recursion. Please check the following code for details.
static void Main(string[] args)
{
Document pdf = new Document(myDir + "test.pdf");
Dictionary<string, string> fontNames = new Dictionary<string, string>();
for (int i = 1; i <= pdf.Pages.Count; i++)
{
foreach (Aspose.Pdf.Text.Font font in pdf.Pages[i].Resources.Fonts)
{
if (!fontNames.ContainsKey(font.FontName))
fontNames.Add(font.FontName, font.FontName);
}
if (pdf.Pages[i].Resources.Forms.Count > 0)
ProcessXForms(pdf.Pages[i].Resources.Forms, fontNames);
}
foreach (string fontName in fontNames.Keys)
{
Console.WriteLine("Font {0} on page resource", fontName);
}
pdf.Dispose();
}
public static void ProcessXForms(Aspose.Pdf.XFormCollection forms, Dictionary<string, string> fontNames)
{
foreach (Aspose.Pdf.XForm form in forms)
{
if (form.Resources.Fonts != null)
{
foreach (Aspose.Pdf.Text.Font font in form.Resources.Fonts)
{
if (!fontNames.ContainsKey(font.FontName))
fontNames.Add(font.FontName, font.FontName);
// recursive call
if (form.Resources.Forms.Count > 0)
ProcessXForms(form.Resources.Forms, fontNames);
}
}
}
}
Regarding your second question about creating a PDF column by column, I am afraid that this feature is not currently supported in the new generator. I have logged a new feature request PDFNEWNET-37950 in our issue tracking system for its implementation. Meanwhile, you may use the old generator (Aspose.Pdf.Generator) to create a PDF with columns. Please check the sample code below. We will notify you as soon as it is supported in the new generator.
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
// specify the left margin info for the PDF file
pdf.PageSetup.Margin.Left = new Aspose.Pdf.Generator.MarginInfo().Left = 40;
// specify the Right margin info for the PDF file
pdf.PageSetup.Margin.Right = new Aspose.Pdf.Generator.MarginInfo().Right = 40;
Aspose.Pdf.Generator.Section sec0 = pdf.Sections.Add();
Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();
Aspose.Pdf.Generator.Section sec2 = pdf.Sections.Add();
sec0.IsNewPage = false;
sec1.IsNewPage = false;
sec2.IsNewPage = false;
Graph graph1 = new Graph(sec0, 500, 2);
// Add the line to paragraphs collection of section object
sec0.Paragraphs.Add(graph1);
// specify the coordinates for the line
float[] posArr = new float[] { 1, 2, 500, 2 };
Line l1 = new Line(graph1, posArr);
graph1.Shapes.Add(l1);
//Create string variables with text containing html tags
string s = "<font face=\"Times New Roman\" size=18>" + "<strong>How to Steer Clear of money scams</strong> </font>";
//Create text paragraphs containing HTML text
Text heading_text = new Text(s);
heading_text.IsHtmlTagSupported = true;
heading_text.TextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;
sec0.Paragraphs.Add(heading_text);
// Add four columns in the section
sec1.ColumnInfo.ColumnCount = 2;
// Set the spacing between the columns
sec1.ColumnInfo.ColumnSpacing = "5";
sec1.ColumnInfo.ColumnWidths = "105 105";
Text text1 = new Text("By A Googler (The Official Google Blog)");
text1.TextInfo.FontSize = 8;
text1.TextInfo.LineSpacing = 2;
text1.TextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;
sec1.Paragraphs.Add(text1);
text1.TextInfo.FontSize = 10;
text1.TextInfo.IsTrueTypeFontItalic = true;
// Create a graphs object to draw a line
Graph graph2 = new Graph(50, 10);
// specify the coordinates for the line
float[] posArr2 = new float[] { 1, 10, 100, 10 };
Line l2 = new Line(graph2, posArr2);
graph2.Shapes.Add(l2);
// Add the line to paragraphs collection of section object
sec1.IsNewColumn = true;
sec1.Paragraphs.Add(graph2);
Text text2 = new Text(@"Sed augue tortor, sodales id, luctus et, pulvinar ut, eros. Suspendisse vel dolor. Sed quam. Curabitur ut massa vitae eros euismod aliquam. Pellentesque sit amet elit. Vestibulum interdum pellentesque augue. Cras mollis arcu sit amet purus. Donec augue. Nam mollis tortor a elit. Nulla viverra nisl vel mauris. Vivamus sapien. nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et,nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales.nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales.");
text2.TextInfo.IsTrueTypeFontItalic = false;
sec1.Paragraphs.Add(text2);
Text text44 = new Text(@" ");
text44.TextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Justify;
sec2.Paragraphs.Add(text44);
// Save the Pdf
pdf.Save(myDir + "Multiple_Columns.pdf");
Please feel free to contact us for any further assistance.
Best Regards,
The issues you have found earlier (filed as PDFNEWNET-37950) have been fixed in Aspose.Pdf for .NET 10.3.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi Divender,