static void Main(string[] args)
{
List<Thread> threads = new List<Thread>();
for (int i = 0; i < 15; i++)
{
string result = String.Format("Result{0}.pdf",i);
Thread thread = new Thread(() =>
{
HtmlToPDF(result);
});
threads.Add(thread);
}
threads.ForEach(t => t.Start());
threads.ForEach(t => t.Join());
}
static void HtmlToPDF(string result)
{
PdfDocument doc = new PdfDocument();
String html = File.ReadAllText("testEmailPdf.html");
PdfHtmlLayoutFormat format = new PdfHtmlLayoutFormat { IsWaiting = true };
PdfPageSettings setting = new PdfPageSettings { Size = PdfPageSize.A4 };
doc.Security.KeySize = Spire.Pdf.Security.PdfEncryptionKeySize.Key128Bit;
doc.Security.OwnerPassword = "$123456$";
doc.Security.UserPassword = "test";
doc.Security.Permissions = Spire.Pdf.Security.PdfPermissionsFlags.Print | Spire.Pdf.Security.PdfPermissionsFlags.FillFields;
Thread thread = new Thread(() =>
{ doc.LoadFromHTML(html, false, setting, format); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
doc.SaveToFile(result);
}
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.pdf");
foreach (PdfPageBase page in pdf.Pages)
{
Image[] images = page.ExtractImages();
if (images != null && images.Length > 0)
{
for (int j = 0; j<images.Length; j++)
{
Image image = images[j];
PdfBitmap bp = new PdfBitmap(image);
bp.Quality = 20;
page.ReplaceImage(j, bp);
}
}
}
pdf.SaveToFile("Result.pdf");