示例#1
0
        public PDFPermission ReadPDFSecurity(PDFDocument sourcePDF)
        {
            PDFPermission pDFPermission;

            PDFHelper.DisplayTrialPopupIfNecessary();
            try
            {
                PDFPermission    pDFPermission1          = null;
                AccessPermission currentAccessPermission = sourcePDF.PDFBoxDocument.getCurrentAccessPermission();
                if (currentAccessPermission != null)
                {
                    pDFPermission1 = new PDFPermission()
                    {
                        AllowAssembly                = currentAccessPermission.canAssembleDocument(),
                        AllowDegradedPrinting        = currentAccessPermission.canPrintDegraded(),
                        AllowExtractContents         = currentAccessPermission.canExtractContent(),
                        AllowExtractForAccessibility = currentAccessPermission.canExtractForAccessibility(),
                        AllowFillInForm              = currentAccessPermission.canFillInForm(),
                        AllowModifyAnnotations       = currentAccessPermission.canModifyAnnotations(),
                        AllowModifyContents          = currentAccessPermission.canModifyAnnotations(),
                        AllowPrinting                = currentAccessPermission.canPrint()
                    };
                }
                pDFPermission = pDFPermission1;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                throw new PDFToolkitException(exception.Message, exception);
            }
            return(pDFPermission);
        }
示例#2
0
 public void MergePDFs(List <string> sourcePDFs, string outputFile)
 {
     PDFHelper.DisplayTrialPopupIfNecessary();
     foreach (string sourcePDF in sourcePDFs)
     {
         this.mergeUtility.addSource(sourcePDF);
     }
     if (!PDFHelper.AddStamp)
     {
         this.mergeUtility.setDestinationFileName(outputFile);
         this.mergeUtility.mergeDocuments();
     }
     else
     {
         string str = Path.Combine(Path.GetTempPath(), string.Concat(Path.GetRandomFileName(), ".pdf"));
         this.mergeUtility.setDestinationFileName(str);
         this.mergeUtility.mergeDocuments();
         PDDocument pDDocument = PDDocument.load(new java.io.File(str));
         pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument);
         pDDocument.save(outputFile);
         if (pDDocument != null)
         {
             pDDocument.close();
         }
         if (System.IO.File.Exists(str))
         {
             System.IO.File.Delete(str);
         }
     }
 }
示例#3
0
 public void SaveOpenSettings(string outputFile)
 {
     PDFHelper.DisplayTrialPopupIfNecessary();
     PDFHelper.AddTrialStampIfNecessary(this.pdfDocument.PDFBoxDocument, false);
     this.documentDocumentOpenSettings.setViewerPreferences(this.documentViewerPrefernces);
     this.pdfDocument.PDFBoxDocument.save(outputFile);
 }
示例#4
0
        private void ParseCSV()
        {
            TextFieldParser textFieldParser = new TextFieldParser(this.csvFile)
            {
                TextFieldType = FieldType.Delimited
            };

            textFieldParser.SetDelimiters(new string[] { this.delimiter });
            while (!textFieldParser.EndOfData)
            {
                List <string> list = textFieldParser.ReadFields().ToList <string>();
                this.contents.Add(list);
            }
            textFieldParser.Close();
            try
            {
                PDFHelper.DisplayTrialPopupIfNecessary();
                this.DrawTable();
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                throw new PDFToolkitException(exception.Message, exception.InnerException);
            }
        }
示例#5
0
 private void Split(int start, int end, int repeatEvery)
 {
     if (this.CheckOutput())
     {
         PDFHelper.DisplayTrialPopupIfNecessary();
         try
         {
             Splitter splitter = new Splitter();
             splitter.setStartPage(start);
             splitter.setEndPage(end);
             splitter.setSplitAtPage(repeatEvery);
             List list = splitter.split(this.pdfDocument.PDFBoxDocument);
             for (int i = 0; i < list.size(); i++)
             {
                 PDDocument pDDocument = PDFHelper.AddTrialStampIfNecessary((PDDocument)list.@get(i));
                 string     str        = string.Format("{0} [{1}].pdf", this.OutputFileName, i);
                 pDDocument.save(Path.Combine(this.OutputFilePath, str));
             }
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             throw new PDFToolkitException(exception.Message, exception.InnerException);
         }
     }
 }
示例#6
0
文件: PDFHocr.cs 项目: jehan2898/root
        internal static bool CreateHocrFileFromPDF(PDDocument document, string outputfile, bool useWords)
        {
            bool flag;

            try
            {
                PDFHocr pDFHocr = new PDFHocr()
                {
                    getHOCRByWords = useWords
                };
                pDFHocr.setSortByPosition(true);
                pDFHocr.setStartPage(0);
                pDFHocr.setEndPage(document.getNumberOfPages());
                PDFHelper.DisplayTrialPopupIfNecessary();
                if (PDFHelper.AddStamp)
                {
                    pDFHocr.setEndPage(3);
                }
                pDFHocr.writeText(document, new OutputStreamWriter(new ByteArrayOutputStream()));
                if ((pDFHocr.lineList == null ? false : pDFHocr.lineList.Count > 0))
                {
                    HocrPageModel hocrPageModel = new HocrPageModel();
                    hocrPageModel.Lines.AddRange(pDFHocr.SortLineList(pDFHocr.lineList));
                    pDFHocr.pageList.Add(hocrPageModel);
                    pDFHocr.lineList.Clear();
                }
                pDFHocr.GetHocrFromPageList(pDFHocr.pageList, outputfile);
                flag = true;
            }
            catch (Exception exception)
            {
                flag = false;
            }
            return(flag);
        }
示例#7
0
文件: PDFHocr.cs 项目: jehan2898/root
        internal static List <HocrPageModel> GetPageWordDetails(PDDocument document)
        {
            List <HocrPageModel> hocrPageModels;

            try
            {
                PDFHocr pDFHocr = new PDFHocr();
                pDFHocr.setSortByPosition(true);
                pDFHocr.setStartPage(0);
                pDFHocr.setEndPage(document.getNumberOfPages());
                Writer outputStreamWriter = new OutputStreamWriter(new ByteArrayOutputStream());
                PDFHelper.DisplayTrialPopupIfNecessary();
                if (PDFHelper.AddStamp)
                {
                    pDFHocr.setEndPage(3);
                }
                pDFHocr.writeText(document, outputStreamWriter);
                if ((pDFHocr.lineList == null ? false : pDFHocr.lineList.Count > 0))
                {
                    HocrPageModel hocrPageModel = new HocrPageModel();
                    hocrPageModel.Lines.AddRange(pDFHocr.SortLineList(pDFHocr.lineList));
                    pDFHocr.pageList.Add(hocrPageModel);
                    pDFHocr.lineList.Clear();
                }
                hocrPageModels = pDFHocr.pageList;
            }
            catch (Exception exception)
            {
                hocrPageModels = null;
            }
            return(hocrPageModels);
        }
示例#8
0
 public void SplitByRepeatingPageRanges(string pageRange, int repeatEvery)
 {
     if (this.CheckOutput())
     {
         PDFHelper.DisplayTrialPopupIfNecessary();
         try
         {
             if (pageRange.Contains <char>('-'))
             {
                 string str = "";
                 if (pageRange.ToLower().Contains("odd"))
                 {
                     str = "odd";
                 }
                 else if (pageRange.ToLower().Contains("even"))
                 {
                     str = "even";
                 }
                 PDPageTree pages = this.pdfDocument.PDFBoxDocument.getPages();
                 int        count = pages.getCount();
                 this.splitCounter = 0;
                 this.SplitByRepeatingPageRanges(pageRange, repeatEvery, pages, count, str);
             }
             else
             {
                 Console.WriteLine("Invalid page range.");
             }
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             throw new PDFToolkitException(exception.Message, exception);
         }
     }
 }
示例#9
0
        internal string GetText(PDDocument pdfDocument, int pageNumber, bool format)
        {
            string text;
            double num;
            string str = "";

            if (format)
            {
                try
                {
                    PDFHelper.DisplayTrialPopupIfNecessary();
                    PDFTextStripperByArea pDFTextStripperByArea = new PDFTextStripperByArea();
                    pDFTextStripperByArea.setSortByPosition(true);
                    if (PDFHelper.AddStamp)
                    {
                        str = string.Concat(str, "You are using a trial license of PDF Toolkit, as a result only the first three pages would be extracted.");
                    }
                    PDPage      page     = pdfDocument.getPage(pageNumber - 1);
                    PDRectangle cropBox  = page.getCropBox();
                    int         rotation = page.getRotation();
                    if (cropBox == null)
                    {
                        cropBox = page.getMediaBox();
                    }
                    int num1 = 0;
                    int num2 = 0;
                    if (rotation % 180 != 0)
                    {
                        num  = Math.Round((double)cropBox.getWidth());
                        num1 = int.Parse(num.ToString());
                        num  = Math.Round((double)cropBox.getHeight());
                        num2 = int.Parse(num.ToString());
                    }
                    else
                    {
                        num  = Math.Round((double)cropBox.getHeight());
                        num1 = int.Parse(num.ToString());
                        num  = Math.Round((double)cropBox.getWidth());
                        num2 = int.Parse(num.ToString());
                    }
                    pDFTextStripperByArea.addRegion("class1", new java.awt.Rectangle(0, 0, num2, num1));
                    pDFTextStripperByArea.extractRegions(page);
                    str = string.Concat(str, pDFTextStripperByArea.getTextForRegion("class1"));
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    throw new PDFToolkitException(exception.Message, exception.InnerException);
                }
                text = str;
            }
            else
            {
                text = this.GetText(pdfDocument, pageNumber);
            }
            return(text);
        }
示例#10
0
 public void MergeEachFolderInFolderTree(string sourceFolder, string outputFolder)
 {
     if (this.DirectoryExists(sourceFolder))
     {
         if (this.CreateDirectory(outputFolder))
         {
             this.outputFolder = outputFolder;
             DirectoryInfo directoryInfo = new DirectoryInfo(sourceFolder);
             PDFHelper.DisplayTrialPopupIfNecessary();
             this.GetSubFolders(directoryInfo);
         }
     }
 }
示例#11
0
 public void SplitByTopLevelBookmarks()
 {
     if (this.CheckOutput())
     {
         PDFHelper.DisplayTrialPopupIfNecessary();
         try
         {
             PDDocumentCatalog documentCatalog = this.pdfDocument.PDFBoxDocument.getDocumentCatalog();
             PDDocumentOutline documentOutline = documentCatalog.getDocumentOutline();
             if (documentOutline != null)
             {
                 PDOutlineItem firstChild = documentOutline.getFirstChild();
                 PDPageTree    pages      = documentCatalog.getPages();
                 List <int>    nums       = new List <int>();
                 while (firstChild != null)
                 {
                     PDPage pDPage = firstChild.findDestinationPage(this.pdfDocument.PDFBoxDocument);
                     nums.Add(pages.indexOf(pDPage));
                     firstChild = firstChild.getNextSibling();
                 }
                 nums.Add(pages.getCount());
                 for (int i = 0; i < nums.Count - 1; i++)
                 {
                     int        item       = nums[i];
                     int        num        = nums[i + 1];
                     PDDocument pDDocument = new PDDocument();
                     for (int j = item; j < num; j++)
                     {
                         pDDocument.addPage(this.pdfDocument.PDFBoxDocument.getPage(j));
                     }
                     pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument);
                     string str = string.Format("{0} [{1}].pdf", this.OutputFileName, i);
                     pDDocument.save(Path.Combine(this.OutputFilePath, str));
                     pDDocument.close();
                 }
             }
             else
             {
                 Console.WriteLine("This document does not contain any bookmarks.");
             }
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             throw new PDFToolkitException(exception.Message, exception.InnerException);
         }
     }
 }
示例#12
0
 public void Save(string output)
 {
     PDFHelper.DisplayTrialPopupIfNecessary();
     if (PDFHelper.AddStamp)
     {
         this.pdfDocument = PDFHelper.AddTrialStampIfNecessary(this.pdfDocument);
     }
     try
     {
         this.pdfDocument.save(output);
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         throw new PDFToolkitException(exception.Message, exception);
     }
 }
示例#13
0
        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);
                }
            }
        }
示例#14
0
 private void Save()
 {
     PDFHelper.DisplayTrialPopupIfNecessary();
     if (PDFHelper.AddStamp)
     {
         this.pdfFile = PDFHelper.AddTrialStampIfNecessary(this.pdfFile);
     }
     try
     {
         this.pdfFile.save(this.outputFile);
         this.pdfFile.close();
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         throw new PDFToolkitException(exception.Message, exception.InnerException);
     }
 }
示例#15
0
        public string GetXMPMetadata()
        {
            string     str      = "";
            PDMetadata metadata = this.pdfDocument.getDocumentCatalog().getMetadata();

            if (metadata != null)
            {
                try
                {
                    PDFHelper.DisplayTrialPopupIfNecessary();
                    str = PDFHelper.convertStreamToString(metadata.exportXMPMetadata());
                }
                catch (java.io.IOException oException)
                {
                    throw new System.IO.IOException(oException.getMessage());
                }
            }
            return(str);
        }
示例#16
0
        public string GetText(PDDocument pdfDocument)
        {
            PDFHelper.DisplayTrialPopupIfNecessary();
            string str = "";

            try
            {
                PDFTextStripper pDFTextStripper = new PDFTextStripper();
                if (PDFHelper.AddStamp)
                {
                    str = string.Concat(str, "You are using a trial license of PDF Toolkit, as a result only the first three pages would be extracted.");
                    pDFTextStripper.setEndPage(3);
                }
                str = string.Concat(str, pDFTextStripper.getText(pdfDocument));
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                throw new PDFToolkitException(exception.Message, exception.InnerException);
            }
            return(str);
        }
示例#17
0
 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);
     }
 }
示例#18
0
 public void ExtractImages(string outputFolder, string prefix, bool addKey)
 {
     PDFHelper.DisplayTrialPopupIfNecessary();
     try
     {
         this.CheckOutputFolder(outputFolder);
         foreach (PDPage page in this.pdfDocument.getPages())
         {
             try
             {
                 this.ProcessResources(page.getResources(), prefix, addKey);
             }
             catch (Exception exception)
             {
             }
         }
     }
     catch (Exception exception2)
     {
         Exception exception1 = exception2;
         throw new PDFToolkitException(exception1.Message, exception1);
     }
 }
示例#19
0
        public void ApplyOverlay(string outputFile)
        {
            PDFHelper.DisplayTrialPopupIfNecessary();
            Map     hashMap = new HashMap();
            Overlay overlay = new Overlay();

            overlay.setInputPDF(this.overlayDestination.PDFBoxDocument);
            overlay.setAllPagesOverlayPDF(this.overlay.PDFBoxDocument);
            overlay.setOverlayPosition(Overlay.Position.FOREGROUND);
            PDDocument pDDocument = overlay.overlay(hashMap);

            if (!PDFHelper.AddStamp)
            {
                pDDocument.save(outputFile);
            }
            else
            {
                pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument);
                pDDocument.save(outputFile);
            }
            pDDocument.close();
            overlay.close();
        }
示例#20
0
 public void SecurePDF(PDFDocument sourcePDF, string outputFile)
 {
     PDFHelper.DisplayTrialPopupIfNecessary();
     try
     {
         AccessPermission accessPermission = new AccessPermission();
         accessPermission.setCanAssembleDocument(this.Permission.AllowAssembly);
         accessPermission.setCanExtractContent(this.Permission.AllowExtractContents);
         accessPermission.setCanExtractForAccessibility(this.Permission.AllowExtractForAccessibility);
         accessPermission.setCanFillInForm(this.Permission.AllowFillInForm);
         accessPermission.setCanModify(this.Permission.AllowModifyContents);
         accessPermission.setCanModifyAnnotations(this.Permission.AllowModifyAnnotations);
         accessPermission.setCanPrint(this.Permission.AllowPrinting);
         accessPermission.setCanPrintDegraded(this.Permission.AllowDegradedPrinting);
         StandardProtectionPolicy standardProtectionPolicy = new StandardProtectionPolicy(this.OwnerPassword, this.UserPassword, accessPermission);
         if (!PDFHelper.AddStamp)
         {
             sourcePDF.PDFBoxDocument.protect(standardProtectionPolicy);
             sourcePDF.PDFBoxDocument.save(outputFile);
             sourcePDF.PDFBoxDocument.close();
         }
         else
         {
             PDDocument pDFBoxDocument = sourcePDF.PDFBoxDocument;
             pDFBoxDocument = PDFHelper.AddTrialStampIfNecessary(pDFBoxDocument);
             pDFBoxDocument.protect(standardProtectionPolicy);
             pDFBoxDocument.save(outputFile);
             pDFBoxDocument.close();
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         throw new PDFToolkitException(exception.Message, exception);
     }
 }
示例#21
0
        internal string GetTextByArea(PDDocument pdfDocument, double X, double Y, double width, double height, int pageNumber)
        {
            string empty;

            try
            {
                PDFHelper.DisplayTrialPopupIfNecessary();
                string str = string.Empty;
                if (PDFHelper.AddStamp)
                {
                    str = string.Concat(str, "You are using a trial license of PDF Toolkit, as a result only the first three pages would be extracted.");
                }
                if ((width <= 0 ? true : height <= 0))
                {
                    Console.WriteLine("Sorry the length and width you provided are not greater than zero, no text will be extracted.");
                    str = string.Empty;
                }
                else
                {
                    PDPage                page = pdfDocument.getPage(pageNumber - 1);
                    string                str1 = "region";
                    Rectangle2D           num  = new Rectangle2D.Double(X, Y, width, height);
                    PDFTextStripperByArea pDFTextStripperByArea = new PDFTextStripperByArea();
                    pDFTextStripperByArea.addRegion(str1, num);
                    pDFTextStripperByArea.extractRegions(page);
                    str = string.Concat(str, pDFTextStripperByArea.getTextForRegion(str1).Replace("\r", string.Empty).Replace("\n", string.Empty));
                }
                empty = str;
            }
            catch (Exception exception)
            {
                Console.WriteLine("Sorry an exception occured when the text was being extracted\n{0}", exception.Message);
                empty = string.Empty;
            }
            return(empty);
        }
示例#22
0
        public void MergeFolderOfPDFs(string sourceFolder, string outputFile, bool processSubFolders)
        {
            FileInfo[] fileInfoArray;
            PDFHelper.DisplayTrialPopupIfNecessary();
            DirectoryInfo directoryInfo = new DirectoryInfo(sourceFolder);

            fileInfoArray = (!processSubFolders ? directoryInfo.GetFiles("*.pdf") : directoryInfo.GetFiles("*.pdf", SearchOption.AllDirectories));
            FileInfo[] fileInfoArray1 = fileInfoArray;
            for (int i = 0; i < (int)fileInfoArray1.Length; i++)
            {
                FileInfo fileInfo = fileInfoArray1[i];
                this.mergeUtility.addSource(fileInfo.FullName);
            }
            if (!PDFHelper.AddStamp)
            {
                this.mergeUtility.setDestinationFileName(outputFile);
                this.mergeUtility.mergeDocuments();
            }
            else
            {
                string str = Path.Combine(Path.GetTempPath(), string.Concat("aquaforest\\pdftoolkit\\", Path.GetRandomFileName(), ".pdf"));
                this.mergeUtility.setDestinationFileName(str);
                this.mergeUtility.mergeDocuments();
                PDDocument pDDocument = PDDocument.load(new java.io.File(str));
                pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument);
                pDDocument.save(outputFile);
                if (pDDocument != null)
                {
                    pDDocument.close();
                }
                if (System.IO.File.Exists(str))
                {
                    System.IO.File.Delete(str);
                }
            }
        }
示例#23
0
        internal void createPDFFromText(string pdfFile)
        {
            string     str;
            bool       flag;
            PDDocument pDDocument = new PDDocument();

            PDFHelper.DisplayTrialPopupIfNecessary();
            PDFHelper.CheckOutputFolder(Path.GetDirectoryName(pdfFile));
            try
            {
                this.pdfFileName = pdfFile;
                Reader fileReader = new FileReader(this.textFile);
                int    num        = 40;
                if (this.font == null)
                {
                    this.font = PDFType1Font.TIMES_ROMAN;
                }
                float       height = this.font.PDFBoxFont.getBoundingBox().getHeight() / 1000f;
                PDRectangle lETTER = PDRectangle.LETTER;
                if (this.isLandescape)
                {
                    lETTER = new PDRectangle(lETTER.getHeight(), lETTER.getWidth());
                }
                height = height * this.fontSize * 1.05f;
                string[]            strArrays           = System.IO.File.ReadAllLines(this.textFile);
                PDPage              pDPage              = new PDPage(lETTER);
                PDPageContentStream pDPageContentStream = null;
                float    single     = -1f;
                float    width      = pDPage.getMediaBox().getWidth() - (float)(2 * num);
                bool     flag1      = true;
                string[] strArrays1 = strArrays;
                for (int i = 0; i < (int)strArrays1.Length; i++)
                {
                    string str1 = strArrays1[i];
                    flag1 = false;
                    string   str2       = Regex.Replace(str1, "\\t|\\n|\\r", "");
                    string[] strArrays2 = str2.Replace("[\\n\\r]+$", "").Split(new char[] { ' ' });
                    int      num1       = 0;
                    while (num1 < (int)strArrays2.Length)
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        float         stringWidth   = 0f;
                        bool          flag2         = false;
                        do
                        {
                            string str3 = "";
                            int    num2 = strArrays2[num1].IndexOf('\f');
                            if (num2 != -1)
                            {
                                flag2 = true;
                                str   = strArrays2[num1].Substring(0, num2);
                                if (num2 < strArrays2[num1].Length)
                                {
                                    str3 = strArrays2[num1].Substring(num2 + 1);
                                }
                            }
                            else
                            {
                                str = strArrays2[num1];
                            }
                            if ((str.Length > 0 ? true : !flag2))
                            {
                                stringBuilder.Append(str);
                                stringBuilder.Append(" ");
                            }
                            if ((!flag2 ? false : str3.Length != 0))
                            {
                                strArrays2[num1] = str3;
                            }
                            else
                            {
                                num1++;
                            }
                            if (!flag2)
                            {
                                if (num1 < (int)strArrays2.Length)
                                {
                                    string str4 = strArrays2[num1];
                                    num2 = str4.IndexOf('\f');
                                    if (num2 != -1)
                                    {
                                        str4 = str4.Substring(0, num2);
                                    }
                                    string str5 = string.Concat(stringBuilder.ToString(), " ", str4);
                                    try
                                    {
                                        stringWidth = this.font.PDFBoxFont.getStringWidth(str5) / 1000f * this.fontSize;
                                    }
                                    catch (Exception exception)
                                    {
                                    }
                                }
                                flag = (num1 >= (int)strArrays2.Length ? false : stringWidth < width);
                            }
                            else
                            {
                                break;
                            }
                        }while (flag);
                        if (single < (float)num)
                        {
                            pDPage = new PDPage(lETTER);
                            pDDocument.addPage(pDPage);
                            if (pDPageContentStream != null)
                            {
                                pDPageContentStream.endText();
                                pDPageContentStream.close();
                            }
                            pDPageContentStream = new PDPageContentStream(pDDocument, pDPage);
                            pDPageContentStream.setFont(this.font.PDFBoxFont, this.fontSize);
                            pDPageContentStream.beginText();
                            single = pDPage.getMediaBox().getHeight() - (float)num + height;
                            pDPageContentStream.newLineAtOffset((float)num, single);
                        }
                        if (pDPageContentStream == null)
                        {
                            throw new java.io.IOException("Error:Expected non-null content stream.");
                        }
                        pDPageContentStream.newLineAtOffset(0f, -height);
                        single = single - height;
                        try
                        {
                            pDPageContentStream.showText(stringBuilder.ToString());
                            if (flag2)
                            {
                                pDPage = new PDPage(lETTER);
                                pDDocument.addPage(pDPage);
                                pDPageContentStream.endText();
                                pDPageContentStream.close();
                                pDPageContentStream = new PDPageContentStream(pDDocument, pDPage);
                                pDPageContentStream.setFont(this.font.PDFBoxFont, this.fontSize);
                                pDPageContentStream.beginText();
                                single = pDPage.getMediaBox().getHeight() - (float)num + height;
                                pDPageContentStream.newLineAtOffset((float)num, single);
                            }
                        }
                        catch (Exception exception1)
                        {
                        }
                    }
                }
                if (flag1)
                {
                    pDDocument.addPage(pDPage);
                }
                if (pDPageContentStream != null)
                {
                    pDPageContentStream.endText();
                    pDPageContentStream.close();
                }
                if (PDFHelper.AddStamp)
                {
                    pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument);
                }
                try
                {
                    pDDocument.save(pdfFile);
                }
                catch (Exception exception3)
                {
                    Exception exception2 = exception3;
                    throw new PDFToolkitException(exception2.Message, exception2.InnerException);
                }
            }
            catch (Exception exception5)
            {
                Exception exception4 = exception5;
                if (pDDocument != null)
                {
                    pDDocument.close();
                }
                throw exception4;
            }
        }
示例#24
0
        public PDFAValidationResult ConvertToPDFA()
        {
            PDFAValidationResult pDFAValidationResult = new PDFAValidationResult();

            try
            {
                try
                {
                    bool flag = true;
                    this.CheckImages();
                    pDFAValidationResult.IsValid = false;
                    this.EmbedFonts(flag);
                    this.doc.save(this.tempFileName);
                    PDDocumentCatalog documentCatalog = this.doc.getDocumentCatalog();
                    try
                    {
                        if (documentCatalog.getOutputIntents().size() <= 0)
                        {
                            this.colorProfile = new FileInputStream(this.iccString);
                            PDOutputIntent pDOutputIntent = new PDOutputIntent(this.doc, this.colorProfile);
                            pDOutputIntent.setInfo("sRGB IEC61966-2.1");
                            pDOutputIntent.setOutputCondition("sRGB IEC61966-2.1");
                            pDOutputIntent.setOutputConditionIdentifier("sRGB IEC61966-2.1");
                            pDOutputIntent.setRegistryName("http://www.color.org");
                            documentCatalog.addOutputIntent(pDOutputIntent);
                            this.doc.save(this.tempFileName);
                        }
                    }
                    catch (Exception exception)
                    {
                    }
                    PDFHelper.DisplayTrialPopupIfNecessary();
                    PDFHelper.AddTrialStampIfNecessary(this.doc, false);
                    this.DoMetadata();
                    if (!this.ValidatePDF)
                    {
                        Console.WriteLine("The file was convereted but it has not been validated, to validate pdfa files after conversion set the ValidatePDF porperty to true.");
                        System.IO.File.Copy(this.tempFileName, this.outPutFileName, this.overwrite);
                    }
                    else
                    {
                        PDFAValidationResult pDFAValidationResult1 = (new PDFAValidator()).ValidatePDFA(this.tempFileName, (AquaforestPDFAFlavour)this.PDFAFlavour);
                        pDFAValidationResult.IsValid          = pDFAValidationResult1.IsValid;
                        pDFAValidationResult.ValidationResult = pDFAValidationResult1.ValidationResult;
                        if ((pDFAValidationResult.IsValid ? false : !this.copyUnvalidated))
                        {
                            Console.WriteLine("The file was convereted but failed during validation. If you want to copy this to the output file set CopyUnvalidated to true");
                        }
                        else
                        {
                            System.IO.File.Copy(this.tempFileName, this.outPutFileName, this.overwrite);
                        }
                    }
                }
                catch (Exception exception1)
                {
                    Console.WriteLine("The attempted pdf/a conversion failed.\n{0}", exception1.Message);
                    PDF2PDFaConverter.EmptyDirectory(Path.GetDirectoryName(this.tempFileName));
                    Directory.Delete(Path.GetDirectoryName(this.tempFileName));
                }
            }
            finally
            {
                if (this.doc != null)
                {
                    this.doc.close();
                    this.doc = null;
                }
                try
                {
                    PDF2PDFaConverter.EmptyDirectory(Path.GetDirectoryName(this.tempFileName));
                    Directory.Delete(Path.GetDirectoryName(this.tempFileName));
                }
                catch (Exception exception2)
                {
                }
            }
            return(pDFAValidationResult);
        }