AFMScanner Parsing Error

	Message	"Error happened during parsing AFMScanner"
	StackTrace	"   at Aspose.Fonts.Type1.Internals.Parsing.BaseType1Scanner.Scan(Int32 startPosition, Int32& endPosition)\r\n   at Aspose.Fonts.Type1.Internals.Parsing.AFMParsing.AFMScanner.Scan()\r\n   at Aspose.Fonts.Type1.Type1FontParser.ParseImpl()\r\n   at Aspose.Fonts.Type1.Type1FontParser.Parse(FontDefinition fontDefinition)\r\n   at Aspose.Fonts.Font.Open(FontDefinition fontDefinition)\r\n   at \u0005  .\u0002(FontDefinition \u0002)\r\n   at Aspose.Pdf.Text.FontRepository.FindFont(String fontName)\r\n   at Aspose.Pdf.TextStamp.\u0002()\r\n   at Aspose.Pdf.Text.TextParagraph.AppendLine(String line, Single lineSpacing)\r\n   at Aspose.Pdf.Text.TextParagraph.AppendLine(String line)\r\n  

            Document doc = new Document();               
            doc.Save(strPdfOutput + @"\tmp\" + parser.ParseDateTimeStamp(email) + ".pdf");
            Page page = doc.Pages.Add();
            page.PageInfo.DefaultTextState = new TextState("Arial");

            

            TextParagraph paragraph = new TextParagraph();                
            paragraph.AppendLine("TEST");

Aspose PDF v16.10.0.0

@caryangell

I have worked with the code shared by you but it is not enough to reproduce the issue. I request you to please try using Aspose.Pdf for .NET 17.11 in your environment and then share your kind feedback with us. In case the issue persists, please create a narrowed down sample application reproducing the issue so that we may investigate it further to help you out,

the goal was to begin a new Asspose.pdf.document. and insert text, i started with 17.11

and have worked back until i finally got an erro message that made sense…

Document doc = new Document();
doc.Save(strPdfOutput + @"\tmp" + parser.ParseDateTimeStamp(email) + “.pdf”);
Page page = doc.Pages.Add();
page.PageInfo.DefaultTextState = new TextState(“Arial”);

            TextParagraph paragraph = new TextParagraph();                
            paragraph.AppendLine(strResultSummary);
            paragraph.AppendLine(@"=======================");

            TextBuilder textBuilder = new TextBuilder(page);
            textBuilder.AppendParagraph(paragraph);

            // append the paragraph to the Pdf page with the TextBuilder
            doc.Save(strPdfOutput + @"\tmp\" + parser.ParseDateTimeStamp(email) + ".pdf");

Its anytime i use a “string” in the text fragment constructor, or add the text post construction using fragment.Text = “blah”… I even tried to pass in a Textreader and same issue… It returns a meaningless message from Aspose.Pdf. with some sort of unicode starttext(\u0002) error

I actually work backwords through your builds, from 17.11 -> 16.10 till i recieved a meaningful error message that i sent in the initial post

@caryangell

I have worked over your requirements and like to request you to please try using following sample code with the latest available version of Aspose.Pdf API on your end.

        //Create a new Document instance
        pdfDocument = new Document();

        // Get particular page
        Page pdfPage = pdfDocument.Pages.Add();

        // Create text fragment
        TextFragment textFragment = new TextFragment("main text");
        textFragment.Position = new Position(100, 600);

        // Set text properties
        textFragment.TextState.FontSize = 12;
        textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman");
        textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray);
        textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);

        // Create TextBuilder object
        TextBuilder textBuilder = new TextBuilder(pdfPage);

        // Append the text fragment to the PDF page
        textBuilder.AppendText(textFragment);

        // Save resulting PDF document.
        pdfDocument.Save(@"D:\AddText.pdf");

For in-depth knowledge of working with text, you may visit this documentation article for your kind reference.

I hope this will be helpful. Please let us know if you need any further assistance.

Aspose.Pdf v 17.11 - project build: .NET 4.5.2
I have implemented the code you sent and im still getting an error anytime i load the contructor with any type of text…

$7533A51511F356F0.jpg (107.7 KB)

$5A62D2164573FC6F.jpg (73.9 KB)

Message: "Error happened during parsing \u0002 "

StackTrace "
at \u0006 .\b ​ \u0002(Int32 \u0002, Int32& \u0003)\r\n
at \u0002 .\u0002()\r\n
at \u0005 ​ .\u0002()\r\n
at \u0005 ​ .\u0002 ​ \u0002(\u0002 \u0002)\r\n
at \u0003 .\u0002(\u0002 \u0002)\r\n
at \b .\u0002(\u0002 \u0002)\r\n
at Aspose.Pdf.Text.FontRepository.FindFont(String fontName)\r\n
at Aspose.Pdf.Text.TextFragment.\u0002(String \u0002)\r\n
at Aspose.Pdf.Text.TextFragment…ctor(String text)\r\n
at DDM.Utilities.LoDER.AsposeUtils.AsposeUtilities.RenderAttachmantSummary(EmailItemsObject email, String strResultSummary, Int32 intFileCounter, String strPdfOutput, List`1& lstFileNames) in myfile

Both the following snippets generate the error…

TextParagraph paragraph = new TextParagraph();
paragraph.AppendLine("");

TextFragment textFragment = new TextFragment()
{
Position = new Position(100, 600)
};

@caryangell

I have observed the images and stack trace shared by you. Please verify if the specified font TimesNewRoman is installed in your environment or not. Kindly execute the code after installing this font, if not installed already.

I do have the Times New Roman font installed on the machine. Do note that the font is acutally “Times New Roman” not “TimesNewRoman” as you have suggested. Should this make a difference?

$7533A51511F356F0.jpg (110.0 KB)

I can fetch the font using the following code, assign to a State object, and then assign to a paragraph, but then throws when i assign the string to the paragraph.Text

            Document doc = new Document();                               
            Page page = doc.Pages.Add();

            Aspose.Pdf.Text.Font font = FontRepository.FindFont("Times New Roman", ignoreCase: true);

            TextParagraph paragraph = new TextParagraph();
            TextState state = new TextState();
            state.Font = font;
            paragraph.AppendLine("", state);

I need to resolve this as i have a production push in next two days, i really do not want to revert back to Aspose.Pdf v10.11

@caryangell

I would like to share with you that both, TimesNewRoman and Times New Roman, work fine and the space between it is not causing any problem. I am still unable to reproduce this issue in my environment. You have shared the .NET framework on your side, please also mention your complete environment details including OS details, Application type etc. Kindly share a narrowed down sample application reproducing this issue, so that we may investigate it further to help you out.

We recommend using latest available version of our APIs as they contain more features and bug fixes as compared to older versions. Support is provided on the basis of latest version, so reverting back may not be a good choice to make.