private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { DecomposeData argumentDecompose = e.Argument as DecomposeData; List <String> listFileNames = new List <string>(); DecomposeResults decomposeResults = new DecomposeResults(); decomposeResults.notCancelled = true; decomposeResults.filePathsPdf = argumentDecompose.filePathsPdf; int filesCount = argumentDecompose.filePathsPdf.Count; for (int i = 0; i < filesCount; i++) { if (backgroundWorker1.CancellationPending == true) { decomposeResults.notCancelled = false; break; } else { String fileName = argumentDecompose.filePathsPdf[i]; String fileNameTiff = fileName + ".tiff"; // create tiff ConvertPDFToTIFF(fileName, textBox_destFolder.Text, fileNameTiff); listFileNames.Add(fileNameTiff); backgroundWorker1.ReportProgress((i + 1) * 100 / filesCount); } } decomposeResults.filePathsTiff = listFileNames; e.Result = decomposeResults; }
private void StartThread() { List <String> filePaths = new List <string>(); // create one-page pdfs first iTextSharp.text.pdf.PdfReader reader = null; int currentPage = 1; int pageCount = 0; String filepath = textBox_file.Text; System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); reader = new iTextSharp.text.pdf.PdfReader(filepath); reader.RemoveUnusedObjects(); pageCount = reader.NumberOfPages; string ext = System.IO.Path.GetExtension(filepath); for (int i = 1; i <= pageCount; i++) { iTextSharp.text.pdf.PdfReader reader1 = new iTextSharp.text.pdf.PdfReader(filepath); string outfile = filepath.Replace((System.IO.Path.GetFileName(filepath)), (System.IO.Path.GetFileName(filepath).Replace(".pdf", "") + "_" + i.ToString()) + ext); reader1.RemoveUnusedObjects(); iTextSharp.text.Document doc = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(currentPage)); iTextSharp.text.pdf.PdfCopy pdfCpy = new iTextSharp.text.pdf.PdfCopy(doc, new System.IO.FileStream(outfile, System.IO.FileMode.Create)); doc.Open(); for (int j = 1; j <= 1; j++) { iTextSharp.text.pdf.PdfImportedPage page = pdfCpy.GetImportedPage(reader1, currentPage); pdfCpy.AddPage(page); currentPage += 1; } doc.Close(); pdfCpy.Close(); reader1.Close(); reader.Close(); filePaths.Add(outfile); } DecomposeData decompose = new DecomposeData { filePathsPdf = filePaths, folder = textBox_destFolder.Text }; backgroundWorker1.RunWorkerAsync(decompose); label_status.Text = localization.GetValueForItem(LocalizedItem.TextSearchStarted).Replace("%i", filePaths.Count.ToString()); label_status.ForeColor = Color.Blue; }