Created
February 23, 2024 13:38
-
-
Save bjoerntx/0e8f8a316e8fd30d08cea5261e7b50ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// split a PDF document into chunks | |
public static List<string> Chunk(byte[] pdfDocument, int chunkSize, int overlap = 1) | |
{ | |
// create a new ServerTextControl instance | |
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) | |
{ | |
tx.Create(); | |
var loadSettings = new TXTextControl.LoadSettings | |
{ | |
PDFImportSettings = TXTextControl.PDFImportSettings.GenerateParagraphs | |
}; | |
// load the PDF document | |
tx.Load(pdfDocument, TXTextControl.BinaryStreamType.AdobePDF, loadSettings); | |
// remove line breaks | |
string pdfText = tx.Text.Replace("\r\n", " "); | |
// call the extracted chunk creation method | |
return CreateChunks(pdfText, chunkSize, overlap); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment