1

我正在尝试使用 aspose.pdf 为 .NET 5.0.0 版制作一个 pdf 文件。

我的代码如下所示:

        var license = new License();
        license.SetLicense("path/My.lic");

        var document = new Pdf();
        document.Security = new Security();
        document.Security.IsAnnotationsModifyingAllowed = false;

        //Restrict contents modification
        document.Security.IsContentsModifyingAllowed = false;

        //Restrict copying the data
        document.Security.IsCopyingAllowed = false;

        //Allow to print the document
        document.Security.IsPrintingAllowed = true;

        //Restrict form filling
        document.Security.IsFormFillingAllowed = false;
        document.GraphInfo.Flatness = 1;

        Section mainSection = document.Sections.Add();
        //var signature = new Image(mainSection);
        //signature.ImageInfo.File = "path/MyBackgroundImage.png";
        //signature.ImageInfo.ImageFileType = ImageFileType.Png;


        mainSection.BackgroundImageFile = "path/MyBackgroundImage.png";
        mainSection.BackgroundImageType = ImageFileType.Png;
        mainSection.PageInfo.PageWidth = 1052*72*32;//PageSize.A4Width;
        mainSection.PageInfo.PageHeight = 744 * 72 * 32;//PageSize.A4Height;
        document.SetUnicode();
        document.Save("path/Name.pdf");

问题是应该作为背景图像传递的图像即使在我传递精确点值时也会调整大小PageWidthPageHeight我发现 aspose 以点而不是像素为单位获取大小。转换取决于图片的 dpi,在我的情况下等于每英寸 32 个,所以:Points = Pixels * 72 * 32对于我来说)

我的图片大小为 1052 像素宽 * 744 像素,扩展名为 32 dpi *.png;

我应该在我的代码中进行哪些更改以使其正常工作?

如果需要任何进一步的信息,请询问。

先谢谢了:)

4

0 回答 0