我正在尝试使用aspose.pdf for .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");
问题是,即使我在精确点值中传递PageWidth
和PageHeight
值,也会调整应该作为背景图像传递的图像(我发现aspose的大小不是以像素为单位的点。转换取决于图片的dpi,在我的情况下等于每英寸32,所以:Points = Pixels * 72 * 32
对于我的情况)
我的照片尺寸为1052像素宽* 744像素,32 dpi * .png扩展名;
我应该在代码中更改哪些内容才能使其正常工作?
如果需要任何进一步的信息,请询问。
谢谢你提前:)