PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 9:05 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sun Mar 01, 2015 4:45 am 
Offline

Joined: Sun Mar 01, 2015 2:37 am
Posts: 3
Using the following code, I am able to write page numbers to SOME files.

Code:
  var outputDocument = new PdfDocument();
  var currentPageNumber = 1;

  var inputDocument = PdfReader.Open(@"C:\SamplePdfs\display.pdf", PdfDocumentOpenMode.Import);

  for (var i = 0; i < inputDocument.PageCount; i++)
  {
       PdfPage page = outputDocument.AddPage(inputDocument.Pages[i]);
       XGraphics gfx = XGraphics.FromPdfPage(page);
       XFont font = new XFont("Arial", 100, XFontStyle.Regular);
       gfx.DrawString(Convert.ToString(currentPageNumber), font, XBrushes.Black, new XRect(0, 0, page.Width - 100, page.Height - 100), XStringFormats.BottomCenter);
       currentPageNumber++;
  }

  outputDocument.Save(@"c:\test\sample1.pdf");

See an example pdf that I cannot write to here: http://www.filedropper.com/newdisplay It is like the pdfPage is not accepting the DrawString command even though all the other pages are.


Last edited by 82edwards on Mon Mar 02, 2015 1:47 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 01, 2015 8:04 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 340
Hi!

The link to the PDF does not work.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 1:47 am 
Offline

Joined: Sun Mar 01, 2015 2:37 am
Posts: 3
Link updated. A ";" was added at the end of the url and was causing the issue. Sorry about that.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 2:55 am 
Offline

Joined: Sun Mar 01, 2015 2:37 am
Posts: 3
Here is another example with a different host.

https://www.dropbox.com/s/0e0exs0lhytx3xl/ThirdConversion.pdf?dl=0

It is a 2 page pdf that is blank on both pages. I tried to upload it here, but it would not let me.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 5:28 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

The file NewDisplay.pdf uses negative values in the MediaBox: "MediaBox[-89.5 -702.5 702.5 -90.5]"

Most PDF files use positive values. Maybe your page numbers will show up when you use negative values for x and y.

I just ran the Watermark sample - and the watermark doesn't show. The same will happen to your page numbers.
I don't have time to give a deeper investigation now.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 301 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group