Skip to content

[Bug]: PDF tools write the regional calendar's year as the PDF's date, and fail in Saudi Arabia and Iran #1972

Done

Description

@lightscape-jm

What happened?

PDFsharp writes a PDF's dates (Info /CreationDate, /ModDate and the XMP packet) with the thread's regional format. Where that format's calendar isn't the Gregorian one, the PDF is dated with that calendar's year written as a Gregorian one: 2569 under Thailand's (Thai Buddhist), 1405 under Iran's (Persian), 1448 under Saudi Arabia's (Umm al-Qura). Under Saudi Arabia's and Iran's, saving a PDF again then fails with "Specified time is not supported in this calendar" when the PDF carries a date that calendar can't write: 1448 from an earlier save, or no creation date at all (PDFsharp then uses year 1).

#1775 fixes this for the PDFs its PdfSharpConverter.SaveDated saves: the marked-frames export, merge, picture → PDF, and PdfFinishing.Finish (page numbers, watermark, password). These PDFsharp saves still use the regional calendar:

  • PdfPageTools: rotate, crop and the page editor's reorder and turn
  • PdfSheets: pages per sheet
  • PdfBlankPages: remove blank pages
  • PdfPrintableAnnotations: printable annotations for PDF/A
  • PdfSharpConverter: split, extract pages, remove metadata, and compression (whole file, pages, split)
  • CompressionEstimator: the compression estimate (a save to a counting stream)
  • Ebooks/ComicBook: comic → PDF
  • Ocr/OcrTextLayer and Ocr/TesseractConverter: OCR of a PDF or a picture
  • Office/LibreOfficeConverter: the first-page PDF

Fix

A fix is ready on my fork (fix/pdf-dates-calendar): every PDFsharp save in Filee.Engines goes through SaveDated, and a test runs every PDF tool under ar-SA, th-TH, fa-IR and en-US, with PDFs dated in ways those calendars can't write, and reads the compiled engines for any other PdfDocument save. It builds on #1775's SaveDated, so I'll open it after #1775 merges, in our agreed order.

What did you expect?

Every PDF dated this year in the Gregorian calendar (PDF dates are Gregorian, whatever the user's calendar), and every PDF tool working under every regional format.

Steps to reproduce

  1. Set the system's regional format to Thai (Thailand), or Arabic (Saudi Arabia).
  2. Rotate a PDF (or crop it, remove its blank pages, compress it, split it…).
  3. Thai: the output's /CreationDate reads D:2569…. Saudi Arabia: rotate the output again, or remove its metadata; the job fails with "Specified time is not supported in this calendar".

Files involved

Any PDF. A PDF with no /CreationDate fails in Saudi Arabia and Iran on the first save.

Filee version

main at 79f03be (and current main: the saves listed above are unchanged).

Operating system

Found under ar-SA, th-TH and fa-IR on macOS (the regional format is the thread's culture, so every system is affected).

Engines page status

No response

Log


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions