Iki minangka solusi profesional kanggo ngompres PDF nggunakake C#, F#, VB.NET. Gunakake API optimasi PDF kanggo ngembangake piranti lunak tingkat dhuwur, platform-independen kanggo platform .NET lan .NET Core. Coba online gratis!
Pustaka C# iki nyedhiyakake pangembang kanthi kemampuan kanggo ngompres PDF dokumen kanthi cepet lan efisien kanthi program. Gampang entuk output PDF sing dioptimalake siap kanggo dicithak, diarsipake utawa dienggo bareng liwat jaringan. Iki minangka solusi pangolahan PDF dokumen mandiri kanggo C# sing ora mbutuhake piranti lunak pihak katelu kanggo diinstal.
Produk kita nyedhiyakake pangembang C# kanthi API terpadu kanggo nyuda ukuran PDF file. Kompresi PDF ditindakake kanthi rong pass. Sajrone pass pisanan, kabeh kaca PDF diowahi dadi format gambar. Produk kita nggunakake algoritma kompresi gambar sing adaptif lan efisien banget sing ngidini pangembang entuk output PDF sing kompak nalika njaga kualitas dokumen sing optimal. Ing pass sabanjure, urutan gambar dikompres lan digabungake kanggo mbentuk isi PDF file anyar sing dioptimalake.
Kompresi PDF digawe gampang karo 'Aspose.Words for .NET'. Conto ing ngisor iki nuduhake carane nyuda ukuran PDF file ing C#:
dotnet add package Aspose.Words
Nyalin
using Aspose.Words;
using Aspose.Words.Pdf2Word.FixedFormats;
using var pdfStream = File.OpenRead("Input.pdf");
var renderer = new PdfFixedRenderer();
var pdfReadOptions = new PdfFixedOptions
{
ImageFormat = FixedImageFormat.Jpeg,
JpegQuality = 50
};
const double maxPageDimension = 1584;
var pagesStream = renderer.SavePdfAsImages(pdfStream, pdfReadOptions);
var builder = new DocumentBuilder();
for (var i = 0; i < pagesStream.Count; ++i)
{
// Setel ukuran kaca maksimal kanggo ngindhari skala gambar kaca saiki.
var pageSetup = builder.PageSetup;
SetPageSize(pageSetup, maxPageDimension, maxPageDimension);
var pageImage = builder.InsertImage(pagesStream[i]);
SetPageSize(pageSetup, pageImage.Width, pageImage.Height);
pageSetup.TopMargin = 0;
pageSetup.LeftMargin = 0;
pageSetup.BottomMargin = 0;
pageSetup.RightMargin = 0;
if (i != pagesStream.Count - 1)
builder.InsertBreak(BreakType.SectionBreakNewPage);
}
var saveOptions = new PdfSaveOptions
{
CacheBackgroundGraphics = true
};
builder.Document.Save("Output.pdf", saveOptions);
private void SetPageSize(PageSetup pageSetup, double width, double height)
{
pageSetup.PageWidth = width;
pageSetup.PageHeight = height;
}
using Aspose.Words;
var doc = new Document("Input.pdf");
doc.Cleanup();
var nodes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in nodes)
{
if (shape.IsImage)
{
// Iku nganti pangembang kanggo milih perpustakaan kanggo komprèsi gambar.
using var image = Image.FromStream(shape.ImageData.ToStream());
// ...
// Compress gambar lan nyetel maneh menyang wangun.
shape.ImageData.SetImage("yourCompressedImage");
}
}
var saveOptions = new PdfSaveOptions
{
CacheBackgroundGraphics = true
};
doc.Save("Output.pdf", saveOptions);
using Aspose.Words;
var doc = new Document("Input.pdf");
doc.Cleanup();
var nodes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in nodes)
{
if (shape.IsImage)
{
// Iku nganti pangembang kanggo milih perpustakaan kanggo komprèsi gambar.
using var image = Image.Fromstream(shape.ImageData.ToStream());
// ...
// Compress gambar lan nyetel maneh menyang wangun.
shape.ImageData.SetImage("yourCompressedImage");
}
}
doc.Save("Output.pdf");
using Aspose.Words;
var doc = new Document("Input.pdf");
doc.Cleanup();
var nodes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in nodes)
{
if (shape.IsImage)
{
// Iku nganti pangembang kanggo milih perpustakaan kanggo komprèsi gambar.
using var image = Image.FromStream(shape.ImageData.ToStream());
// ...
// Compress gambar lan nyetel maneh menyang wangun.
shape.ImageData.SetImage("yourCompressedImage");
}
}
var saveOptions = new OoxmlSaveOptions
{
CompressionLevel = CompressionLevel.Maximum
};
doc.Save("Output.pdf", saveOptions);
using Aspose.Words;
var doc = new Document();
var builder = new DocumentBuilder(doc);
var shape = builder.InsertImage("Input.pdf");
var saveOptions = new ImageSaveOptions(SaveFormat.Pdf)
{
};
shape.GetShapeRenderer().Save("Output.pdf", saveOptions);
using Aspose.Words;
using Aspose.Words.Pdf2Word.FixedFormats;
using var pdfStream = File.OpenRead("Input.pdf");
var renderer = new PdfFixedRenderer();
var pdfReadOptions = new PdfFixedOptions
{
ImageFormat = FixedImageFormat.Jpeg,
JpegQuality = 50
};
const double maxPageDimension = 1584;
var pagesStream = renderer.SavePdfAsImages(pdfStream, pdfReadOptions);
var builder = new DocumentBuilder();
for (var i = 0; i < pagesStream.Count; ++i)
{
// Setel ukuran kaca maksimal kanggo ngindhari skala gambar kaca saiki.
var pageSetup = builder.PageSetup;
SetPageSize(pageSetup, maxPageDimension, maxPageDimension);
var pageImage = builder.InsertImage(pagesStream[i]);
SetPageSize(pageSetup, pageImage.Width, pageImage.Height);
pageSetup.TopMargin = 0;
pageSetup.LeftMargin = 0;
pageSetup.BottomMargin = 0;
pageSetup.RightMargin = 0;
if (i != pagesStream.Count - 1)
builder.InsertBreak(BreakType.SectionBreakNewPage);
}
var saveOptions = new PdfSaveOptions
{
CacheBackgroundGraphics = true
};
builder.Document.Save("Output.pdf", saveOptions);
private void SetPageSize(PageSetup pageSetup, double width, double height)
{
pageSetup.PageWidth = width;
pageSetup.PageHeight = height;
}
Ana telung pilihan alternatif kanggo nginstal "Aspose.Words kanggo .NET" sistem sampeyan. Pilih salah siji sing cocog karo kabutuhan sampeyan lan tindakake pandhuan langkah demi langkah:
Produk kita kanthi lintas-platform lan ndhukung kabeh implementasi .NET utama:
Nganti kode .NET ora gumantung ing hardware utawa sistem operasi sing ndasari, nanging mung ing Mesin Virtual, sampeyan bebas ngembangake piranti lunak apa wae kanggo Windows, macOS, Android, iOS lan Linux. Priksa manawa sampeyan wis nginstal versi .NET Framework, .NET Core, Windows Azure, Mono utawa Xamarin sing cocog.
Disaranake nggunakake Microsoft Visual Studio, Xamarin, lan lingkungan pangembangan terintegrasi MonoDevelop kanggo nggawe aplikasi C#, F#, VB.NET.
Kanggo rincian liyane, waca Dokumentasi Produk.
Sampeyan bisa ngoptimalake file ing akeh format file liyane: