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 > General Discussion
  New Posts New Posts RSS Feed - Split a document and store it in a stream in Delph
  FAQ FAQ  Forum Search   Register Register  Login Login

Split a document and store it in a stream in Delph

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

Joined: 14 Dec 10
Location: 404
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmaltais Quote  Post ReplyReply Direct Link To This Post Topic: Split a document and store it in a stream in Delph
    Posted: 10 Jan 11 at 9:33PM
Hi,

I need to split a PDF document bot I don't want to generate intermediate files. The resulting documents are stored in a database blob field using a MemoryStream.

Thanks
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 10 Jan 11 at 9:39PM
Hi!

Have a look in the online-reference here:
http://www.quickpdflibrary.com/help/quickpdf/FunctionGroups.php

These two chapters should be interest regarding your question:
http://www.quickpdflibrary.com/help/quickpdf/DocumentManipulation.php
http://www.quickpdflibrary.com/help/quickpdf/PageManipulation.php

Cheers, Ingo


Back to Top
Paddy View Drop Down
Beginner
Beginner


Joined: 24 Mar 10
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote Paddy Quote  Post ReplyReply Direct Link To This Post Posted: 11 Jan 11 at 9:12AM
If you use the ExtractPageRanges function then you can get the split / extract pages into memory and then save the resulting new document to your database using the SteamToStream function if you're using Delphi or the SaveToVariant function if you're using the ActiveX edition or the SaveToString function if you're using the DLL edition. That should do the trick.
Back to Top
pmaltais View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Dec 10
Location: 404
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmaltais Quote  Post ReplyReply Direct Link To This Post Posted: 11 Jan 11 at 2:08PM
Ok I get it.

When you extract pages from document A. It creates document B. Do pages extracted from document A are deleted from that document or just copied to the new one (B)?

Thanks
Back to Top
pmaltais View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Dec 10
Location: 404
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmaltais Quote  Post ReplyReply Direct Link To This Post Posted: 11 Jan 11 at 5:11PM
Hi!

Here's a function I call to SPLIT a document conained in a TMemoryStream property of a custom maid object. The object is to be split at page iFromPage.

It works well as long as there's more than 2 pages in the document. Otherwise, the resulting splitted 2 documents only hava a blank page in it.

Any idea on what's wrong with my code? Is there a better solution?

Thanks

function  TDocumentService.SplitPDFDocument(oDocument : TDocument; iFromPage : integer) : TDocument;
var
  iStatus: Integer;
  myPDFLibCtrl: TQuickPDF0722;
  iSubDocumentID: Integer;
  oNewDocument: TDocument;
begin
  // Init.
  myPDFLibCtrl := nil;
  oNewDocument := nil; // Created by the  CopyToNewDocument function
  iStatus := 0;

  if Assigned(oDocument) then
  begin
    try
      // Load Library
      myPDFLibCtrl := TQuickPDF0722.Create();
      iStatus := myPDFLibCtrl.UnlockKey(LIC_QUICK_PDF_LIB);
      if (iStatus <> 0) then
      begin
        // Load document stream from custom document object into control
        // memStream is a property of type TMemoryStream
        oDocument.memStream.Seek(0, soFromBeginning);
        while not (oDocument.fileStream.Position = 0) do;
        myPDFLibCtrl.LoadFromStream(oDocument.memStream);

        // Save second part to new document
        iSubDocumentID := myPDFLibCtrl.ExtractPages(iFromPage, myPDFLibCtrl.PageCount);
        myPDFLibCtrl.SelectDocument(iSubDocumentID);
        oNewDocument := CopyToNewDocument(oDocument);
        myPDFLibCtrl.SaveToStream(oNewDocument.memStream);
        oNewDocument.numberOfPages := myPDFLibCtrl.PageCount;

        // Reload document object to process first part
        oDocument.fileStream.Seek(0, soFromBeginning);
        while not (oDocument.memStream.Position = 0) do;
        myPDFLibCtrl.LoadFromStream(oDocument.memStream);

        // Save pages from first part back into original document
        iSubDocumentID := myPDFLibCtrl.ExtractPages(1, iFromPage - 1);
        myPDFLibCtrl.SelectDocument(iSubDocumentID);
        myPDFLibCtrl.SaveToStream(oDocument.memStream);
        oDocument.numberOfPages := myPDFLibCtrl.PageCount;

      end
      else
      begin
        ShowMessage('Quick PDF Library: Invalid licence.');
      end;
    except
      on E: Exception do ShowMessage(E.Message);
    end;

    // Cleanup
    FreeAndNil(myPDFLibCtrl);
  end;
  Result := oNewDocument;
end;

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