Print Page | Close Window

Problem Splitting a File

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2320
Printed Date: 03 Feb 26 at 11:35AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Problem Splitting a File
Posted By: Thahn
Subject: Problem Splitting a File
Date Posted: 28 Jun 12 at 2:00PM
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




Replies:
Posted By: AndrewC
Date Posted: 02 Jul 12 at 1:35PM
Here is a link to some sample code that will do what you need.

http://www.quickpdf.org/forum/c-extract-pages-based-on-a-keyword-match_topic2325.html - http://www.quickpdf.org/forum/c-extract-pages-based-on-a-keyword-match_topic2325.html

Andrew.



Posted By: Thahn
Date Posted: 04 Jul 12 at 11:44AM
Thank you. It works perfectly and is more faster by a factor of at least 4:1 on larger files.

Tom



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk