PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu May 13, 2021 9:24 am

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Nov 02, 2006 9:06 pm 

Joined: Thu Nov 02, 2006 9:02 pm
Posts: 1
Location: Australia
I was wondering if the PDFsharp object could be used to find text within a PDF file and retrieve the page number it was on. What I need to do is split a PDF file based upon finding some text.

ie. The top of every page has the text
where xxxxxxxx is the customer name. When the xxxxxxxx changes I need to split the PDF. So a single PDF with 10 pages, 4 which are for Customer X, 3 for Customer Y and 3 for Customer Z would need to produce 3 files,
one for customer X of three pages
one for customer Y of four pages
one for customer Z of three pages

It would also be great if the text search could use a regular expression.

Is this possible with PDFsharp?

Reply with quote  
 Post subject:
PostPosted: Thu Nov 02, 2006 10:04 pm 
empira Employee
User avatar

Joined: Thu Oct 12, 2006 10:07 pm
Posts: 49
Location: Cologne, Germany

the content of a PDF page is a sequence of bytes that represents graphical commands. These bytes are called the "content stream" of the page. You can get it uncompressed with this code:

A "Hello, World" page may look like this:
1 0 0 1 0 841.8898 cm
1 0 0 -1 0 0 cm
-100 Tz
/F0 -10 Tf
1 0 0 1 70.8661 80.9199 Tm
-10 TL
/F0 -10 Tf
1 0 0 1 99.4111 80.9199 Tm

You can find
as strings.

You should find
in your PDF file. This is easy to parse. Try PdfSharp Explorer to analyse your PDF.

But depending on the PDF producer application you find this:

There is kerning information (distance adjustment) between the characters. Adobe Acrobat never creates this if you use a fixed size font like Courier. Unfortunately tools like FreePDF always creates distance information, even if it is superfluous.

We at empira currently have the same problem to identify address information in PDF files and split it into single files. We recommend using Adobe Acrobat as producer and Courier New as font for the information text.

Further I wrote the class PdfSharp.Pdf.Content.ContentReader to convert a content stream into a squence of operation (it is in the current source code). Maybe this reader helps you to find your text.

I will publish our solution if we have one (currently we are working on other things).

Stefan Lange

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

All times are UTC

Who is online

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