Free Support Forum - aspose.com

Aspose.pdf : Image insert rotated to 90 degree

Hello

We are dynamically adding images to PDF, it works 99% fine, in some cases image printing in 90 degree angle, not able to find whats wrong with code. Can you please help in fixing issue.

Aspose.pdf.dll version is: 9.7.0.0

Code :
// this is for signature control only, image size is 240 x 40

                    var lowerLeftX = (field.Left > onefouth_W ? field.Left + 6 : field.Left) * widthFactor;
                    var lowerLeftY = (pageHeight * heightFactor) - (field.Top * heightFactor) - 25;

                    string base64 = source.Substring(source.IndexOf(',') + 1);
                    base64 = base64.Trim('\0');
                    byte[] chartData = Convert.FromBase64String(base64);
                    var sigImage = new MemoryStream();
                    sigImage.Write(chartData, 0, chartData.Length);
                    sigImage.Flush();
                    sigImage.Position = 0;
                    var img = System.Drawing.Image.FromStream(sigImage);

                    // Resize signature image based on size factors
                    var w = img.Width * widthFactor;
                    var h = img.Height * heightFactor;

                    var upperRightX = lowerLeftX + w;
                    var upperRightY = lowerLeftY + h;

                    // Add image to Images collection of Page Resources
                    pdfPage.Resources.Images.Add(sigImage, 100);

                    // Using GSave operator: this operator saves current graphics state
                    pdfPage.Contents.Add(new Operator.GSave());

                    // Create Rectangle and Matrix objects
                    Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
                    Aspose.Pdf.DOM.Matrix matrix = new Aspose.Pdf.DOM.Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });

                    // Using ConcatenateMatrix (concatenate matrix) operator: defines how image must be placed
                    pdfPage.Contents.Add(new Operator.ConcatenateMatrix(matrix));
                    XImage ximage = pdfPage.Resources.Images[pdfPage.Resources.Images.Count];

                    // Using Do operator: this operator draws image
                    pdfPage.Contents.Add(new Operator.Do(ximage.Name));

                    // Using GRestore operator: this operator restores graphics state
                    pdfPage.Contents.Add(new Operator.GRestore()); 

AsposeIssue.png (29.5 KB)

Thanks

@venkat.veligiram

Thank you for contacting support.

We would like to request you to upgrade to Aspose.PDF for .NET 18.3 as it includes more features and bug fixes. Also, the support is provided based on latest available version. Your code snippet includes some undeclared properties thus we are unable to test it in our environment. Please narrow it down and share a sample application along with source PDF document and image file in case the issue persists with suggested version of Aspose.PDF API. Moreover, an image can be added to a PDF document by Adding Image Stamp in a PDF File.

I hope this will be helpful. Please feel free to contact us if you need any further assistance.

Thank you, after changing to image stamp it is working fine.

@venkat.veligiram,

Thank you for the confirmation. It is nice to hear from you that the problem has been resolved.