예제 #1
0
 public PdfCatalog GetCatalog()
 {
     PdfCatalog c = new PdfCatalog();
     c.Ref = NextRef;
     c.Add("Type", "/Catalog");
     c.Add("Pages", "");
     return c;
 }
예제 #2
0
파일: PdfBody.cs 프로젝트: 15831944/WW
 public PdfBody(FontType fontType)
 {
     this.pdfCatalog_0           = new PdfCatalog();
     this.pdfOutlines_0          = new PdfOutlines();
     this.pdfCatalog_0.Outlines  = this.pdfOutlines_0;
     this.pdfPages_0             = new PdfPages();
     this.pdfCatalog_0.Pages     = this.pdfPages_0;
     this.pdfProcedureSetArray_0 = new PdfProcedureSetArray();
     this.fontSetup_0            = new FontSetup(this.pdfFontInfo_0, fontType);
 }
예제 #3
0
        /// <inheritdoc/>
        protected override void Start()
        {
            ClearBitmaps();
            base.Start();
            pdfWriter = new PdfWriter(Stream);
            pdfWriter.Begin();
            PdfCatalog catalog = new PdfCatalog();

            pdfPages      = new PdfPages();
            pdfPagesLink  = pdfWriter.Prepare(pdfPages);
            catalog.Pages = pdfPagesLink;
            pdfWriter.Prepare(catalog);
            hashList = new Dictionary <string, PdfIndirectObject>();
        }
예제 #4
0
        /// <summary>
        /// This method checks a number of document-wide requirements of the PDF/A
        /// standard.
        /// </summary>
        /// <remarks>
        /// This method checks a number of document-wide requirements of the PDF/A
        /// standard. The algorithms of some of these checks vary with the PDF/A
        /// level and thus are implemented in subclasses; others are implemented
        /// as private methods in this class.
        /// </remarks>
        /// <param name="catalog">The catalog being checked</param>
        public virtual void CheckDocument(PdfCatalog catalog)
        {
            PdfDictionary catalogDict = catalog.GetPdfObject();

            SetPdfAOutputIntentColorSpace(catalogDict);
            CheckOutputIntents(catalogDict);
            CheckMetaData(catalogDict);
            CheckCatalogValidEntries(catalogDict);
            CheckTrailer(catalog.GetDocument().GetTrailer());
            CheckLogicalStructure(catalogDict);
            CheckForm(catalogDict.GetAsDictionary(PdfName.AcroForm));
            CheckOutlines(catalogDict);
            CheckPages(catalog.GetDocument());
            CheckOpenAction(catalogDict.Get(PdfName.OpenAction));
            CheckColorsUsages();
        }
예제 #5
0
        public Pdf(
            MediaBox mediaBox       = null,
            string version          = "1.7",
            PageLayout pageLayout   = PageLayout.OneColumn,
            PdfMetadata pdfMetadata = null)
        {
            Version = version;

            Pages = new PdfPages(ObjectNumber); // Move to function
            PdfObjects.Add(Pages);
            ObjectNumber++;

            Catalog = new PdfCatalog(ObjectNumber, this.Pages, pageLayout); // Move to function
            PdfObjects.Add(Catalog);
            ObjectNumber++;

            this.AddPage(mediaBox);
        }
예제 #6
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));

            PdfCatalog      catalog = pdfDoc.GetCatalog();
            PdfOCProperties ocProps = catalog.GetOCProperties(true);
            PdfDictionary   occd    = (PdfDictionary)ocProps.GetPdfObject().Get(PdfName.D);
            PdfArray        order   = occd.GetAsArray(PdfName.Order);

            PdfObject nestedLayers     = order.Get(0);
            PdfObject nestedLayerArray = order.Get(1);
            PdfObject groupedLayers    = order.Get(2);
            PdfObject radioGroup       = order.Get(3);

            order.Set(0, radioGroup);
            order.Set(1, nestedLayers);
            order.Set(2, nestedLayerArray);
            order.Set(3, groupedLayers);

            pdfDoc.Close();
        }
예제 #7
0
        public PdfDocument(PdfFile file)
        {
            _file = file;

            foreach (var item in _file.Items)
            {
                if (item is PdfTrailer trailer)
                {
                    var root = (PdfIndirectReference)trailer["Root"];

                    _root = new PdfCatalog(root.Dereference <PdfDictionary>());

                    break;
                }
            }

            // NOTE: Linearized documents may have multiple trailers. We use the first.

            if (_root is null)
            {
                throw new Exception("Missing trailer");
            }
        }
        /**
        * Gets the <CODE>PdfCatalog</CODE>-object.
        *
        * @param pages an indirect reference to this document pages
        * @return <CODE>PdfCatalog</CODE>
        */
        internal PdfCatalog GetCatalog(PdfIndirectReference pages) {
            PdfCatalog catalog = new PdfCatalog(pages, writer);
            
            // [C1] outlines
            if (rootOutline.Kids.Count > 0) {
                catalog.Put(PdfName.PAGEMODE, PdfName.USEOUTLINES);
                catalog.Put(PdfName.OUTLINES, rootOutline.IndirectReference);
            }
            
            // [C2] version
            writer.GetPdfVersion().AddToCatalog(catalog);
            
            // [C3] preferences
            viewerPreferences.AddToCatalog(catalog);
            
            // [C4] pagelabels
            if (pageLabels != null) {
                catalog.Put(PdfName.PAGELABELS, pageLabels.GetDictionary(writer));
            }
            
            // [C5] named objects
            catalog.AddNames(localDestinations, GetDocumentLevelJS(), documentFileAttachment, writer);
            
            // [C6] actions
            if (openActionName != null) {
                PdfAction action = GetLocalGotoAction(openActionName);
                catalog.OpenAction = action;
            }
            else if (openActionAction != null)
                catalog.OpenAction = openActionAction;
            if (additionalActions != null)   {
                catalog.AdditionalActions = additionalActions;
            }
            
            // [C7] portable collections
            if (collection != null) {
                catalog.Put(PdfName.COLLECTION, collection);
            }

            // [C8] AcroForm
            if (annotationsImp.HasValidAcroForm()) {
                catalog.Put(PdfName.ACROFORM, writer.AddToBody(annotationsImp.AcroForm).IndirectReference);
            }

            if (language != null) {
                catalog.Put(PdfName.LANG, language);
            }

            return catalog;
        }
예제 #9
0
        /// <exception cref="System.IO.IOException"/>
        private void OutputDss(PdfDictionary dss, PdfDictionary vrim, PdfArray ocsps, PdfArray crls, PdfArray certs
                               )
        {
            PdfCatalog catalog = document.GetCatalog();

            if (document.GetPdfVersion().CompareTo(PdfVersion.PDF_2_0) < 0)
            {
                catalog.AddDeveloperExtension(PdfDeveloperExtension.ESIC_1_7_EXTENSIONLEVEL5);
            }
            foreach (PdfName vkey in validated.Keys)
            {
                PdfArray      ocsp = new PdfArray();
                PdfArray      crl  = new PdfArray();
                PdfArray      cert = new PdfArray();
                PdfDictionary vri  = new PdfDictionary();
                foreach (byte[] b in validated.Get(vkey).crls)
                {
                    PdfStream ps = new PdfStream(b);
                    ps.SetCompressionLevel(CompressionConstants.DEFAULT_COMPRESSION);
                    ps.MakeIndirect(document);
                    crl.Add(ps);
                    crls.Add(ps);
                    crls.SetModified();
                }
                foreach (byte[] b in validated.Get(vkey).ocsps)
                {
                    PdfStream ps = new PdfStream(b);
                    ps.SetCompressionLevel(CompressionConstants.DEFAULT_COMPRESSION);
                    ocsp.Add(ps);
                    ocsps.Add(ps);
                    ocsps.SetModified();
                }
                foreach (byte[] b in validated.Get(vkey).certs)
                {
                    PdfStream ps = new PdfStream(b);
                    ps.SetCompressionLevel(CompressionConstants.DEFAULT_COMPRESSION);
                    ps.MakeIndirect(document);
                    cert.Add(ps);
                    certs.Add(ps);
                    certs.SetModified();
                }
                if (ocsp.Size() > 0)
                {
                    ocsp.MakeIndirect(document);
                    vri.Put(PdfName.OCSP, ocsp);
                }
                if (crl.Size() > 0)
                {
                    crl.MakeIndirect(document);
                    vri.Put(PdfName.CRL, crl);
                }
                if (cert.Size() > 0)
                {
                    cert.MakeIndirect(document);
                    vri.Put(PdfName.Cert, cert);
                }
                vri.MakeIndirect(document);
                vrim.Put(vkey, vri);
            }
            vrim.MakeIndirect(document);
            vrim.SetModified();
            dss.Put(PdfName.VRI, vrim);
            if (ocsps.Size() > 0)
            {
                ocsps.MakeIndirect(document);
                dss.Put(PdfName.OCSPs, ocsps);
            }
            if (crls.Size() > 0)
            {
                crls.MakeIndirect(document);
                dss.Put(PdfName.CRLs, crls);
            }
            if (certs.Size() > 0)
            {
                certs.MakeIndirect(document);
                dss.Put(PdfName.Certs, certs);
            }
            dss.MakeIndirect(document);
            dss.SetModified();
            catalog.Put(PdfName.DSS, dss);
        }
예제 #10
0
        // add another test comment
        // more and more comments
        public PdfDocument(String content)
        {
            _offset  = 0;
            _buffers = new List <String>();
            _offsets = new List <int>();

            // header
            _buffers.Add("%PDF-1.4\n%âãÏÓ\n");
            _offset += _buffers.Last().Length;
            _offsets.Add(_offset);

            // pages
            PdfPageTree pageTree = PdfPageTree.GetPdfPageTree();

            // page
            PdfPage page = new PdfPage();
            PdfFont font = new PdfFont();

            page.SetFont(font);
            PdfStream stream = new PdfStream(content);

            page.AddContent(stream);
            pageTree.AddPage(page);

            _buffers.Add(pageTree.ToPDF());
            _offset += _buffers.Last().Length;
            _offsets.Add(_offset);

            _buffers.Add(page.ToPDF());
            _offset += _buffers.Last().Length;
            _offsets.Add(_offset);

            _buffers.Add(font.ToPDF());
            _offset += _buffers.Last().Length;
            _offsets.Add(_offset);

            _buffers.Add(stream.ToPDF());
            _offset += _buffers.Last().Length;
            _offsets.Add(_offset);

            PdfCatalog catalog = PdfCatalog.GetPdfCatalog();

            _buffers.Add(catalog.ToPDF());
            _offset += _buffers.Last().Length;


            // x ref table
            String table = String.Empty;

            table += "xref" + "\n";
            table += "0 " + _buffers.Count.ToString() + "\n";
            table += "0000000000 65535 f \n";
            foreach (var offset in _offsets)
            {
                table += offset.ToString().PadLeft(10, '0') + " " + "00000" + " " + "n " + "\n";
            }
            _buffers.Add(table);


            // trailer
            String trailer = String.Empty;

            trailer += "trailer" + "\n" + "\n";
            trailer += "<<" + "\n";
            trailer += "/Root " + catalog.GetRefStr() + "\n";
            trailer += "/Size " + (_buffers.Count - 1).ToString() + "\n";
            trailer += ">>" + "\n";
            _buffers.Add(trailer);

            _buffers.Add("startxref" + "\n" + _offset.ToString() + "\n" + "%%EOF\n");
        }
예제 #11
0
        internal PdfDocument Merge(string outputFile, PdfMergeTree mergeTree)
        {
            Form1.configProgressBar(mergeTree.count);

            listOptions();

            if (!VerifyOutputFile(outputFile))
            {
                throw new IOException("Invalid Output File");
            }

            PdfWriter writer = new PdfWriter(outputFile);

            destPdf = new PdfDocument(writer);

            destPdfOutlines = destPdf.GetOutlines(false);

            PdfMerger merger = new PdfMerger(destPdf, MERGE_TAGS, MERGE_BOOKMARKS);

            merger.SetCloseSourceDocuments(false);

            logMsgDbLn2("");

            int pageCount = merge(merger, mergeTree.GetMergeItems, 1) - 1;

            logMsgFmtln("total page count", pageCount);

            if (pageCount < 1)
            {
                destPdf.Close();
                return(null);
            }

            if (KEEP_IMPORT_BOOKMARKS && ADD_BOOKMARK_FOR_EACH_FILE)
            {
                // process and adjust bookmarks
                MergeOutlines(destPdf.GetOutlines(true).GetAllChildren(),
                              mergeTree.GetMergeItems);
            }

            if (!(KEEP_IMPORT_BOOKMARKS && !ADD_BOOKMARK_FOR_EACH_FILE))
            {
                // eliminate all of the current bookmarks
                destPdfOutlines = clearOutline(destPdf);
            }

            if (ADD_BOOKMARK_FOR_EACH_FILE)
            {
                // add the new bookmarks
                addOutline(mergeTree.GetMergeItems, destPdfOutlines, 0);
            }
            // all complete
            // leave open for further processing
            //			destPdf.Close();

            // return the final PDF document

            PdfCatalog destPdfCatalog = destPdf.GetCatalog();

            destPdfCatalog.SetPageMode(PdfName.UseOutlines);
            destPdfCatalog.SetPageLayout(PdfName.SinglePage);
            destPdfCatalog.SetOpenAction(PdfExplicitDestination.CreateFit(1));

            return(destPdf);
        }