コード例 #1
0
        public Task <byte[]> ConvertToPdfA2B(MemoryStream input)
        {
            var output    = new MemoryStream();
            var iccStream = new FileStream(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _imageColorMatchingFilename), FileMode.Open, FileAccess.Read);

            try
            {
                var intent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", iccStream);

                var currentPdf = new PdfADocument(new PdfWriter(output), PdfAConformanceLevel.PDF_A_2B, intent);
                var inputPdf   = new PdfDocument(new PdfReader(input));

                currentPdf.SetTagged();
                currentPdf.GetCatalog().SetLang(new PdfString("en-US"));
                currentPdf.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true));

                for (int i = 1; i <= inputPdf.GetNumberOfPages(); i++)
                {
                    currentPdf.AddPage(inputPdf.GetPage(i).CopyTo(currentPdf));
                }

                //inputPdf.CopyPagesTo(1, inputPdf.GetNumberOfPages(), currentPdf);

                currentPdf.Close();

                return(Task.FromResult(output.ToArray()));
            }
            finally
            {
                iccStream.Dispose();
                input.Dispose();
                output.Dispose();
            }
        }
コード例 #2
0
        public void Copy(PdfDocument pdf)
        {
            var numberOfPages = pdf.GetNumberOfPages();

            for (var pageNumber = 1; pageNumber <= numberOfPages; pageNumber++)
            {
                var page       = pdf.GetPage(pageNumber);
                var copiedPage = page.CopyTo(_pdfa);

                _pdfa.AddPage(copiedPage);
            }
        }