Java 添加Spire pdf的图像戳变大

Java 添加Spire pdf的图像戳变大,java,image,pdf,io,stamp,Java,Image,Pdf,Io,Stamp,我正在将一张315p x 315p的图像作为邮票添加到pdf文件中。但它变大了: 如你所见,它现在大约有420p宽。pdf文件未缩放 我紧跟着那辆车 我以为它是矩形2D,所以我根据这个创建了一个矩形,它的宽度和高度都是正确的: 这里有什么问题 以下是我的源代码: pom.xml的一部分 <repositories> <repository> <id>com.e-iceblue</id> <name&

我正在将一张315p x 315p的图像作为邮票添加到pdf文件中。但它变大了:

如你所见,它现在大约有420p宽。pdf文件未缩放

我紧跟着那辆车

我以为它是
矩形2D
,所以我根据这个创建了一个矩形,它的宽度和高度都是正确的:

这里有什么问题

以下是我的源代码:

pom.xml的一部分

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.pdf.free</artifactId>
        <version>3.9.0</version>
    </dependency>
</dependencies>
public static void main(String[] args) {
    String inputPdfPath = "F:/TEMP/a.pdf";
    String outputPdfPath = "F:/TEMP/a2.pdf";
    String stampImagePath = "C:/Users/Administrator/nextcloud/company/lanzhong/210528审批优化/approved.png";

    //Create a PdfDocument object
    PdfDocument doc = new PdfDocument();
    //Load a PDF document
    doc.loadFromFile(inputPdfPath);
    //Get the last page
    PdfPageBase page = doc.getPages().get(doc.getPages().getCount() - 1);
    //Load an image file
    PdfImage image = PdfImage.fromFile(stampImagePath);
    //Get the width and height of the image
    int width = image.getWidth();
    int height = image.getHeight();
    //Create a PdfTemplate object based on the size of the image
    PdfTemplate template = new PdfTemplate(width, height);
    //Draw image on the template
    template.getGraphics().drawImage(image, 0, 0, width, height);
    //Create a rubber stamp annotation, specifying its location and position
    Rectangle2D rect = new Rectangle2D.Float((float)(10), (float)(10), width, height);
    PdfRubberStampAnnotation stamp = new PdfRubberStampAnnotation(rect);
    //Create a PdfAppearance object
    PdfAppearance pdfAppearance = new PdfAppearance(stamp);
    //Set the template as the normal state of the appearance
    pdfAppearance.setNormal(template);
    //Apply the appearance to the stamp
    stamp.setAppearance(pdfAppearance);
    //Add the stamp annotation to PDF
    page.getAnnotationsWidget().add(stamp);
    //Save the file
    doc.saveToFile(outputPdfPath);
    doc.close();
}