Migration Errors _Aspose Pdf

Hi Team ,

We are trying to migrate the Aspose pdf dll from older version 94.0.0) to latest version (17.12). We are facing errors in below classes.

Kindly provide suitable classes to resolve the errors.

Classes Description

Pdf To create a new a pdf document
Section To create a new section in a pdf document
VerticalAlignmentType To vertically align the content in the pdf document
TextInfo Used for Text characteristics like text size
GraphInfo Used for storing graph characteristics like border, color
and linewidth
Segment & Text To create a new segment for text in pdf
ImageInfo Used for image height, width and other characteristics
Color color class is available, but color constructor doenot takes
arguments
Imageformat Imageformat class is available, but it doesnot support
bmp,emf,Exif, Gif, Icon, Jpeg, Png, Tiff, Wmf

Thanks,
Veeramani

Classes & Description

Pdf Class:
To create a new a pdf document
Section class :
To create a new section in a pdf document
VerticalAlignmentType :
To vertically align the content in the pdf document
TextInfo :
Used for Text characteristics like text size
GraphInfo
Used for storing graph characteristics like border, color
and linewidth
Segment & Text
To create a new segment for text in pdf
ImageInfo
Used for image height, width and other characteristics
Color
color class is available, but color constructor doenot takes arguments
Imageformat
Imageformat class is available, but it doesnot support
bmp,emf,Exif, Gif, Icon, Jpeg, Png, Tiff, Wmf

@rave7001

Thanks for contacting support.

Please note that, in latest release(s) of the API, the old legacy Aspose.Pdf.Generator approach has been obsoleted and discontinued. Instead, DOM (Document Object Model) has been introduced in which you deal with the PDF document at object level and it is also enhanced and improved in terms of performance. In order to work with Aspose.API after upgrading to latest version, you need to change your code snippet according to new DOM structure and namespaces.

Please notice following:

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

Section has been replaced with Page, so new code would be as follows:

// Add Page
Page page = doc.Pages.Add();
// Get Page
Page page_ = doc.Pages[1];

Above enum can be used with Aspose.Pdf namespace:

textStamp.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;

Now TextState is available under the namespace of Aspose.Pdf.Text and can be used to set Font, Foreground/Background Color of the text.

textStamp.TextState.Font = FontRepository.FindFont("Arial");
textStamp.TextState.FontStyle = FontStyles.Bold;
.....

You can simply access GraphInfo while using Aspose.Pdf namespace, like following:

Aspose.Pdf.GraphInfo ginfo = new Aspose.Pdf.GraphInfo();

TextFragment and TextSegment classes have been added under the namespace of Aspose.Pdf.Text and can be used to add text inside PDF documents. Please visit “Add Text to PDF file” article in API documentation.

Please use Aspose.Pdf.Image class, in order to use an image and set its height/width:

Aspose.Pdf.Image imageht = new Aspose.Pdf.Image();
// if image is in stream
imageht.ImageStream = new FileStream(""D://myimage.png"", FileMode.Open);
// if image is from a file path
imageht.File = "D://myimage.png";
imageht.IsBlackWhite = true;
imageht.FixHeight = 500;
sec.Paragraphs.Add(imageht);

Any property of type Color, accepts the value from Aspose.Pdf.Color class:

textState.ForegroundColor = Aspose.Pdf.Color.Red;

Furthermore, in case you want to use a color with custom values of colors scheme, you may please follow below code:

int alpha = 10;
int green = 0;
int red = 100;
int blue = 0;
Color alphaColor = Color.FromArgb(alpha, red, green, blue);

In order to save an image in any of the above formats, you may use System.Drawing.Imaging.ImageFormat - however please share a sample code snippet to explain a bit more of your requirement for the image formats, so that we can share respective information.

Moreove, please visit following useful article(s) in our API documentation, in order to work with new approach:

PS: We have released a new version Aspose.Pdf for .NET 18.1, which is latest version of the API currently.

Thanks for your detailed explanation.

We are facing the errors in positioning type namespace in image class and text class. Kindly help us to resolve this error.

for example :

pdfImage.PositioningType = PositioningType.PageRelative;
pdfImage.Left = rect.Left;

In this example, it shows as Aspose.pdf.table or Aspose.pdf.image doesnot contain the definition for positioning Type.

@rave7001

Thanks for getting back to us.

In order to specify position of Table and Image inside PDF document, you may set their Alignment (Horizontal and Vertical) property as well as set Margin. However, in case you are still unable to achieve your requirements, please share your existing code snippet along with input and expected output PDF. We will test the scenario in our environment and share our feedback accordingly.