Beispiel #1
0
        public PDF2PDFaConverter(string fileName, string output, string password, AquaforestPDFAFlavour PDFAFlavour)
        {
            try
            {
                int pDFAFlavour = (int)PDFAFlavour;
                this.SetFlavour(pDFAFlavour);
                this.PDFAFlavour    = pDFAFlavour;
                this.outPutFileName = output;
                this.inputFileName  = fileName;
                string tempPath = Path.GetTempPath();
                Guid   guid     = Guid.NewGuid();
                this.tempFileName = Path.Combine(tempPath, string.Concat("aquaforest\\pdftoolkit\\", guid.ToString(), "\\", Path.GetFileName(output)));
                string str           = Path.Combine(Path.GetDirectoryName(this.tempFileName), "password.pdf");
                string directoryName = Path.GetDirectoryName(this.tempFileName);
                if (!Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                }
                System.IO.File.Copy(this.inputFileName, str, true);
                PDDocument pDDocument = PDDocument.load(new java.io.File(str));
                if (pDDocument.isEncrypted())
                {
                    pDDocument.setAllSecurityToBeRemoved(true);
                }
                pDDocument.save(this.tempFileName);
                this.doc = new PDDocument();
                switch (this.pdfaversion)
                {
                case 1:
                {
                    if (this.doc.getDocument().getVersion() < 1.4f)
                    {
                        this.doc.getDocument().setVersion(1.4f);
                    }
                    break;
                }

                case 2:
                {
                    if (this.doc.getDocument().getVersion() < 1.7f)
                    {
                        this.doc.getDocument().setVersion(1.7f);
                    }
                    break;
                }

                case 3:
                {
                    if (this.doc.getDocument().getVersion() < 1.7f)
                    {
                        this.doc.getDocument().setVersion(1.7f);
                    }
                    break;
                }
                }
                foreach (PDPage page in pDDocument.getPages())
                {
                    this.doc.addPage(page);
                }
                this.doc.setDocumentInformation(pDDocument.getDocumentInformation());
                this.doc.getDocumentCatalog().setDocumentOutline(pDDocument.getDocumentCatalog().getDocumentOutline());
                this.doc.getDocumentCatalog().setAcroForm(pDDocument.getDocumentCatalog().getAcroForm());
                this.doc.getDocumentCatalog().setLanguage(pDDocument.getDocumentCatalog().getLanguage());
                this.doc.getDocumentCatalog().setMetadata(pDDocument.getDocumentCatalog().getMetadata());
                this.doc.getDocumentCatalog().setPageLabels(pDDocument.getDocumentCatalog().getPageLabels());
                this.doc.getDocumentCatalog().setViewerPreferences(pDDocument.getDocumentCatalog().getViewerPreferences());
                this.doc.getDocumentCatalog().setPageMode(pDDocument.getDocumentCatalog().getPageMode());
                this.doc.getDocumentCatalog().setPageLayout(pDDocument.getDocumentCatalog().getPageLayout());
                this.doc.save(this.tempFileName);
                this.doc.close();
                this.doc = PDDocument.load(new java.io.File(this.tempFileName));
                pDDocument.close();
                pDDocument = null;
                try
                {
                    Assembly executingAssembly      = Assembly.GetExecutingAssembly();
                    Stream   manifestResourceStream = executingAssembly.GetManifestResourceStream("Aquaforest.PDF.sRGB_IEC61966-2-1_black_scaled.icc");
                    using (FileStream fileStream = System.IO.File.Create("sRGB_IEC61966-2-1_black_scaled.icc", (int)manifestResourceStream.Length))
                    {
                        byte[] numArray = new byte[checked (manifestResourceStream.Length)];
                        manifestResourceStream.Read(numArray, 0, (int)numArray.Length);
                        fileStream.Write(numArray, 0, (int)numArray.Length);
                    }
                    manifestResourceStream = executingAssembly.GetManifestResourceStream("Aquaforest.PDF.font.xml");
                    using (FileStream fileStream1 = System.IO.File.Create("font.xml", (int)manifestResourceStream.Length))
                    {
                        byte[] numArray1 = new byte[checked (manifestResourceStream.Length)];
                        manifestResourceStream.Read(numArray1, 0, (int)numArray1.Length);
                        fileStream1.Write(numArray1, 0, (int)numArray1.Length);
                    }
                }
                catch
                {
                }
                this.iccString = "sRGB_IEC61966-2-1_black_scaled.icc";
            }
            catch (InvalidPasswordException invalidPasswordException)
            {
                Console.WriteLine("The Password Provided is Invalid.");
                Environment.Exit(104);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                Environment.Exit(104);
            }
        }