|
I have only used QuickPDF once and that was several years ago so I am a newbie. Be kind!
I hope someone can help me correct my thinking on how to split a file. I have spent hours on this and despite the code being similar (and simple) to every example I can find, my results are not correct. The task is to examine the input file, page by page, and output
to a new file each page that matches a key. The key can be located anywhere on the page.
My code outputs the correct number of pages but only the first page is correct, all others are blank. Obviously, I have something wrong in the "merge" code but I can't see it. I would also appreciate any suggestions on how to make the code more efficient. I have included the entire code snippet in case the problem is different than I think it is.
QuickPDF 7.19
{CODE} const eBillIdentifier = 'EBILL'; var NewID :integer; DocID : integer; x : integer; TextContent : AnsiString; PageOut : boolean; begin PageOut := false; // get total page count QP.LoadFromFile(FileIn); DocID := QP.SelectedDocument; PageCount := QP.PageCount; // Iterate through each page in the document x := 1; while x <= PageCount do begin // look for pages that match TextContent := QP.ExtractFilePageText(FileIn, '', x, 0); if pos(eBillIdentifier, TextContent) <> 0 then begin // found one QP.ExtractPageRanges(IntToStr(x)); // save ID of input page DocID := QP.SelectedDocument; // is it the first output page? if not PageOut then begin // yes, start output document NewID := QP.SelectedDocument; PageOut := true; end else begin // merge with previous result QP.SelectDocument(NewID); QP.MergeDocument(DocID); end; end; // page wanted inc(x); end; //loop QP.SelectDocument(NewID); QP.SaveToFile(FileOut); QP.RemoveDocument(NewID); {CODE}
TIA for your help, Tom
|