Few function are missing from new version of Aspose pdf

Hi,

I have taken the latest version of aspose lib but after updating with the latest lib i am getting errors from the existing working code. In the below code i am getting error “Generator” doesn’t exist in the aspose.pdf. I am using this method for converting text to pdf. Is there any alternative function in the latest lib which does the same activity.

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

@pradeepdone,

There are no Pdf and Section elements in the new DOM (Document Object Model) approach, as the structure of a PDF file is hierarchical, Aspose.PDF for .NET API also accesses the elements in the same way. You can use Document and Page instances instead of the Pdf and Section. In order to better understand the new DOM approach, please refer to this help topic: Introduction to the DOM API

Furthermore, we are documenting each API change in the release notes section. Please refer to the release notes section: Release Notes

Below is the code i have used to convert text to pdf. So with the latest version can help on how do i do it.

        System.IO.TextReader tr = new StreamReader(FilePath);

        Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

        Aspose.Pdf.Document pdf2 = new Aspose.Pdf.Document();

        Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

        sec1.PageInfo.Margin.Left = sec1.PageInfo.Margin.Top = 5;

        Aspose.Pdf.Generator.Text t2 = new Aspose.Pdf.Generator.Text(tr.ReadToEnd());
        
        // set the font size for text inside PDF file
        t2.TextInfo.FontSize = 12;
        // add text to paragraphs collection of section object
        sec1.Paragraphs.Add(t2);

        pdf1.Save(DestinationPath);

@pradeepdone,

Please try the following code example:

C#

System.IO.TextReader tr = new StreamReader(FilePath);
Aspose.Pdf.Document pdf1 = new Aspose.Pdf.Document();
Aspose.Pdf.Document pdf2 = new Aspose.Pdf.Document();
Aspose.Pdf.Page page = pdf1.Pages.Add();
page.PageInfo.Margin.Left = page.PageInfo.Margin.Top = 5;
TextFragment t2 = new TextFragment(tr.ReadToEnd());
// set the font size for text inside PDF file
t2.TextState.FontSize = 12;
// add text to paragraphs collection of section object
page.Paragraphs.Add(t2);
pdf1.Save(DestinationPath);

Please also refer to this helping section: Working with Text

Thank u for reply that actually worked for me.

@pradeepdone,

It is nice to hear from you that the problem has been resolved. Please feel free to let us know whenever you require any further assistance.

What about the tab1.GetMinColumnWidth(0) that was available in aspose.pdf.generator???

@JCI-YORK

Please use the below code with new DOM model to set the column width as minimum or as per the content:

tab1.ColumnAdjustment = ColumnAdjustment.AutoFitToContent;
tab1.ColumnWidths = "50 50 50";

With generator namespace, I could loop through the columns set all the columns to be min spaced, then take what is left and place it in whatever column I wanted to absorb the rest of the space. I can no longer do that.

@JCI-YORK

You can also use DOM in order to specify the column widths in percentage as well as the number of columns like below:

tab1.ColumnWidths = "10% 10% 10% 20% 50%"; // 100% total width on page

Well yeah, been doing it that way for years.

@JCI-YORK

In case you are unable to find any alternative of any other Class or Feature in DOM approach, please feel free to create a new topic.