static async Task Extract() { //PDFExtractor extractor = new PDFExtractor(@"D:\Desktop\PDFtk\pdftk.exe"); PDFExtractor extractor = new PDFExtractor(); extractor.InputFile = new System.IO.FileInfo(@"D:\Desktop\Debug\Test.pdf"); extractor.OutputPath = new System.IO.DirectoryInfo(@"D:\Desktop\Debug\Output"); extractor.OutputName = "extracted.pdf"; //extractor.ExtractRange(new int[] { 1, 3, 5, 7, 9 }); Console.WriteLine("Start Extracting"); await extractor.ExtractAsync(new int[] { 99 }); //extractor.ExtractRange("1-3 7-end"); Console.WriteLine("Extracting Finished"); }
public async Task ImportAsync(ZebraDBManager manager, FileInfo file, bool _override = false) { bool alreadyExists = false; Sheet existingSheet = null; //Check if Sheet is already in Database foreach (var sheet in Piece.Sheet) { Progress = -1; if (sheet.Part == Part) { //If no overwriting is intended, throw exception if (_override == false) { throw new SheetAlreadyExistsException(sheet); } //If overwriting is intended, set bool to true, so that the sheet does not get created twice in the database alreadyExists = true; existingSheet = sheet; } } this.Progress = 25; if (alreadyExists == false) { //Create database entry (only if sheet does not exists yet) var _newsheet = manager.NewSheet(Piece.PieceID, Part.PartID); this.Progress = 50; //Extract page PDFExtractor extractor = new PDFExtractor() { InputFile = file, OutputName = _newsheet.SheetID.ToString().PadLeft(8, '0'), OutputPath = new DirectoryInfo(manager.ZebraConfig.TempDir) }; foreach (int page in Pages) { extractor.AddPage(page); } this.Progress = 75; try { //Extract the page from the batch await extractor.ExtractAsync(); } catch (Exception) { manager.Context.Remove <Sheet>(_newsheet); Progress = -1; throw; } this.Progress = 75; ProcessFile(manager, _newsheet.SheetID.ToString().PadLeft(8, '0'), _newsheet); this.Progress = 100; IsImported = true; } else if (alreadyExists == true) { this.Progress = 50; //Extract page PDFExtractor extractor = new PDFExtractor() { InputFile = file, OutputName = existingSheet.SheetID.ToString().PadLeft(8, '0'), OutputPath = new DirectoryInfo(manager.ZebraConfig.TempDir) }; this.Progress = 75; try { //Extract the page from the batch await extractor.ExtractAsync(Pages.ToArray()); } catch (Exception) { Progress = -1; throw; } ProcessFile(manager, existingSheet.SheetID.ToString().PadLeft(8, '0'), existingSheet, FileImportMode.Copy, true); this.Progress = 100; IsImported = true; } }