iTextSharp.text.pdf.PdfCopy.CopyAcroForm C# (CSharp) Метод

CopyAcroForm() публичный Метод

public CopyAcroForm ( PdfReader reader ) : void
reader PdfReader
Результат void
        public void CopyAcroForm(PdfReader reader)
        {
            SetFromReader(reader);

            PdfDictionary catalog = reader.Catalog;
            PRIndirectReference hisRef = null;
            PdfObject o = catalog.Get(PdfName.ACROFORM);
            if (o != null && o.Type == PdfObject.INDIRECT)
                hisRef = (PRIndirectReference)o;
            if (hisRef == null) return; // bugfix by John Engla
            RefKey key = new RefKey(hisRef);
            PdfIndirectReference myRef;
            IndirectReferences iRef;
            indirects.TryGetValue(key, out iRef);
            if (iRef != null) {
                acroForm = myRef = iRef.Ref;
            }
            else {
                acroForm = myRef = body.PdfIndirectReference;
                iRef = new IndirectReferences(myRef);
                indirects[key] =  iRef;
            }
            if (! iRef.Copied) {
                iRef.SetCopied();
                PdfDictionary theForm = CopyDictionary((PdfDictionary)PdfReader.GetPdfObject(hisRef));
                AddToBody(theForm, myRef);
            }
        }

Usage Example

Пример #1
0
        private void CombineMultiplePDFsCer(string[] fileNames, string outFile, bool deleteSource)
        {
            // step 1: creation of a document-object
            Document document = new Document();

            //create newFileStream object which will be disposed at the end
            using (FileStream newFileStream = new FileStream(outFile, FileMode.Create))
            {
                // step 2: we create a writer that listens to the document
                PdfCopy writer = new iTextSharp.text.pdf.PdfCopy(document, newFileStream);
                if (writer == null)
                {
                    return;
                }
                // step 3: we open the document
                document.Open();
                foreach (string fileName in fileNames)
                {
                    // we create a reader for a certain document
                    PdfReader reader = new PdfReader(fileName);
                    reader.ConsolidateNamedDestinations();
                    // step 4: we add content
                    for (int i = 1; i <= reader.NumberOfPages; i++)
                    {
                        PdfImportedPage page = writer.GetImportedPage(reader, i);
                        writer.AddPage(page);
                    }
                    PRAcroForm form = reader.AcroForm;
                    if (form != null)
                    {
                        writer.CopyAcroForm(reader);
                    }
                    reader.Close();

                    if (deleteSource)
                    {
                        File.Delete(fileName);
                    }
                }
                // step 5: we close the document and writer
                writer.Close();
                document.Close();
            }//disposes the newFileStream object
        }
All Usage Examples Of iTextSharp.text.pdf.PdfCopy::CopyAcroForm