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.
ClassesDescription
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
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
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:
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:
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.