Print Page | Close Window

AppendToFile, incremental updates

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=3438
Printed Date: 01 May 24 at 2:56AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: AppendToFile, incremental updates
Posted By: mhnejmles
Subject: AppendToFile, incremental updates
Date Posted: 10 Feb 17 at 1:55AM
So, has anyone been working with incremental updates lately? I've been trying to make it work in the latest 13.11 version but to no avail. Every pdf file I append goes corrupted and is unusable in most PDF viewers.

Even such a simple code like:

var
  PDF: TDebenuPDFLibrary;
  res: Integer;
begin
  PDF:= TDebenuPDFLibrary.Create;
  PDF.UnlockKey(const_key);
  res:= PDF.LoadFromFile(input_file, '');
  res:= PDF.AppendToFile(input_file);
  PDF.Free;
end;

ends up destroying the pdf file. And no changes were made to it. Direct Access functions work fine but you have less functionality in it. So have anyone else encountered this?



Replies:
Posted By: Ingo
Date Posted: 10 Feb 17 at 8:21AM
Hi mhnejmles,

you should put your code into a try/finally structure to be more save.
What's inside input_file?
It should be always the same name.
Please read the description regarding AppendToFile (then you'll know while corruption can appear):
http://www.debenu.com/docs/pdf_library_reference/AppendToFile.php
Here you can read about incremental updates:
http://www.debenu.com/kb/incremental-updates/

Cheers and welcome here,
Ingo



-------------
Cheers,
Ingo



Posted By: mhnejmles
Date Posted: 10 Feb 17 at 5:58PM
Hi,
thanks for the reply

Sorry, was working really late last night and I didn't have the strength to write everything down here. I am working with the 13.11 Delphi version of QuickPDFLibrary in Delphi Berlin 10.1.

I did go through the description and sample code based on the knowledge base topic about incremental updates to PDFs already.

I will elaborate more on the details....

So I basically copied the code structure from the sample. I was also trying to do some more with it but I came to the conclusion there might be a bug. So let's say I have a pdf file with a filepath. It's a simple pdf file I generated from a Word through Adobe PDF printer with some text in it. I wanna try to append some changes to the file. So I create a new form and a simple code:

unit Unit1;
interface
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, DebenuPDFLibrary, Vcl.StdCtrls;
Const QPDFLicKey='licensekey';
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
    { Public declarations }
  end;
function QuickPDFLib_AppendToPDF(filepath: String): Boolean;
var
  Form1: TForm1;
implementation
{$R *.dfm}
function QuickPDFLib_AppendToPDF(filepath: String): Boolean;
var PDF: TDebenuPDFLibrary;
begin
  result:= false;
  PDF:= TDebenuPDFLibrary.Create;
  PDF.UnlockKey(QPDFLicKey);
  if PDF.LoadFromFile(filepath ,'') > 0 then
    begin
      if PDF.AppendToFile(filepath) > 0 then
        result:= true;
    end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  res: boolean;
begin
  res:= QuickPDFLib_AppendToPDF('C:\pdf_work\test_pdf.pdf');
  if res then
    ShowMessage('Success!!')
  else
    ShowMessage('Fail!!');
end;
end.

And when I use the button, 'Success' message appears. But when I open the pdf file:

- in adobe reader, it gives me error 14, that the file is corrupted
- in google chrome, the file won't load
- tried MS Edge, the file did load there surprisingly

the code is just basic load and append nothing more when I do the same thing using Direct Access(DA) there is no problém, the pdf file saves fine. Problem is that DA doesnt have a lot of the usual functionality.
At first I tried to do some more stuff with it, like add an embedded file, merge 2 documents together and the result file came out alright when I use SaveToFile function. But whenever I use AppendToFile, the result file gets corrupted.
Note: the filepath always stays the same, so I am appending to the same file I open. If you don't give it the same file then the library throws an exception. I can upload the files somewhere if deemed neccessary. But I was kinda curious whether anyone else has encountered this.

Hope it is somewhat understandable,
mhnejmles



Posted By: Ingo
Date Posted: 11 Feb 17 at 10:20PM
if you wanna tell about an error this is the wrong place here...
Try the official support pages in this case.



-------------
Cheers,
Ingo




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