public void SplitByPageRanges(string pageRanges) { int num; int num1; int num2; int num3; if (this.CheckOutput()) { PDFHelper.DisplayTrialPopupIfNecessary(); try { string[] strArrays = pageRanges.Split(new char[] { ',' }); List list = IteratorUtils.toList(this.pdfDocument.PDFBoxDocument.getPages().iterator()); int num4 = list.size(); string[] strArrays1 = strArrays; for (int i = 0; i < (int)strArrays1.Length; i++) { string str = strArrays1[i]; if (this.ConfigureRange(str, num4, out num, out num1, out num2, out num3)) { List list1 = list.subList(num, num1); PDDocument pDDocument = new PDDocument(); for (int j = num2; j < list1.size(); j = j + num3) { PDPage pDPage = (PDPage)list1.@get(j); pDPage.getResources(); pDDocument.addPage(pDPage); } pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument); string str1 = string.Format("{0} [{1}].pdf", this.OutputFileName, str); pDDocument.save(Path.Combine(this.OutputFilePath, str1)); } else { Console.WriteLine("Invalid range: {0}", str); } } } catch (Exception exception1) { Exception exception = exception1; throw new PDFToolkitException(exception.Message, exception.InnerException); } } }
public void ExtractImages(string outputFolder, string prefix, bool addKey, int pageNumber) { PDFHelper.DisplayTrialPopupIfNecessary(); try { this.CheckOutputFolder(outputFolder); if (pageNumber > this.pdfDocument.getNumberOfPages()) { Console.WriteLine("Invalid page number."); } else { PDPage page = this.pdfDocument.getPage(pageNumber - 1); this.ProcessResources(page.getResources(), prefix, addKey); } } catch (Exception exception1) { Exception exception = exception1; throw new PDFToolkitException(exception.Message, exception); } }
public static void ConvertToDoc(string pdfFilePath, string tempDir) { var pdfHeader = System.IO.Path.GetFileName(pdfFilePath); var underscoreIndex = pdfHeader.IndexOf('_'); pdfHeader = pdfHeader.Remove(0, underscoreIndex + 1); WordEx.AddTitle(pdfHeader); _pdfDoc = new PDDocument(); try { _pdfDoc = PDDocument.load(pdfFilePath); } catch { MessageBox.Show("Cant load pdf, try re-downloading:" + Environment.NewLine + pdfFilePath, "PDF Error"); return; } var pagelist = _pdfDoc.getDocumentCatalog().getAllPages(); for (int x = 0; x < pagelist.size(); x++) { //string pageTxt = GetPageText(x); //PDFPage pdfPage = GetPageHeader(pageTxt); //WordEx.AddHeader(pdfPage.Header); PDPage page = (PDPage)pagelist.get(x); PDResources pdResources = page.getResources(); Map pageImages = pdResources.getImages(); if (pageImages != null) { Iterator imageIter = pageImages.keySet().iterator(); while (imageIter.hasNext()) { String key = (String)imageIter.next(); PDXObjectImage pdxObjectImage = (PDXObjectImage)pageImages.get(key); var buffImage = pdxObjectImage.getRGBImage(); Bitmap theImage = buffImage.getBitmap(); if (!ContainsDocImage(theImage)) { //WordEx.AddImage(theImage, pdfPage.Header, pdfHeader); WordEx.AddImage(theImage, pdfHeader, pdfHeader); } else { theImage.Dispose(); } } } } string docText = _stripper.getText(_pdfDoc); WordEx.AddText(docText); foreach (Bitmap btmap in _docImages) { btmap.Dispose(); } _docImages.Clear(); _pdfDoc.close(); _pdfDoc = null; }