PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Mar 19, 2024 8:34 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Mar 08, 2018 12:26 pm 
Offline
User avatar

Joined: Thu Feb 08, 2018 3:40 am
Posts: 3
Hi,

How to get the text from the specific XRect position?

So far I have below code to add a text at specific XRect position. It works great. However, I would like to read the existing text from that position and based upon the existing text, I need to update the new text.

Code:
using (PdfDocument InputDocument = PdfReader.Open(filePath, PdfDocumentOpenMode.Modify))
            {
                for (int i = 0; i < InputDocument.Pages.Count; i++)
                {
                    PdfPage page = InputDocument.Pages[i];
                    XGraphics gfx = XGraphics.FromPdfPage(page);
                    XFont font = new XFont("Courier", 10, XFontStyle.Regular);
                    XTextFormatter tf = new XTextFormatter(gfx);

                    var rect = new XRect(new PointF(505, 38.5f), new SizeF(76, 10));

                    gfx.DrawRectangle(XBrushes.White, rect);
                    tf.Alignment = XParagraphAlignment.Left;
                    tf.DrawString("some text based upon existing text", font, XBrushes.Black, rect, XStringFormats.TopLeft);
                }

                InputDocument.Save("out.pdf");
            }


Please help.

Thanks

_________________
Sri


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 08, 2018 1:42 pm 
Offline
PDFsharp Guru
User avatar

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

PDFsharp was not designed to extract text.

You can search this site or the web for "text extract" and maybe look at this package:
https://www.nuget.org/packages/PdfTextract/

The task is simpler if you deal with PDF files coming from just one application.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 09, 2018 4:11 am 
Offline
User avatar

Joined: Thu Feb 08, 2018 3:40 am
Posts: 3
Thomas Hoevel wrote:
Hi!

PDFsharp was not designed to extract text.

You can search this site or the web for "text extract" and maybe look at this package:
https://www.nuget.org/packages/PdfTextract/

The task is simpler if you deal with PDF files coming from just one application.

Ok thanks. Yes. The PDF files which we are trying to edit are coming from one source. The position is same on all pdf files. Basically I am trying to update the page number once multiple pdf files are appended. There might be prefix/suffix to the page numbers. So, I need to read the existing page number and update it accordingly.

_________________
Sri


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 45 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