0

For diff with another. This is a problem with DevExpress Lib.

I have code below. On calling AddRubberStampAnnotation i have null reference exception without any stacktrace inside lib. Streams not empty, so i have no idea wtf. Using FilePath instead of Stream does not make any changes.

My goal are combine stamp(its full A4 pdf doc with all pages of pdf doc) My usings are

    <PackageReference Include="DevExpress.Document.Processor" Version="22.1.4" />
    <PackageReference Include="DevExpress.Drawing" Version="22.1.4" />
    <PackageReference Include="DevExpress.Pdf.Core" Version="22.1.4" />
    <PackageReference Include="DevExpress.Pdf.Drawing" Version="22.1.4" />
    public static byte[] MergeWithStampDevEx(this byte[] doc, byte[] stamp)
        {
            using var docStream = new MemoryStream(doc);
            using var outStream = new MemoryStream();
            using var stampStream = new MemoryStream(stamp);
            using var proccessor = new PdfDocumentProcessor();
            proccessor.LoadDocument(docStream);
            var rec = proccessor.Document.Pages[0].CropBox;

            foreach (var page in proccessor.DocumentFacade.Pages)
            {
                var stampFacade = page.AddRubberStampAnnotation(rec, stampStream, page.PageNumber);
                stampFacade.Opacity = WatermarkTransparentState;
            }
            proccessor.SaveDocument(outStream);

            return outStream.ToArray();
        }

Maybe ill must choose another way and its imposible?

Im tried to debug, but didnt see anything empty. So i have no ideas. From my code nothing is null, all have values and seems ok, so This question not usefull to detect a problem. One more - not enough stacktrace from deep of devexpress that is problem.

Hollow
  • 11
  • 3
  • `var rec = proccessor.Document.Pages[0].CropBox;` this code does not check for `null` of this var. Is it? – Fildor May 30 '23 at 08:24
  • @Fildor i know what is NRE, but i see no reasons of it. And this is not so different code with sample from official docs of devexpress. An error failed with no stacktrace like page is null, but in debug mode i can see values of props inside page var – Hollow May 30 '23 at 08:25
  • 1
    @Fildor `var rec = proccessor.Document.Pages[0].CropBox;` is not null, checked it right now – Hollow May 30 '23 at 08:28
  • `AddRubberStampAnnotation` is that an extension method or an actual class member? And I guess you also checked `page` itself and `page.PageNumber` ... Does it _always_ throw or only sometimes on the same input? Only on specific inputs but then repeatably? Or completely random? – Fildor May 30 '23 at 08:33
  • ^^ And are you 100% sure it throws on that line? ( Debuggers _can_ be off by some lines, sometimes. ) – Fildor May 30 '23 at 08:35
  • 1
    @Fildor its throws always. `page` and `page.PageNumber` is not null. `AddRubberStampAnnotation` is actual class member of `PdfPageFacade` that is type of `page`. Changing of input to file input instead of stream or changing files have no influence – Hollow May 30 '23 at 08:36
  • Can you add literal output of whatever you get as error, even if it lacks stacktrace? – Fildor May 30 '23 at 08:38
  • @Fildor yes, im sure. Calling this methode insid of local watch throws its to. Maybe by stacktrace it will depp inside of calls, but with no stacktrace debug it seems impossible, because resharper cant place breakpoint inside =( – Hollow May 30 '23 at 08:39
  • I'd also encourage to go and search in DevExpress's Support Forums and maybe if nothing is there post the error there. When we were still using it, I found their support quite effective at times. – Fildor May 30 '23 at 08:39
  • ``` System.NullReferenceException HResult=0x80004003 Message = Object reference not set to an instance of an object. Source = DevExpress.Pdf.v22.1.Core StackTrace: в Taxcom.PdrMerger.PdrMerger.MergeWithStampDevEx(Byte[] doc, Byte[] stamp) в C:\repos\git\old\taxcom.union.platform.b2b\Taxcom.PdrMerger\Class1.cs:line 57 в Test.Program.Main(String[] args) в C:\repos\git\old\taxcom.union.platform.b2b\Test\Program.cs:line12 ``` – Hollow May 30 '23 at 08:41
  • Hope you are well. DevExpress Support Services are only available to active subscribers (see Support Services | General Information | DevExpress Documentation) Unfortunately, we are not able to service or renew accounts in the Russian Federation as the global sanctions regime prevents us from transacting business with anyone located in the Russian Federation. I do apologize. – Hollow May 30 '23 at 08:43
  • 1
    To lazy to update question. If anyone will looking for get this: `PageNumber` must be from 1 to `page.Count()` as an arg for `addAnnotation`. Inside of devexpress there will be `int num = pageNumber - 1;` `foreach (IPdfAnnotationState pdfAnnotationState in documentStateBase[num].AnnotationStates.ToList())` – Hollow May 30 '23 at 09:10

0 Answers0