Example #1
0
        /// <summary>
        /// Sets PDF/A Conformance ColorProfile.
        /// </summary>
        public void SetColorProfile()
        {
            if (PageSetup.ConformanceLevel == PdfXConformance.PDFXNONE)
            {
                return;
            }

            var pdfDictionary = new PdfDictionary(PdfName.OUTPUTINTENT);

            pdfDictionary.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
            pdfDictionary.Put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
            pdfDictionary.Put(PdfName.S, PdfName.GTS_PDFA1);

            var profileStream = StreamHelper.GetResourceByName("PdfRpt.Core.Helper.srgb.profile");
            var pdfICCBased   = new PdfICCBased(ICC_Profile.GetInstance(profileStream));

            pdfICCBased.Remove(PdfName.ALTERNATE);
            pdfDictionary.Put(PdfName.DESTOUTPUTPROFILE, PdfWriter.AddToBody(pdfICCBased).IndirectReference);

            PdfWriter.ExtraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(pdfDictionary));
        }
Example #2
0
        private void crearPdf_2(string rutaFinal)
        {
            try
            {
                lbl_pdfconvertir.Text = "Convirtiendo a PDF/A...";
                lbl_pdfconvertir.Refresh();
                string ruta_archivo = convertidor_path;
                System.Drawing.Image actualBitmap_ = System.Drawing.Image.FromFile(ruta_archivo);
                Guid objGuid = actualBitmap_.FrameDimensionsList[0];
                System.Drawing.Imaging.FrameDimension objDimension = new System.Drawing.Imaging.FrameDimension(objGuid);
                int total_page = actualBitmap_.GetFrameCount(objDimension);
                actualBitmap_.SelectActiveFrame(objDimension, 0);



                garbage_collector();
                var width0  = actualBitmap_.Width;
                var height0 = actualBitmap_.Height;
                iTextSharp.text.Rectangle cero = new iTextSharp.text.Rectangle(width0, height0);

                doc_pdf = new Document(cero, 0, 0, 0, 0);

                doc_pdf.SetMargins(0, 0, 0, 0);
                PdfWriter writer = PdfWriter.GetInstance(doc_pdf, new FileStream(rutaFinal, FileMode.Create));
                writer.PDFXConformance = PdfWriter.PDFA1B;
                doc_pdf.Open();

                PdfDictionary outi = new PdfDictionary(PdfName.OUTPUTINTENT);
                outi.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
                outi.Put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
                outi.Put(PdfName.S, PdfName.GTS_PDFA1);

                //Perfiles icc
                var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
                path = path.Replace("file:\\", "");
                ICC_Profile icc = ICC_Profile.GetInstance(path + @"\sRGB_v4.icc");
                PdfICCBased ib  = new PdfICCBased(icc);
                ib.Remove(PdfName.ALTERNATE);
                outi.Put(PdfName.DESTOUTPUTPROFILE, writer.AddToBody(ib).IndirectReference);

                writer.ExtraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(outi));
                BaseFont             bf = BaseFont.CreateFont(path + @"\arial.ttf", BaseFont.WINANSI, true);
                iTextSharp.text.Font f  = new iTextSharp.text.Font(bf, 12);

                float subtrahend0 = doc_pdf.PageSize.Height - 10;

                iTextSharp.text.Image pool0;
                pool0 = iTextSharp.text.Image.GetInstance(actualBitmap_, System.Drawing.Imaging.ImageFormat.Gif);

                pool0.Alignment = 3;
                pool0.ScaleToFit(doc_pdf.PageSize.Width - (doc_pdf.RightMargin * 2), subtrahend0);
                doc_pdf.Add(pool0);
                garbage_collector();
                //Crear las paginas
                for (int i = 1; i < total_page; ++i)
                {
                    actualBitmap_.SelectActiveFrame(objDimension, i);
                    float Width  = actualBitmap_.Width;
                    float Height = actualBitmap_.Height;
                    Task  task1  = Task.Factory.StartNew(() => pdf_paralelo_page(actualBitmap_));
                    Task  task2  = Task.Factory.StartNew(() => pdf_paralelo_doc(Width, Height));
                    Task.WaitAll(task1, task2);
                    doc_pdf.Add(page_prop_pdf);
                    decimal porcentaje = ((decimal)i / (decimal)total_page);
                    progressBar1.Value = (int)(porcentaje * 100);
                    progressBar1.Refresh();
                    garbage_collector();
                }
                progressBar1.Value = 100;
                writer.CreateXmpMetadata();
                doc_pdf.Close();
                actualBitmap_.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Falla de sistema en la conversión a PDF/A", title);
                if (ex.ToString().Contains("utilizado en otro proceso"))
                {
                    MessageBox.Show("El PDF esta siendo utilizado en otro proceso", title);
                }
                MessageBox.Show(ex.ToString(), title);
                garbage_collector();
            }
            garbage_collector();
        }