0

I've been working on an application in C# using WinForms and the PDFsharp library. The goal is to create a PDF file with a specified page label. I first saved a given string as the file name, then attempted to use a different string as the PageLabel. I tried properly setting the page label within the PDF document using PDFsharp, but faced challenges in getting the page label metadata in the correct location within the PDF structure.

I tried setting the page label using the PdfDictionary and PdfArray objects, but the label was not inserted in the correct location. Next, made adjustments to the code and attempted to modify the Pages dictionary rather than the Catalog dictionary, but still didn't achieve the desired result. I then further tried correcting the code to create and add the PdfDictionary and PdfArray objects in the right sequence, but still didn't achieve the desired metadata structure for the page labels.

Is there a way to do this using PDFSharp? Two of us have been working on this problem for days and while we're understanding a bit more of what goes where, we can't seem to solve this problem.

  • What is _a specified page label_? I've not used _PDFsharp_, but of the PDF libraries I've used, `0,0` coordinate is the lower-left corner of the page which seems counterintuitive as one may think of it being the upper-left corner of the page. – Tu deschizi eu inchid Apr 12 '23 at 00:37
  • The following may be of interest: https://stackoverflow.com/questions/54883217/pdfsharp-get-pages-coordinates and https://forum.pdfsharp.net/viewtopic.php?p=9038 – Tu deschizi eu inchid Apr 12 '23 at 00:37
  • Try adding page labels to a very basic PDF file with `cpdf -add-page-labels` and then look inside the output PDF file to see what was added and where. – johnwhitington Apr 12 '23 at 15:46
  • I wrote a basic winforms app to do just that. Input a string as the file name, and input a separate string for the page label. If you convert a pdf to a txt file and browse through the metadata you will find this snipit that defines a page label and what it's name is (though technically it is called a Prefix): 5 0 obj <>]>>>> endobj I can't seem to figure out a way to add this. It seems there is no method to produce this prefix '/P(MyLabel)' within the PDFSharp source code. Although I'd like to add it if possible.. – Brett M. Apr 13 '23 at 01:24

0 Answers0