我有一个用户PDF上传提交系统,而通常情况下,用户会上传非常大的PDF,这是最初打算打印时,我们只需要他们的网页大小的查看。我需要在服务器上自动压缩它们。我们正在运行Windows 2003。现在,我们只有用户通过SoftArtisans.FileUp
方法上传PDF。
我的问题是,在用户上传PDF之后,在服务器上自动完成此操作的最佳或最简单方法是什么?
发布于 2013-05-08 14:25:35
为什么不试试这个网站。以前使用过它,它可以正常工作:
http://www.neeviapdf.com/PDFcompress/?w=code
发布于 2013-05-09 08:26:34
在您的情况下,Docotic.Pdf库可能很有用。
如果我明白你的意思,你愿意减少上传PDF文件中图像的大小/质量,并应用其他通用压缩选项。
下面是此类场景的示例代码。守则:
使用示例中的代码,您应该能够优化上传的文件。
public static void compressPdf(string path, string outputPath)
{
using (PdfDocument doc = new PdfDocument(path))
{
foreach (PdfImage image in doc.Images)
{
// image that is used as mask or image with attached mask are
// not good candidates for recompression
//
// also, small images might be used as mask even though image.IsMask for them is false
//
if (!image.IsMask && image.Mask == null && image.Width >= 8 && image.Height >= 8)
{
if (image.ComponentCount == 1)
{
// for black-and-white images fax compression gives better results
image.RecompressWithGroup4Fax();
}
else
{
// scale image and recompress it with JPEG compression
// this will cause image to be smaller in terms of bytes
// please note that some of the image quality will be lost
image.Scale(0.5, PdfImageCompression.Jpeg, 65);
// or you can just recompress the image without scaling
//image.RecompressWithJpeg(65);
// or you can resize the image to specific size
//image.ResizeTo(640, 480, PdfImageCompression.Jpeg, 65);
}
}
}
var saveOptions = new PdfSaveOptions
{
RemoveUnusedObjects = true,
// this option causes smaller files but
// such files can only be opened with Acrobat 6 (released in 2003) or newer
UseObjectStreams = true,
// this option will cause output file to be optimized for Fast Web View
Linearize = true
};
doc.Save(outputPath, saveOptions);
}
}
免责声明:我为Bit工作,图书馆的供应商。
https://stackoverflow.com/questions/16420500
复制相似问题