コード例 #1
0
 public virtual void MakeObjectIndirectWhileFontIsIndirectTest()
 {
     using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) {
         // to avoid an exception
         document.AddNewPage();
         PdfFontUnitTest.TestFont font = new PdfFontUnitTest.TestFont();
         font.GetPdfObject().MakeIndirect(document);
         PdfDictionary dictionary = new PdfDictionary();
         NUnit.Framework.Assert.IsTrue(font.MakeObjectIndirect(dictionary));
         NUnit.Framework.Assert.IsNotNull(dictionary.GetIndirectReference());
         NUnit.Framework.Assert.AreEqual(document, dictionary.GetIndirectReference().GetDocument());
     }
 }
コード例 #2
0
 private void RemovePageTagFromParent(IPdfStructElem pageTag, IPdfStructElem parent)
 {
     if (parent is PdfStructElem)
     {
         PdfStructElem structParent = (PdfStructElem)parent;
         if (!structParent.IsFlushed())
         {
             structParent.RemoveKid(pageTag);
             PdfDictionary parentObject = structParent.GetPdfObject();
             if (!connectedStructToModel.ContainsKey(parentObject) && parent.GetKids().Count == 0 && parentObject != rootTagElement
                 .GetPdfObject())
             {
                 RemovePageTagFromParent(structParent, parent.GetParent());
                 parentObject.GetIndirectReference().SetFree();
             }
         }
         else
         {
             if (pageTag is PdfMcr)
             {
                 throw new PdfException(PdfException.CannotRemoveTagBecauseItsParentIsFlushed);
             }
         }
     }
 }
コード例 #3
0
 private void RemovePageTagFromParent(IStructureNode pageTag, IStructureNode parent)
 {
     if (parent is PdfStructElem)
     {
         PdfStructElem structParent = (PdfStructElem)parent;
         if (!structParent.IsFlushed())
         {
             structParent.RemoveKid(pageTag);
             PdfDictionary parentStructDict = structParent.GetPdfObject();
             if (waitingTagsManager.GetObjForStructDict(parentStructDict) == null && parent.GetKids().Count == 0 && !(structParent
                                                                                                                      .GetParent() is PdfStructTreeRoot))
             {
                 RemovePageTagFromParent(structParent, parent.GetParent());
                 PdfIndirectReference indRef = parentStructDict.GetIndirectReference();
                 if (indRef != null)
                 {
                     // TODO how about possible references to structure element from refs or structure destination for instance?
                     indRef.SetFree();
                 }
             }
         }
         else
         {
             if (pageTag is PdfMcr)
             {
                 throw new PdfException(PdfException.CannotRemoveTagBecauseItsParentIsFlushed);
             }
         }
     }
 }
コード例 #4
0
        public virtual void MakeObjectIndirectWhileFontIsDirectTest()
        {
            PdfFontUnitTest.TestFont font       = new PdfFontUnitTest.TestFont();
            PdfDictionary            dictionary = new PdfDictionary();

            NUnit.Framework.Assert.IsFalse(font.MakeObjectIndirect(dictionary));
            NUnit.Framework.Assert.IsNull(dictionary.GetIndirectReference());
        }
コード例 #5
0
        private void RegisterMcr(PdfMcr mcr, bool registeringOnInit)
        {
            PdfDictionary mcrPageObject = mcr.GetPageObject();

            if (mcrPageObject == null || (!(mcr is PdfObjRef) && mcr.GetMcid() < 0))
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Kernel.Pdf.Tagging.ParentTreeHandler));
                logger.Error(iText.IO.LogMessageConstant.ENCOUNTERED_INVALID_MCR);
                return;
            }
            SortedDictionary <int, PdfMcr> pageMcrs = pageToPageMcrs.Get(mcrPageObject.GetIndirectReference());

            if (pageMcrs == null)
            {
                pageMcrs = new SortedDictionary <int, PdfMcr>();
                pageToPageMcrs.Put(mcrPageObject.GetIndirectReference(), pageMcrs);
            }
            if (mcr is PdfObjRef)
            {
                PdfDictionary obj = ((PdfDictionary)mcr.GetPdfObject()).GetAsDictionary(PdfName.Obj);
                if (obj == null || obj.IsFlushed())
                {
                    throw new PdfException(PdfException.WhenAddingObjectReferenceToTheTagTreeItMustBeConnectedToNotFlushedObject
                                           );
                }
                PdfNumber n = obj.GetAsNumber(PdfName.StructParent);
                if (n != null)
                {
                    pageMcrs.Put(StructParentIndexIntoKey(n.IntValue()), mcr);
                }
                else
                {
                    throw new PdfException(PdfException.StructParentIndexNotFoundInTaggedObject);
                }
            }
            else
            {
                pageMcrs.Put(mcr.GetMcid(), mcr);
            }
            if (!registeringOnInit)
            {
                structTreeRoot.SetModified();
            }
        }
コード例 #6
0
            public virtual bool CheckWhetherSignatureCoversWholeDocument(PdfFormField signatureField)
            {
                rangeIsCorrect = false;
                PdfDictionary signature = (PdfDictionary)signatureField.GetValue();

                int[] byteRange = ((PdfArray)signature.Get(PdfName.ByteRange)).ToIntArray();
                try {
                    if (4 != byteRange.Length || 0 != byteRange[0] || tokens.GetSafeFile().Length() != byteRange[2] + byteRange
                        [3])
                    {
                        return(false);
                    }
                }
                catch (System.IO.IOException) {
                    // That's not expected because if the signature is invalid, it should have already failed
                    return(false);
                }
                contentsStart = byteRange[1];
                contentsEnd   = byteRange[2];
                long signatureOffset;

                if (null != signature.GetIndirectReference())
                {
                    signatureOffset = signature.GetIndirectReference().GetOffset();
                    searchInV       = true;
                }
                else
                {
                    signatureOffset = signatureField.GetPdfObject().GetIndirectReference().GetOffset();
                    searchInV       = false;
                    contentsLevel++;
                }
                try {
                    tokens.Seek(signatureOffset);
                    tokens.NextValidToken();
                    ReadObject(false, false);
                }
                catch (System.IO.IOException) {
                    // That's not expected because if the signature is invalid, it should have already failed
                    return(false);
                }
                return(rangeIsCorrect);
            }
コード例 #7
0
        private bool EnsureElementPageEqualsKidPage(PdfStructElem elem, PdfDictionary kidPage)
        {
            PdfObject pageObject = elem.GetPdfObject().Get(PdfName.Pg);

            if (pageObject == null)
            {
                pageObject = kidPage;
                // Explicitly using object indirect reference here in order to correctly process released objects.
                elem.Put(PdfName.Pg, kidPage.GetIndirectReference());
            }
            return(kidPage.Equals(pageObject));
        }
コード例 #8
0
ファイル: PdfObjRef.cs プロジェクト: leofidus/itext7-dotnet
        public PdfObjRef(PdfAnnotation annot, PdfStructElem parent)
            : base(new PdfDictionary(), parent)
        {
            PdfDictionary parentObject = parent.GetPdfObject();

            EnsureObjectIsAddedToDocument(parentObject);
            PdfDocument doc = parentObject.GetIndirectReference().GetDocument();

            annot.GetPdfObject().Put(PdfName.StructParent, new PdfNumber((int)doc.GetNextStructParentIndex()));
            PdfDictionary dict = (PdfDictionary)GetPdfObject();

            dict.Put(PdfName.Type, PdfName.OBJR);
            dict.Put(PdfName.Obj, annot.GetPdfObject());
        }
コード例 #9
0
        public virtual void UnregisterMcr(PdfMcr mcrToUnregister)
        {
            PdfDictionary pageDict = mcrToUnregister.GetPageObject();

            if (pageDict == null)
            {
                // invalid mcr, ignore
                return;
            }
            if (pageDict.IsFlushed())
            {
                throw new PdfException(PdfException.CannotRemoveMarkedContentReferenceBecauseItsPageWasAlreadyFlushed);
            }
            IDictionary <int, PdfMcr> pageMcrs = pageToPageMcrs.Get(pageDict.GetIndirectReference());

            if (pageMcrs != null)
            {
                if (mcrToUnregister is PdfObjRef)
                {
                    PdfDictionary obj = ((PdfDictionary)mcrToUnregister.GetPdfObject()).GetAsDictionary(PdfName.Obj);
                    if (obj != null && !obj.IsFlushed())
                    {
                        PdfNumber n = obj.GetAsNumber(PdfName.StructParent);
                        if (n != null)
                        {
                            pageMcrs.JRemove(StructParentIndexIntoKey(n.IntValue()));
                            structTreeRoot.SetModified();
                            return;
                        }
                    }
                    foreach (KeyValuePair <int, PdfMcr> entry in pageMcrs)
                    {
                        if (entry.Value.GetPdfObject() == mcrToUnregister.GetPdfObject())
                        {
                            pageMcrs.JRemove(entry.Key);
                            structTreeRoot.SetModified();
                            break;
                        }
                    }
                }
                else
                {
                    pageMcrs.JRemove(mcrToUnregister.GetMcid());
                    structTreeRoot.SetModified();
                }
            }
        }
コード例 #10
0
        private PdfMcr PrepareMcrForMovingToNewParent(PdfMcr mcrKid, PdfStructElem newParent)
        {
            PdfObject     mcrObject = mcrKid.GetPdfObject();
            PdfDictionary mcrPage   = mcrKid.GetPageObject();
            PdfDictionary mcrDict   = null;

            if (!mcrObject.IsNumber())
            {
                mcrDict = (PdfDictionary)mcrObject;
            }
            if (mcrDict == null || !mcrDict.ContainsKey(PdfName.Pg))
            {
                if (!EnsureElementPageEqualsKidPage(newParent, mcrPage))
                {
                    if (mcrDict == null)
                    {
                        mcrDict = new PdfDictionary();
                        mcrDict.Put(PdfName.Type, PdfName.MCR);
                        mcrDict.Put(PdfName.MCID, mcrKid.GetPdfObject());
                    }
                    // Explicitly using object indirect reference here in order to correctly process released objects.
                    mcrDict.Put(PdfName.Pg, mcrPage.GetIndirectReference());
                }
            }
            if (mcrDict != null)
            {
                if (PdfName.MCR.Equals(mcrDict.Get(PdfName.Type)))
                {
                    mcrKid = new PdfMcrDictionary(mcrDict, newParent);
                }
                else
                {
                    if (PdfName.OBJR.Equals(mcrDict.Get(PdfName.Type)))
                    {
                        mcrKid = new PdfObjRef(mcrDict, newParent);
                    }
                }
            }
            else
            {
                mcrKid = new PdfMcrNumber((PdfNumber)mcrObject, newParent);
            }
            return(mcrKid);
        }
コード例 #11
0
        /// <summary>This method removes all widget annotation entries from the form field  the given annotation merged with.
        ///     </summary>
        public virtual void ReleaseFormFieldFromWidgetAnnotation()
        {
            PdfDictionary annotDict = GetPdfObject();

            foreach (PdfName entry in widgetEntries)
            {
                annotDict.Remove(entry);
            }
            PdfDictionary parent = annotDict.GetAsDictionary(PdfName.Parent);

            if (parent != null && annotDict.Size() == 1)
            {
                PdfArray kids = parent.GetAsArray(PdfName.Kids);
                kids.Remove(annotDict.GetIndirectReference());
                if (kids.Size() == 0)
                {
                    parent.Remove(PdfName.Kids);
                }
            }
        }
コード例 #12
0
ファイル: UpdateLinksTests.cs プロジェクト: icnocop/HtmlToPdf
        public void OneFile_LinksToTheNextFile_UpdatesLink(string exeFileName)
        {
            HtmlToPdfRunner runner = new HtmlToPdfRunner(exeFileName);

            string htmlFile2Contents = @"
<html>
  <head>
  </head>
  <body>
   Page 2
  </body>
</html>";

            using (TempHtmlFile htmlFile2 = new TempHtmlFile(htmlFile2Contents))
            {
                string htmlFile1Contents = $@"
<html>
  <head>
  </head>
  <body>
   Page 1
   <br/>
   <a href=""{htmlFile2.FilePath}"">Page 2</a>
  </body>
</html>";
                using (TempHtmlFile htmlFile1 = new TempHtmlFile(htmlFile1Contents))
                {
                    using (TempPdfFile pdfFile = new TempPdfFile(this.TestContext))
                    {
                        string             commandLine = $"\"{htmlFile1.FilePath}\" \"{htmlFile2.FilePath}\" \"{pdfFile.FilePath}\"";
                        HtmlToPdfRunResult result      = runner.Run(commandLine);
                        Assert.AreEqual(0, result.ExitCode, result.Output);

                        using (PdfReader pdfReader = new PdfReader(pdfFile.FilePath))
                        {
                            using (PdfDocument pdfDocument = new PdfDocument(pdfReader))
                            {
                                Assert.AreEqual(2, pdfDocument.GetNumberOfPages());

                                // get the first page
                                PdfPage pdfPage = pdfDocument.GetPage(1);

                                // get link annotations
                                List <PdfLinkAnnotation> linkAnnotations = pdfPage.GetAnnotations().OfType <PdfLinkAnnotation>().ToList();
                                Assert.AreEqual(1, linkAnnotations.Count);

                                // get the first link annotation
                                PdfLinkAnnotation linkAnnotation = linkAnnotations.ElementAt(0);
                                Assert.IsNotNull(linkAnnotation);

                                // get action
                                PdfDictionary action = linkAnnotation.GetAction();
                                Assert.IsNotNull(action);

                                // get GoTo sub-type
                                PdfName s = action.GetAsName(PdfName.S);

                                if (exeFileName == HtmlToPdfRunner.HtmlToPdfExe)
                                {
                                    Assert.AreEqual(PdfName.GoTo, s);

                                    // get destination
                                    PdfArray             destination = action.GetAsArray(PdfName.D);
                                    PdfIndirectReference destinationPageReference = destination.GetAsDictionary(0).GetIndirectReference();
                                    PdfName   zoom       = destination.GetAsName(1);
                                    PdfNumber pageOffset = destination.GetAsNumber(2);

                                    // get expected values
                                    PdfPage              pdfPage2              = pdfDocument.GetPage(2);
                                    PdfDictionary        page2Dictionary       = pdfPage2.GetPdfObject();
                                    PdfIndirectReference expectedPageReference = page2Dictionary.GetIndirectReference();
                                    PdfName              expectedZoom          = PdfName.FitH;
                                    float expectedPageOffset = pdfPage2.GetPageSize().GetTop();

                                    // assert
                                    Assert.AreEqual(expectedPageReference, destinationPageReference);
                                    Assert.AreEqual(expectedZoom, zoom);
                                    Assert.AreEqual(expectedPageOffset, pageOffset.FloatValue());
                                }
                                else if (exeFileName == HtmlToPdfRunner.WkhtmltopdfExe)
                                {
                                    Assert.AreEqual(PdfName.URI, s);

                                    PdfString uri = action.GetAsString(PdfName.URI);
                                    Assert.AreEqual(htmlFile2.FilePath, HttpUtility.UrlDecode(uri.ToString()));
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
        private static void SeparateKids(PdfDictionary structElem, ICollection <PdfObject> firstPartElems, StructureTreeCopier.LastClonedAncestor
                                         lastCloned)
        {
            PdfObject k = structElem.Get(PdfName.K);

            // If /K entry is not a PdfArray - it would be a kid which we won't clone at the moment, because it won't contain
            // kids from both parts at the same time. It would either be cloned as an ancestor later, or not cloned at all.
            // If it's kid is struct elem - it would definitely be structElem from the first part, so we simply call separateKids for it.
            if (!k.IsArray())
            {
                if (k.IsDictionary() && PdfStructElem.IsStructElem((PdfDictionary)k))
                {
                    SeparateKids((PdfDictionary)k, firstPartElems, lastCloned);
                }
            }
            else
            {
                PdfDocument document = structElem.GetIndirectReference().GetDocument();
                PdfArray    kids     = (PdfArray)k;
                for (int i = 0; i < kids.Size(); ++i)
                {
                    PdfObject     kid     = kids.Get(i);
                    PdfDictionary dictKid = null;
                    if (kid.IsDictionary())
                    {
                        dictKid = (PdfDictionary)kid;
                    }
                    if (dictKid != null && PdfStructElem.IsStructElem(dictKid))
                    {
                        if (firstPartElems.Contains(kid))
                        {
                            SeparateKids((PdfDictionary)kid, firstPartElems, lastCloned);
                        }
                        else
                        {
                            if (dictKid.IsFlushed())
                            {
                                throw new PdfException(PdfException.TagFromTheExistingTagStructureIsFlushedCannotAddCopiedPageTags);
                            }
                            // elems with no kids will not be marked as from the first part,
                            // but nonetheless we don't want to move all of them to the second part; we just leave them as is
                            if (dictKid.ContainsKey(PdfName.K))
                            {
                                CloneParents(structElem, lastCloned, document);
                                kids.Remove(i--);
                                PdfStructElem.AddKidObject(lastCloned.clone, -1, kid);
                            }
                        }
                    }
                    else
                    {
                        if (!firstPartElems.Contains(kid))
                        {
                            CloneParents(structElem, lastCloned, document);
                            PdfMcr mcr;
                            if (dictKid != null)
                            {
                                if (dictKid.Get(PdfName.Type).Equals(PdfName.MCR))
                                {
                                    mcr = new PdfMcrDictionary(dictKid, new PdfStructElem(lastCloned.clone));
                                }
                                else
                                {
                                    mcr = new PdfObjRef(dictKid, new PdfStructElem(lastCloned.clone));
                                }
                            }
                            else
                            {
                                mcr = new PdfMcrNumber((PdfNumber)kid, new PdfStructElem(lastCloned.clone));
                            }
                            kids.Remove(i--);
                            PdfStructElem.AddKidObject(lastCloned.clone, -1, kid);
                            document.GetStructTreeRoot().GetParentTreeHandler().RegisterMcr(mcr);
                        }
                    }
                }
            }
            // re-register mcr
            if (lastCloned.ancestor == structElem)
            {
                lastCloned.ancestor = lastCloned.ancestor.GetAsDictionary(PdfName.P);
                lastCloned.clone    = lastCloned.clone.GetAsDictionary(PdfName.P);
            }
        }
コード例 #14
0
        protected internal virtual void FlushFontData(String fontName, PdfName subtype)
        {
            GetPdfObject().Put(PdfName.Subtype, subtype);
            if (fontName != null && fontName.Length > 0)
            {
                GetPdfObject().Put(PdfName.BaseFont, new PdfName(fontName));
            }
            int firstChar;
            int lastChar;

            for (firstChar = 0; firstChar < 256; ++firstChar)
            {
                if (shortTag[firstChar] != 0)
                {
                    break;
                }
            }
            for (lastChar = 255; lastChar >= firstChar; --lastChar)
            {
                if (shortTag[lastChar] != 0)
                {
                    break;
                }
            }
            if (firstChar > 255)
            {
                firstChar = 255;
                lastChar  = 255;
            }
            if (!IsSubset() || !IsEmbedded())
            {
                firstChar = 0;
                lastChar  = shortTag.Length - 1;
                for (int k = 0; k < shortTag.Length; ++k)
                {
                    // remove unsupported by encoding values in case custom encoding.
                    // save widths information in case standard pdf encodings (winansi or macroman)
                    if (fontEncoding.CanDecode(k))
                    {
                        shortTag[k] = 1;
                    }
                    else
                    {
                        if (!fontEncoding.HasDifferences() && fontProgram.GetGlyphByCode(k) != null)
                        {
                            shortTag[k] = 1;
                        }
                        else
                        {
                            shortTag[k] = 0;
                        }
                    }
                }
            }
            if (fontEncoding.HasDifferences())
            {
                // trim range of symbols
                for (int k = firstChar; k <= lastChar; ++k)
                {
                    if (!FontEncoding.NOTDEF.Equals(fontEncoding.GetDifference(k)))
                    {
                        firstChar = k;
                        break;
                    }
                }
                for (int k = lastChar; k >= firstChar; --k)
                {
                    if (!FontEncoding.NOTDEF.Equals(fontEncoding.GetDifference(k)))
                    {
                        lastChar = k;
                        break;
                    }
                }
                PdfDictionary enc = new PdfDictionary();
                enc.Put(PdfName.Type, PdfName.Encoding);
                PdfArray diff = new PdfArray();
                bool     gap  = true;
                for (int k = firstChar; k <= lastChar; ++k)
                {
                    if (shortTag[k] != 0)
                    {
                        if (gap)
                        {
                            diff.Add(new PdfNumber(k));
                            gap = false;
                        }
                        diff.Add(new PdfName(fontEncoding.GetDifference(k)));
                    }
                    else
                    {
                        gap = true;
                    }
                }
                enc.Put(PdfName.Differences, diff);
                GetPdfObject().Put(PdfName.Encoding, enc);
            }
            else
            {
                if (!fontEncoding.IsFontSpecific())
                {
                    GetPdfObject().Put(PdfName.Encoding, PdfEncodings.CP1252.Equals(fontEncoding.GetBaseEncoding()) ? PdfName.
                                       WinAnsiEncoding : PdfName.MacRomanEncoding);
                }
            }
            if (IsForceWidthsOutput() || !IsBuiltInFont() || fontEncoding.HasDifferences())
            {
                GetPdfObject().Put(PdfName.FirstChar, new PdfNumber(firstChar));
                GetPdfObject().Put(PdfName.LastChar, new PdfNumber(lastChar));
                PdfArray wd = new PdfArray();
                for (int k = firstChar; k <= lastChar; ++k)
                {
                    if (shortTag[k] == 0)
                    {
                        wd.Add(new PdfNumber(0));
                    }
                    else
                    {
                        //prevent lost of widths info
                        int   uni   = fontEncoding.GetUnicode(k);
                        Glyph glyph = uni > -1 ? GetGlyph(uni) : fontProgram.GetGlyphByCode(k);
                        wd.Add(new PdfNumber(glyph != null ? glyph.GetWidth() : 0));
                    }
                }
                GetPdfObject().Put(PdfName.Widths, wd);
            }
            PdfDictionary fontDescriptor = !IsBuiltInFont() ? GetFontDescriptor(fontName) : null;

            if (fontDescriptor != null)
            {
                GetPdfObject().Put(PdfName.FontDescriptor, fontDescriptor);
                if (fontDescriptor.GetIndirectReference() != null)
                {
                    fontDescriptor.Flush();
                }
            }
        }
コード例 #15
0
 private IDictionary <int, CleanUpImagesCompareTool.PageImageObjectsPaths> ExtractImagesFromPdf(String pdf,
                                                                                                String outputPath)
 {
     using (PdfReader readerPdf = new PdfReader(pdf)) {
         using (PdfDocument pdfDoc = new PdfDocument(readerPdf)) {
             IDictionary <int, CleanUpImagesCompareTool.PageImageObjectsPaths> imageObjectDatas = new Dictionary <int, CleanUpImagesCompareTool.PageImageObjectsPaths
                                                                                                                  >();
             for (int i = 1; i <= pdfDoc.GetNumberOfPages(); i++)
             {
                 PdfPage page = pdfDoc.GetPage(i);
                 CleanUpImagesCompareTool.PageImageObjectsPaths imageObjectData = new CleanUpImagesCompareTool.PageImageObjectsPaths
                                                                                      (page.GetPdfObject().GetIndirectReference());
                 Stack <LocalPathItem> baseLocalPath = new Stack <LocalPathItem>();
                 PdfResources          pdfResources  = page.GetResources();
                 if (pdfResources.GetPdfObject().IsIndirect())
                 {
                     imageObjectData.AddIndirectReference(pdfResources.GetPdfObject().GetIndirectReference());
                 }
                 else
                 {
                     baseLocalPath.Push(new DictPathItem(PdfName.Resources));
                 }
                 PdfDictionary xObjects = pdfResources.GetResource(PdfName.XObject);
                 if (xObjects == null)
                 {
                     continue;
                 }
                 if (xObjects.IsIndirect())
                 {
                     imageObjectData.AddIndirectReference(xObjects.GetIndirectReference());
                     baseLocalPath.Clear();
                 }
                 else
                 {
                     baseLocalPath.Push(new DictPathItem(PdfName.XObject));
                 }
                 bool isPageToGsExtract = false;
                 foreach (PdfName objectName in xObjects.KeySet())
                 {
                     if (!xObjects.Get(objectName).IsStream() || !PdfName.Image.Equals(xObjects.GetAsStream(objectName).GetAsName
                                                                                           (PdfName.Subtype)))
                     {
                         continue;
                     }
                     PdfImageXObject pdfObject = new PdfImageXObject(xObjects.GetAsStream(objectName));
                     baseLocalPath.Push(new DictPathItem(objectName));
                     if (!useGs)
                     {
                         String extension = pdfObject.IdentifyImageFileExtension();
                         String fileName  = outputPath + objectName + "_" + i + "." + extension;
                         CreateImageFromPdfXObject(fileName, pdfObject);
                     }
                     else
                     {
                         isPageToGsExtract = true;
                     }
                     Stack <LocalPathItem> reversedStack = new Stack <LocalPathItem>();
                     reversedStack.AddAll(baseLocalPath);
                     Stack <LocalPathItem> resultStack = new Stack <LocalPathItem>();
                     resultStack.AddAll(reversedStack);
                     imageObjectData.AddLocalPath(resultStack);
                     baseLocalPath.Pop();
                 }
                 if (useGs && isPageToGsExtract)
                 {
                     String fileName = "Page_" + i;
                     ghostscriptHelper.RunGhostScriptImageGeneration(pdf, outputPath, fileName, i.ToString());
                 }
                 CleanUpImagesCompareTool.ImageRenderListener listener = new CleanUpImagesCompareTool.ImageRenderListener();
                 PdfCanvasProcessor parser = new PdfCanvasProcessor(listener);
                 parser.ProcessPageContent(page);
                 ignoredImagesAreas.Put(i, listener.GetImageRectangles());
                 imageObjectDatas.Put(i, imageObjectData);
             }
             return(imageObjectDatas);
         }
     }
 }
コード例 #16
0
        public virtual void UnregisterMcr(PdfMcr mcrToUnregister)
        {
            PdfDictionary pageDict = mcrToUnregister.GetPageObject();

            if (pageDict == null)
            {
                // invalid mcr, ignore
                return;
            }
            if (pageDict.IsFlushed())
            {
                throw new PdfException(PdfException.CannotRemoveMarkedContentReferenceBecauseItsPageWasAlreadyFlushed);
            }
            ParentTreeHandler.PageMcrsContainer pageMcrs = pageToPageMcrs.Get(pageDict.GetIndirectReference());
            if (pageMcrs != null)
            {
                PdfObject stm;
                if ((stm = GetStm(mcrToUnregister)) != null)
                {
                    PdfIndirectReference xObjectReference = stm is PdfIndirectReference ? (PdfIndirectReference)stm : stm.GetIndirectReference
                                                                ();
                    pageMcrs.GetPageResourceXObjects().Get(xObjectReference).JRemove(mcrToUnregister.GetMcid());
                    if (pageMcrs.GetPageResourceXObjects().Get(xObjectReference).IsEmpty())
                    {
                        pageMcrs.GetPageResourceXObjects().JRemove(xObjectReference);
                        xObjectToStructParentsInd.JRemove(xObjectReference);
                    }
                    structTreeRoot.SetModified();
                }
                else
                {
                    if (mcrToUnregister is PdfObjRef)
                    {
                        PdfDictionary obj = ((PdfDictionary)mcrToUnregister.GetPdfObject()).GetAsDictionary(PdfName.Obj);
                        if (obj != null && !obj.IsFlushed())
                        {
                            PdfNumber n = obj.GetAsNumber(PdfName.StructParent);
                            if (n != null)
                            {
                                pageMcrs.GetObjRefs().JRemove(n.IntValue());
                                structTreeRoot.SetModified();
                                return;
                            }
                        }
                        foreach (KeyValuePair <int, PdfMcr> entry in pageMcrs.GetObjRefs())
                        {
                            if (entry.Value.GetPdfObject() == mcrToUnregister.GetPdfObject())
                            {
                                pageMcrs.GetObjRefs().JRemove(entry.Key);
                                structTreeRoot.SetModified();
                                break;
                            }
                        }
                    }
                    else
                    {
                        pageMcrs.GetPageContentStreamsMcrs().JRemove(mcrToUnregister.GetMcid());
                        structTreeRoot.SetModified();
                    }
                }
            }
        }
コード例 #17
0
 // Mind that this method searches among items contained in page's content stream  only
 public virtual PdfMcr FindMcrByMcid(PdfDictionary pageDict, int mcid)
 {
     ParentTreeHandler.PageMcrsContainer pageMcrs = pageToPageMcrs.Get(pageDict.GetIndirectReference());
     return(pageMcrs != null?pageMcrs.GetPageContentStreamsMcrs().Get(mcid) : null);
 }
コード例 #18
0
 public virtual PdfObjRef FindObjRefByStructParentIndex(PdfDictionary pageDict, int structParentIndex)
 {
     ParentTreeHandler.PageMcrsContainer pageMcrs = pageToPageMcrs.Get(pageDict.GetIndirectReference());
     return(pageMcrs != null ? (PdfObjRef)pageMcrs.GetObjRefs().Get(structParentIndex) : null);
 }
コード例 #19
0
 /// <summary>Updates this object with the values from a dictionary.</summary>
 /// <param name="extGState">the dictionary containing source parameters</param>
 public virtual void UpdateFromExtGState(PdfDictionary extGState)
 {
     UpdateFromExtGState(new PdfExtGState(extGState), extGState.GetIndirectReference() == null ? null : extGState
                         .GetIndirectReference().GetDocument());
 }
コード例 #20
0
        public virtual PdfMcr FindMcrByMcid(PdfDictionary pageDict, int mcid)
        {
            IDictionary <int, PdfMcr> pageMcrs = pageToPageMcrs.Get(pageDict.GetIndirectReference());

            return(pageMcrs != null?pageMcrs.Get(mcid) : null);
        }
コード例 #21
0
        public virtual PdfObjRef FindObjRefByStructParentIndex(PdfDictionary pageDict, int structParentIndex)
        {
            IDictionary <int, PdfMcr> pageMcrs = pageToPageMcrs.Get(pageDict.GetIndirectReference());

            return(pageMcrs != null ? (PdfObjRef)pageMcrs.Get(StructParentIndexIntoKey(structParentIndex)) : null);
        }