Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Problem Splitting a File
  FAQ FAQ  Forum Search   Register Register  Login Login

Problem Splitting a File

 Post Reply Post Reply
Author
Message
Thahn View Drop Down
Beginner
Beginner
Avatar

Joined: 26 Jul 10
Location: U.S.
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote Thahn Quote  Post ReplyReply Direct Link To This Post Topic: Problem Splitting a File
    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

Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 02 Jul 12 at 1:35PM
Here is a link to some sample code that will do what you need.


Andrew.

Back to Top
Thahn View Drop Down
Beginner
Beginner
Avatar

Joined: 26 Jul 10
Location: U.S.
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote Thahn Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store