Print Page | Close Window

Deleting indirect objects

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


Topic: Deleting indirect objects
Posted By: cycle
Subject: Deleting indirect objects
Date Posted: 04 Feb 06 at 6:55AM
Here is an observation I made while using this library.

Suppose you are editing a pdf file and you want to delete an indirect object that is referenced from a dictionary.
The relevant portions of the file can look like this

1000 0 obj << /StreamKey 2000 0 R /OtherKey whatever>>
endobj

...

2000 0 obj << /Length 34141 >> stream
... stream contents ...
endstream
endobj


How do you delete this stream?

Maybe

doc:TPDFDocument;
dict:TPDFDictionary;
obj:TPDFObject;
ref:TPdfIndRef;

obj:=dict.FindValueByKeyName('StreamKey', true);
obj.Purge;


No, it produces an error during saving. Similarly, the following code will not work either.

obj:=dict.FindValueByKeyName('StreamKey', false);
if obj is TPDFIndRef then begin
ref:=TPDFIndRef(obj);
ref.Obj.Purge;
ref.Purge
end;


Looking closer, one can find procedure TPDFDocument.DeleteObj(ObjNum, GenNum) that does exactly what needed. But alas, it is not public.

Fortunately, there is a way around that does not require modifying the library source. The address of this procedure is assigned to a published property of PageTree field. The final code is

ref:=TPDFIndRef(obj);
doc.PageTree.OnDeleteObj(ref.ObjNum, ref.GenNum);
and
dict.PurgeKey('StreamKey');


It works, but it is not exactly trivial.



Replies:
Posted By: swb1
Date Posted: 04 Feb 06 at 5:31PM
This looks like it will work well for Delphi programmers but what about ActiveX and DLL users?


Posted By: cycle
Date Posted: 05 Feb 06 at 2:24AM
It probably won't work for them. It looks like COM and DLL wrappers only expose the top level interface, TiSedQuickPdf class, not the underlying classes, and pdf objects (Cos layer in Adobe terms) are pretty low level.



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