0

I am using PDFsharp and System.Drawing.Image to convert TIFF files to PDFs. After I generate the data to a stream, I convert it to a base64 string. However, even though I convert the same file, when I compare them, the strings have a couple characters that are different between runs. They appear perceptually the same but I do not know why there is variation in the end result.

Is there something in PDFsharp that needs to be set in order for PDF generation to be the exact same when I attempt to convert the same file? I know that if I have a PdfDocument p that p.Info.CreationDate is set to the current time so I set it to new DateTime() instead.

I do not believe the variability is caused by the byte array to base64 string because I use Convert.ToBase64String(myByteAarray).

To do the actual conversion, I use a process based on work by Steven Wellens: https://stackoverflow.com/a/35209378/19831782

usagibear
  • 303
  • 3
  • 12

1 Answers1

2

Fonts will be embedded using random names, so there will be some minor differences between PDF files created in different runs.

The GUID of the document (if any) will be different on each run.

There is no option (yet) to generate identical PDF files in different runs.

  • 1
    I appreciate the explanation. This is unfortunate for testing because I was hoping that I could make sure PDFs are generated as expected. Is there a workaround or region that will consistently be variable that I can ignore? I'm still quite new to testing and working with PDFs. Thanks! – usagibear Jan 11 '23 at 17:23
  • 1
    @usagibear When you diff the PDF files you can see that only irrelevant elements (font names, GUIDs) are different. Bad for automatic testing, but can be done manually ahead of major updates. I would like to have an option in PDFsharp that creates font names that will always be the same, but we do not have that yet. – I liked the old Stack Overflow Jan 12 '23 at 10:08