PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

What does `warn: default category[0]` mean?
http://forum.pdfsharp.com/viewtopic.php?f=2&t=4544
Page 1 of 1

Author:  mino [ Sun Feb 04, 2024 12:13 am ]
Post subject:  What does `warn: default category[0]` mean?

Hello,

I need to read the metadata of PDF documents, it works fine with PdfSharp, but for some PDFs (see attached to reproduce the problem) the following warning is launched:
Quote:
Code:
warn: default category[0]
      Another instance of object 14532 0 R was found. Using previously encountered object instead.

with the number 14532 being "random" (it probably isn't that random, but by that I mean it changes with patological pdfs). This warning message always appears when at least two PDF files are involved, but for some PDFs their combination does not produce the message. Here's the code (F#) I use to produce this warning message (I use the NuGet version of PdfSharp 6.0.0):
Code:
open PdfSharp.Pdf.IO

let file1 = "Modern Computer Algebra.pdf"
let file2 = "Scientific Programming with Maxima.pdf"

let a = PdfReader.Open file1
let b = PdfReader.Open file2

Then, the terminal show this:
Quote:
Code:
warn: default category[0]
      Another instance of object 14532 0 R was found. Using previously encountered object instead.
warn: default category[0]
      Another instance of object 14532 0 R was found. Using previously encountered object instead.

If I only open one of the files, then no message appears. I tried to close (after use) the open pdfs (a.Close() and b.Close()) thinking it might cause the error, but apparently not.

I haven't found a way to silence this warning, nor to correct the problem it seems to raise, I need to read thousands of PDFs this way and the terminal displays hundreds of such warnings, which is quite annoying. What can I do to solve this "problem"?

PS: Here's a WeTransfer link for the files in question (they're too large for the forum)

Author:  Thomas Hoevel [ Mon Feb 05, 2024 10:00 am ]
Post subject:  Re: What does `warn: default category[0]` mean?

Simple answer: File "a" generates no warnings, file "b" generates two warnings.
Those are warnings, no error messages.

If you do not want to see warnings, configure the logger accordingly.

Code:
// Set a logger factory.
using var loggerFactory_ = LoggerFactory.Create(builder =>
{
    builder
        .AddFilter("PDFsharp", LogLevel.Error) // Suppress warnings.
        .AddConsole();
});
LogHost.Factory = loggerFactory_;

var a = PdfReader.Open(@"D:\Computer Algebra\Modern Computer Algebra.pdf");
var b = PdfReader.Open(@"D:\Computer Algebra\Scientific Programming with Maxima.pdf");


Sample code is C#, not F#.

Author:  mino [ Mon Feb 05, 2024 4:32 pm ]
Post subject:  Re: What does `warn: default category[0]` mean?

Thank you for your reply, I was inattentive to the fact that this is indeed a double warning generated by a single PDF file.
I didn't know that PDFsharp used Microsoft.Extensions.Logging (actually, I didn't even know it existed). After some research, it turns out that the code you provided should instead be changed to this for the fix to be effective:
Code:
using var loggerFactory_ = LoggerFactory.Create(builder =>
{
    builder
        .AddFilter("default category", LogLevel.Error)
        .AddConsole();
});

Here's the F# version for those interested:
Code:
let loggerFactory = LoggerFactory.Create(fun builder -> builder.AddFilter("default category", LogLevel.Error).AddConsole() |> ignore)
LogHost.Factory <- loggerFactory

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/