Stamp is landscape is not placed correctly

We have issues placing the stamp in PDF when the PDF was created as landscape orientation.

Below is code

var pdfDocument = new Aspose.Pdf.Document(inputFilePath);
var inputStream = File.OpenRead(inputStampPath);
var extension = Path.GetExtension(inputStampPath);
var stamp = new StampDetail();
stamp.XIndent= -46;
stamp.YIndent= 289;
stamp.Height= 600;
stamp.Width= 600;

		var reader = new StreamReader(inputStream);
		var text = reader.ReadToEnd();
		var template = DotLiquid.Template.Parse(text);
		var det = "[{\"Page\":\"1\",\"XIndent\":\"-46\",\"YIndent\":\"289\",\"Height\":\"600\",\"Width\":\"600\",\"Rotate\":\"270\"}]";
		var inputObject = new
		{
			Model = JsonConvert.DeserializeObject<ExpandoObject>(det)
		};
		var output = template.Render(DotLiquid.Hash.FromAnonymousObject(inputObject));
		var htmlFragment = new HtmlFragment(output);
		var floatingBox = new FloatingBox(stamp.Width, stamp.Height)
		{   
			Top = stamp.XIndent,
			Left = stamp.YIndent
		};
		floatingBox.Paragraphs.Insert(0, htmlFragment);
			pdfDocument.Pages[1].Paragraphs.Add(floatingBox);
	   
	pdfDocument.Save(path);

@appuelex

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input PDF and stamp files.
  • Please attach the output PDF file that shows the undesired behavior.
  • Please attach the expected output PDF file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Stamp-ConsoleApp (1).zip (5.0 MB)
Actual Result
For normal pdf the stamp is in the correct position but for the landscape pdf it in the wrong position.

Expected Result
want the stamp in the pages right corner for normal pdf as well as landscape pdf with a single absolute position

@appuelex

We have logged this problem in our issue tracking system as PDFNET-52605. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

We encountered the same issue also but in java. Any update on when this will be fixed?

@Kolo_yiu

Would you kindly share your sample document with us along with the sample code snippet so that we can test the scenario in our environment and address it accordingly.

here is my code, we found that the height width are swapped while the form is landscape. and if the page is portrait the result become normal. 1098-Approval of Quotation (Sample).pdf (272.8 KB)

public byte[] processDragDropImage(InputStream in, MultipartFile[] fs, List att, Boolean isSwap) throws IOException, RepositoryException {
pdfDocument = new Document(in);
Map<String, Boolean> isSwapedMap = new HashMap<>();
PageCollection pageCollection = pdfDocument.getPages();

    PDDocument doc = PDDocument.load(in);

// doc.silentPrint(job)
for (PdfEditorAttr a : att) {

        Page firstPage = pageCollection.get_Item(a.getPageNum());
        PageInfo pageinfo = firstPage.getPageInfo();

        double tmpWidth = pageinfo.getWidth();
        double tmpHeight = pageinfo.getHeight();
        Boolean isSwaped = isSwapedMap.get(a.getPageNum().toString()) == null ? false : isSwapedMap.get(a.getPageNum().toString()).booleanValue();
        logger.info(isSwaped.toString());
        if (isSwap && (a.getPdfWidth() > a.getPdfHeight()) && !isSwaped) {
            pageinfo.setHeight(tmpWidth);
            pageinfo.setWidth(tmpHeight);
            isSwapedMap.put(a.getPageNum().toString(), true);
        }

        double scale = pageinfo.getWidth() / a.getPdfWidth();
        double heightScale = pageinfo.getHeight() / a.getPdfHeight();
        if (a.getType().equals("IMAGE") && fs.length > 0) {
            ImageStamp imageStamp = new ImageStamp(Arrays.stream(fs).filter(x -> x.getOriginalFilename().equals(a.getText())).findFirst().get().getInputStream());
            imageStamp.setXIndent(a.getPositionX() * scale);
            imageStamp.setYIndent(a.getPositionY() * heightScale);
            imageStamp.setHeight(a.getHeight() * heightScale);
            imageStamp.setWidth(a.getWidth() * scale);
            pageCollection.get_Item(a.getPageNum()).addStamp(imageStamp);
            imageStamp.close();
        } else if (a.getType().equals("TEXT")) {

            Rectangle rect = new Rectangle(a.getPositionX() * scale, a.getPositionY() * heightScale, (a.getPositionX() + (a.getWidth())) * scale, (a.getPositionY() + a.getHeight()) * heightScale);

            DefaultAppearance appearance = new DefaultAppearance(a.getFont(), (float) (a.getFontSize() * scale), java.awt.Color.getColor("Black"));
            FreeTextAnnotation freeTextAnnotation = new FreeTextAnnotation(pageCollection.get_Item(a.getPageNum()), rect, appearance);
            freeTextAnnotation.setRichText(a.getText());

            freeTextAnnotation.getBorder().setWidth(0);

            freeTextAnnotation.setFlags(freeTextAnnotation.getFlags() | AnnotationFlags.ReadOnly);//| AnnotationFlags.ReadOnly);

            freeTextAnnotation.setEndingStyle(0);
            freeTextAnnotation.flatten();


        }
    }
    //pdfDocument.save();
    isSwapedMap.clear();
    byte[] bytes;
    try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
        pdfDocument.save(stream);
        bytes = stream.toByteArray();
        return bytes;
    } catch (IOException e) {
        e.printStackTrace();
    }


    return null;
}

@appuelex

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-42926

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.