简体   繁体   English

如何获得正确的pdf大小

[英]How to get correct pdf size

Hi I'm using some code as follows: 嗨,我使用的代码如下:

var f = new FileInfo(@"C:\sample.pdf");
var size = f.Length

When I inspect the file in explorer it shows a size of 214KB. 当我在资源管理器中检查文件时,它显示大小为214KB。

My code shows a size of 218.882KB. 我的代码显示大小为218.882KB。

Is this difference due to explorer not including metadata? 这是因为资源管理器不包含元数据吗?

Can somebody tell me how through code I could get the 214KB figure? 谁能告诉我如何通过代码获得214KB的数字?

尝试

var fileLengthInKB = f.Length / 1024.0;

Your C# code shows integer number. 您的C#代码显示整数。
Try calculating using those rules: 尝试使用这些规则计算:

1 KB = 1024 B 1 KB = 1024 B.
1 MB = 1024 KB 1 MB = 1024 KB
etc. 等等

Should match to what explorer shows. 应该与资源管理器显示的匹配。

Also, in the explorer compare 'Size' vs 'Size on Disk'. 此外,在资源管理器中比较'大小'与'磁盘大小'。

I already up-voted the right answer, but wanted to note that Windows is "incorrectly" reporting kibibytes (KiB), not kilobytes (KB). 我已经投了正确的答案,但是想要注意到Windows“错误地”报告kibibytes(KiB),而不是千字节(KB)。

While the KB was traditionally calculated as 2^10 bytes (1024) for decades, the IEC redefined the KB in SI terms (10^3 bytes) in 1999 and created the newer KiB unit of measure to take its place. 虽然传统上将KB计算为2 ^ 10字节(1024)数十年,但IEC在1999年以SI术语(10 ^ 3字节)重新定义了KB,并创建了较新的KiB度量单位来取代它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM