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

Free Support Forum - aspose.com

URGENT: Image placement on the form is not consistent across browsers

Hi,


We recently decided to go ahead and purchase the license for Aspose.PDF and everything appeared to be working just fine until recently noticing that one of the images on a form seems to move to different positions depending on the browser.

More specifically, we’ve noted the issue between IE 11 and Chrome. I have a TextFragment containing the following:

Signature: __________________________________________

Our client wanted the form to include someones e-signature on the signature line so to do this we acquired a png image from them containing the signature and then placed it on the form using code resembling this:

int lowerLeftX = 240;
int lowerLeftY = 325;
int upperRightX = 340;
int upperRightY = 278;

var imageName = @“C:\Sandbox\AsposePDF\esignature.png”;

//get the page where image needs to be added
Aspose.Pdf.Page page = pdfDocument.Pages[1];
FileStream imageStream = new FileStream(imageName, FileMode.Open);
page.Resources.Images.Add(imageStream);

//using GSave operator: this operator saves current graphics state
page.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
page.Contents.Add(new Operator.ConcatenateMatrix(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 GRestore operator: this operator restores graphics state
page.Contents.Add(new Operator.GRestore());

imageStream.Close();
imageStream.Dispose();

During testing, I was able to set the image perfectly aligned on top of the signature line by affirming the result in IE 11. But after deploying the solution out someone discovered that the image was positioned approximately 100 or more pixels above the line in Chrome.

I am accustomed to discrepancies within browsers; especially with the diverse interpretation for pixel widths. So although I wouldn’t have imagined this issue to be attributed to browser rendering as much as a feature within the Aspose API; even so, we are looking at more than a couple of pixel differences that we could otherwise accept.

Is there a more appropriate way to position the image on the TextFragment line that we should be using? How can we overcome this huge discrepancy?

Please help!

=========================
RECENT UPDATE
=========================
In the process of troubleshooting this issue we’ve found some new information. Apparently the issue is only prevalent after deployment to our Azure Cloud Server. Locally the graphical location is consistent between Chrome and IE after rendering.

Hopefully this new piece of information will provide some insight as to why this is occurring. Why the anomaly exists between browser platform only after deployment is still puzzling though.



Hi Mark,


Thanks for contacting support.

Can you please share if the image disposition is occurring for all the PDF files and image or its appearing for only few documents. Can you please share some resource files, so that we can further look into this matter. We are sorry for this inconvenience.

Hi Mark,


In addition to above reply, we logged an investigation ticket PDFNEWNET-40235 to analyse the scenario. However answer of above queries will help us to address your issue exactly.

We are sorry for the inconvenience caused.

Best Regards,

Hello,



I’ve attached 2 screenshots of the issue. Unfortunately, due to other parts of the form having PII data; I cannot provide the entire PDF file as it would violate certain laws.



I have also sent you an email with the resource file.



Please note as previously mentioned, that the issue does not occur when developing on our local machines; only after having been deployed to our Azure server do we see the consistent issue.



Thanks

Hi Mark,


Thanks for sharing the details.

The information has been associated with earlier reported issue and we will surely consider replicating the problem on Azure environment. Meanwhile can you please share if the problem is occurring for all the documents or its appearing for certain files.

Hi Mark,


Thanks for sharing the screenshots and sample code. It will help us investigating the issue. We will keep you updated about the issuer resolution progress.

Furthermore, issue can be because of different default PDF viewers of your browsers. We will appreciate it if you please double check the default PDF Viewers of your IE and Chrome browsers. You can set Adobe Reader as default PDF viewer and share the results.

We are sorry for the inconvenience caused.

Best Regards,

Hello Tilal,


Has there been any update for the status of this issue? I have acknowledged the recommendation regarding the default PDF viewers but the results are still the same and the issue persists.

While I can acknowledge the potential of differences between PDF viewers, we purchased the license with expectation that the PDF files generated by your product would be fairly consistent regardless of the viewers. However, this issue is far to exaggerated to be acceptable.

I am sending you a small web project that doesn’t nothing but simply render a PDF file and insert and image so you can see the issue we’re seeing. I will also provide you with the source code for you to examine the code that performs the rendering. I am hoping that the problem is due to our lack of expertise on using your product and not a potential bug.

Please inform us of your assessments as the product is being used in one of our critical projects due for release within the next couple of months and we desperately require some resolve.

Regards,

Mark

Hi Mark,


Thanks for your sharing the sample project. I am looking into it and will update you soon.

Best Regards,

Hi Mark,


Thanks for your patience. I have tested your shared project and notice the issue. However I am afraid I am unable to understand your logic to position image signature on the PDF document. Please note left bottom coordinates of the page are (0,0) and top right corner coordinates are (pagewidth, pageheight) in Aspose.Pdf. You care taking UpperRightY value smaller than LowerLeftY, so apparently it seems the issue. Please test your image placement logic with following coordinates and share the results. However if the issue persist then please share your sample source code, so we will look into it and guide you accordingly.

.....

//int lowerLeftX = 240 + signatureHorizontalPosition; // Distance from the Left Horizontally

//int lowerLeftY = 325 + signatureVerticalPosition; // 345 Rectangle top Distance from the top (High numbers increase top height from lower height)

//int upperRightX = 340 + signatureHorizontalPosition; // Bottom Width

//int upperRightY = 278 + signatureVerticalPosition; // 270 Bottom Height (higher numbers move the bottom portion of image up)

int lowerLeftX = 240;

int lowerLeftY = 337;

int upperRightX = 340;

int upperRightY = 377;

//get the page where image needs to be added

Aspose.Pdf.Page page = pdfDocument.Pages[1];

.....

.....


We are sorry for the inconvenience.


Best Regards,