示例#1
0
        public ActionResult PdfToPdfAConverter(string conformance, string Browser)
        {
            if (Request.Form.Files != null && Request.Form.Files.Count != 0)
            {
                //Load an existing PDF.
                PdfLoadedDocument doc = new PdfLoadedDocument(Request.Form.Files[0].OpenReadStream());
                doc.SubstituteFont += LoadedDocument_SubstituteFont;
                if (conformance == "PDF/A-1b")
                {
                    //Create a new document with PDF/A standard.
                    doc.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B);
                }
                else if (conformance == "PDF/A-2b")
                {
                    //Create a new document with PDF/A standard.
                    doc.ConvertToPDFA(PdfConformanceLevel.Pdf_A2B);
                }
                else if (conformance == "PDF/A-3b")
                {
                    //Create a new document with PDF/A standard.
                    doc.ConvertToPDFA(PdfConformanceLevel.Pdf_A3B);
                }

                //If the position is not set to '0' then the PDF will be empty.
                MemoryStream ms = new MemoryStream();
                doc.Save(ms);
                ms.Position = 0;
                doc.Close(true);
                //Download the PDF document in the browser.
                FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
                fileStreamResult.FileDownloadName = "PDFA.pdf";
                return(fileStreamResult);
            }
            else
            {
                ViewBag.lab  = "Choose a valid PDF file.";
                ViewBag.data = new string[] { "PDF/A-1b", "PDF/A-2b", "PDF/A-3b" };
                return(View());
            }
        }