Free Support Forum - aspose.com

AddImage demo flips image upside down

I was using your demo and trying to add an image and I noticed that the images are always added upside down. Is there a fix for this?

Thanks,

Hi Jeff,

Thanks for your interest in our products.

I have tried adding the source image file that you have shared to one of my sample PDF document and as per my observations, the image is properly being added to the PDF document. I have tested the scenario using Add Image demo hosted over www.aspose.com/demos/ website.

For your reference, I have also attached the resultant PDF document that I have generated. Please take a look. In case you are using any other demo, please share some details. We are sorry for your inconvenience.

Besides this, you may download the latest release version of Aspose.Pdf for .NET 6.3.0 and try using the code snippet shared over following links when working with Images.

I’ve tried a few others, however there are several PDF’s that we have that the image manages to get flipped, can you take a look and let me know what you think the issue is?

Thanks,

Hi Jeff,

In one of the earlier release version of Aspose.Pdf for .NET, some of the customers encountered similar problems but it has been fixed in latest release version of Aspose.Pdf for .NET. If you have downloaded the demos at your end, please install the latest release version over your system and try using the new aspose.pdf.dll. In case the problem still persists, can you pleas share the PDF documents causing these problems so that we can test the scenario at our end. We are really sorry for your inconvenience.

Thank you for your prompt responses. I have the latest version downloaded on 10-11-2011, posted to the site on 10-10-2011, looks like the DLL is from 9-28-2011.
I’ve attached a PDF that we are seeing the issue.

Hi,

I
have tested the scenario and I am able to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as <span style=“font-family:“Arial”,“sans-serif””>PDFNEWNET-31408
. We
will investigate this issue in details and will keep you updated on the status
of a correction.<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif””><span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif””>

We
apologize for your inconvenience.


If you could provide a work around, for example how to flip the image internally or the matrix to allow this to work would be a great help as we have a deadline looming.

Hi,

I have a workaround for current situation but I am not sure if it will work or not. Before adding image to PDF document, you may first invert it by 180 degree and then stamp it to PDF document.

[C#]
//open document
Document pdfDocument = new Document(@“d:\pdftest\IPChart_by_Division%5b1001USGranted%5d.pdf”);
//set coordinates
int lowerLeftX = 100;
int lowerLeftY = 100;
int upperRightX = 6000;
int upperRightY = 6000;
//get the page where image needs to be added
Page page = pdfDocument.Pages[1];
//load image into stream

string yol = @“d:\pdftest\Copy+of+score_card.jpg”;
System.Drawing.Image resim = System.Drawing.Image.FromFile(yol);
resim = cevir((Bitmap)resim, 180);

System.IO.MemoryStream ms = new MemoryStream();
resim.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

//add image to Images collection of Page Resources
page.Resources.Images.Add(ms);
//using q operator: this operator saves current graphics state
page.Contents.Add(new Operator.q());
//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 });
matrix.Transform(rectangle);
//using cm (concatenate matrix) operator: defines how image must be placed
page.Contents.Add(new Operator.cm(matrix));
XImage ximage = page.Resources.Images[page.Resources.Images.Count];
//using Do operator: this operator draws image
page.Contents.Add(new Operator.Do(ximage.Name));
//using Q operator: this operator restores graphics state
page.Contents.Add(new Operator.Q());
//save updated document
pdfDocument.Save(@“d:\pdftest\output.pdf”);
// close stream object
ms.Close();

}

public static Bitmap cevir(Bitmap b, float angle)
{
//create a new empty bitmap to hold rotated image
Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(returnBitmap);
//move rotation point to center of image
g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2);
//rotate
g.RotateTransform(angle);
//move image back
// g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2);
//draw passed in image onto graphics object
g.DrawImage(b, new System.Drawing.Point(0, 0));
g.Dispose();

return returnBitmap;
}

Hi,

This is still a problem in the last version. Any updates on when this is going to be fixed?

It also happens (text is added 180 degree flipped) when inserting text like in this demo:
http://www.aspose.com/docs/display/pdfnet/Add+Text+in+an+Existing+PDF+File

I’m using the latest Aspose.Pdf version 7.0.

Cheers

Pjotr:
This is still a problem in the last version. Any updates on when this is going to be fixed?
Hi Peter,

Thanks for contacting support.

Our development team is working on resolving this problem but I am afraid its not yet completely resolved. Nevertheless I have requested the development team to share the ETA regarding its resolution. As soon as I have some updates, I will be more than happy to update you with the status of correction. Please be patient and spare us little time.

Pjotr:
It also happens (text is added 180 degree flipped) when inserting text like in this demo:
http://www.aspose.com/docs/display/pdfnet/Add+Text+in+an+Existing+PDF+File
I have tried adding text inside one of my sample PDF documents and I am unable to notice any issue. The text is properly being displayed in the resultant PDF document. May be the issue is related to the specific PDF file which you are using, so can you please share the problematic PDF file so that we can test the scenario at our end. We are really sorry for your inconvenience.

Hi,

I tested different PDF documents. It only seems to happen (image an text flipped) on PDF documents that are generated by Aspose.Words. See attachments for source (docx), the converted PDF and the resulting PDF. Any other PDF document that’s not generated by Aspose.Words works fine.

One other thing I noticed with the PDF files generated by Aspose.Words:

- LLY/URY starts counting from the top when images are inserted; when text is inserted the position is counted from the bottom;

When images ares inserted in PDF files not generated by Aspose.Words the LLY/LLX starts counting form the bottom.

As the problem is related to PDF files generated by Aspose.Words I upgraded to the latest version 11.5.0, but the issue still exists.

Here’s my code:

Document pdfDocument = new Document(fileName);

//get the page where image needs to be added
Page page = pdfDocument.Pages[1];

//create text fragment
TextFragment textFragment = new TextFragment(this.imprintValueTextBox.Text);
textFragment.Position = new Position(Convert.ToDouble(this.numericUpDown3.Value), Convert.ToDouble(this.numericUpDown4.Value));

//set text properties
textFragment.TextState.FontSize = 12;
textFragment.TextState.Font = FontRepository.FindFont(“Courier New”);
textFragment.TextState.BackgroundColor = System.Drawing.Color.LightGray;
textFragment.TextState.ForegroundColor = System.Drawing.Color.Black;

// create TextBuilder object
TextBuilder textBuilder = new TextBuilder(page);

// append the text fragment to the PDF page
textBuilder.AppendText(textFragment);

//save updated document
pdfDocument.Save(fileName + “2.pdf”);

Cheers

Hi Peter,

Thanks for sharing the resource files.

I have tested the scenario using Aspose.Pdf for .NET 7.0.0 and I am able to reproduce the same problem that the newly added text inside the PDF document is flipped. However when I have tested the same scenario using upcoming release version of Aspose.Pdf for .NET 7.1.0, the problem seems to be fixed. Text is properly being displayed. The new release version is under testing phase and is expected to release in few days. So I would request you to please be patient and spare us little time. Once the new version becomes available, we will let you know within this forum thread. We are sorry for your inconvenience.

For your reference, I have also attached the resultant PDF documents generated with two release versions. Please take a look. Please note that I have used new Position(200,200); to specify the location of text object.

Hi,

The sample text is not visible when viewing these sample PDF files on a Mac.

Cheers,

Peter

Hi Peter,


Thanks for your patience and sorry for replying you late.

I am testing this scenario over my end and will get back to you soon. Sorry for the delay and inconvenience.

Hi Peter,


I have tried viewing the resultant PDF over iOS and I am unable to see the Text stamp Hello World and only the gray background is appearing. For the sake of correction, I have logged this problem as PDFNEWNET-33950 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Hi Peter,


I am pleased to share that the new version of Aspose.Pdf for .NET 7.1.0 has been published. Please try using it and in case you still face the same problem or you have any further query, please feel free to contact.

Hi,

The text / image upside / down issue has been fixed. But when text is rendered I still cannot see the text (only the grey background) on the Mac with Preview. So PDFNEWNET-33950 is not fixed yet.

Any updates on when this will be fixed? The PDF product doesn’t seem to have a monthly update.



Cheers,

Peter

Hi Peter,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the feedback.

I am afraid; the issue PDFNEWNET-33950 is still not resolved. I have requested the development team to share an ETA regarding this issue and once I get a feedback, I will update you via this forum thread.

Sorry for the inconvenience,

Pjotr:
Hi,

The text / image upside / down issue has been fixed. But when text is rendered I still cannot see the text (only the grey background) on the Mac with Preview. So PDFNEWNET-33950 is not fixed yet.

Any updates on when this will be fixed? The PDF product doesn't seem to have a monthly update.



Cheers,

Peter

Hi Peter,

Thanks for your patience.

We have further investigate this issue and as per our current estimates, we plan to get this issue resolved in next release version of Aspose.Pdf for .NET 7.3.0 which is planned to release in early September-2012. Please be patient and wait for the new release.

Your patience and comprehension is greatly appreciated in this regard. We apologize for this delay and inconvenience.

The issues you have found earlier (filed as PDFNEWNET-33950) have been fixed in Aspose.Pdf for .NET 7.3.0.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.