We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Image rendering to existing pdf flips upside down

Hi,


I am using Aspose.pdf to render controls in my existing pdf. I am rendering image and label control in existing pdf. Version: Version 8.0.0

While rendering image, sometimes (Not frequently) the image gets rendered upside down. e.g.) i have added image in page one at top left corner at 100 px down from top and 100 px from left, but the actual rendering was at bottom left corner at around 100 px up from bottom and 100 px from left. Its look like a mirror image.
I am adding screenshot here for reference.

I am using ‘Page’ class to add image to my pages.
pdfPage.Resources.Images.Add(imageStream);

I can provide the complete code if required.

Is there any problem with current release 8.0.0?
Any help would be appreciated.


Regards,
Brijen Patel

Hi Brijen,


Sorry for the inconvenience faced. Can you please share sample image and code here? So we will investigate and share more information accordingly.

Best Regards,
Hi Tilal,

Here is the sample code i am using to generate pdf file.

var pdfDocument = new Document(docFinalPath);
var pdfPageNo = pdfDocument.Pages[pageNumber];
//Image -1 on Page #1
double leftPosition = 412.5
double bottomPosition = 693.75
// set coordinates
double lowerLeftX = 134.25;
double lowerLeftY = 46.5;
double upperRightX = 0;
double upperRightY = 0;

var imageStream = new MemoryStream(imageBytes); //imageBytes is a byte array for image to be randered on pdf
pdfPageNo.Resources.Images.Add(imageStream);

pdfPageNo.Contents.Add(new Operator.GSave());
var rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);

var matrix =
new Aspose.Pdf.DOM.Matrix(
new[]
{
rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, leftPosition, // rectangle.LLX, Control's left position from page
bottomPosition // rectangle.LLY Control's botom position from page
});

pdfPageNo.Contents.Add(new Operator.ConcatenateMatrix(matrix));
XImage ximage = pdfPageNo.Resources.Images[pdfPageNo.Resources.Images.Count];

pdfPageNo.Contents.Add(new Operator.Do(ximage.Name));
pdfPageNo.Contents.Add(new Operator.GRestore());



double leftPosition = 40.5
double bottomPosition = 699.75
// set coordinates
double lowerLeftX = 134.25;
double lowerLeftY = 46.5;
double upperRightX = 0;
double upperRightY = 0;

var imageStream = new MemoryStream(imageBytes); //imageBytes is a byte array for image to be randered on pdf
pdfPageNo.Resources.Images.Add(imageStream);

pdfPageNo.Contents.Add(new Operator.GSave());
var rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);

var matrix =
new Aspose.Pdf.DOM.Matrix(
new[]
{
rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, leftPosition, // rectangle.LLX, Control's left position from page
bottomPosition // rectangle.LLY Control's botom position from page
});

pdfPageNo.Contents.Add(new Operator.ConcatenateMatrix(matrix));
XImage ximage = pdfPageNo.Resources.Images[pdfPageNo.Resources.Images.Count];

pdfPageNo.Contents.Add(new Operator.Do(ximage.Name));
pdfPageNo.Contents.Add(new Operator.GRestore());


pdfDocument.Save(docSaveDir);

I am attaching the pdf file generated using this code.
I have two images on page# 1 & 2. Both images flips upside down. please check the attached pdf.
I have also added sticy note where the actual image should be rendered.


Thanks & Regards,
Brijen Patel

Hi Brijen,


Thanks for providing additional information. While testing with your provided document, I’ve managed to replicate the issue and logged as PDFNEWNET-35346 for further investigation and resolution. We will keep you updated about issue progress via this forum thread. As a workaround you can add image as image stamp in existing document.

Sorry for the inconvenience faced.

Best Regards,


Thanks for the update Tilal, I will wait for your next update and at the same time i will also look into the workaround - Image statmp - as you suggested.

Hi Tilal,


I am still waiting for your reply. Any update?

Thanks,
Brijen Patel

Hi Brijen,


Thanks for your inquiry. I’m afraid the reported issue is still not resolved and pending for analysis in queue with other priority tasks. We will notify you via this forum thread once it is resolved.

Thanks for your patience and cooperation.

Best Regards,

Hi Brijen,


We are sorry for the delayed response. Please change your code as following, it will resolve the issue.

var matrix =<o:p></o:p>

new Aspose.Pdf.DOM.Matrix(

new[]

{

rectangle.URX - rectangle.LLX, 0, 0, rectangle.LLY - rectangle.URY, leftPosition,

bottomPosition

});

Please feel free to contact us for any further assistance.


Best Regards,