Skip to main content
Participant
February 20, 2020
解決済み

JavaScript help - making all object ID for xobjects unique

  • February 20, 2020
  • 返信数 2.
  • 1498 ビュー

Hi

 

I'm trying to write the javascript for a custom command that runs through a document and finds all xobjects with duplicate object ID and changes the object IDs so they are unique. For context, the xobjects with duplicate object ID's is about 1-2% or less of all xobjects.

 

I've been struggling to find which part of the api relates to what I want to do, if someone is able to point me in the right direction or have an example?

 

Any help is much appreciated!

 

 

このトピックへの返信は締め切られました。
解決に役立った回答 Test Screen Name

JavaScript can't do anything like that, nor get near it. There is no access to page objects. Plug-ins, in C++, have low level access. Why would you want to do this? Shared XObjects is a design aim of PDF, so that identical content does not have to be duplicated. You cannot change an object ID at all, but you could duplicate objects and hence get new object IDs. But why just make the file bigger?

返信数 2

Thom Parker
Community Expert
Community Expert
February 21, 2020

You do know that indirect object IDs in a PDF have to be properly referenced in the object lists and cross reference table? Even with a plug-in you can't simply change an ID. This is a fundamental part of the PDF structure. You would have to access the PDF at the byte level to make this kind of change.  

 

Oddly enough you can actually do this with Acrobat JavaScript. There's an undocument document object function that provides a byte stream of the PDF file contents. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Legend
February 21, 2020

That's an interesting hidden feature. Editing PDF objects (and duplicating form XObjects and updating references), via JavaScript on a bytestream... I think it's fair to say that wouldn't be for the faint-hearted.

Thom Parker
Community Expert
Community Expert
February 21, 2020

Ha, ha, yes, building a PDF parser within Acrobat JavaScript would be quite the challenge. The biggest problem wouldn't be the XRef table, it would be decompressing the object collections. I'll leave that to someone with more time 😉

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Legend
February 20, 2020

JavaScript can't do anything like that, nor get near it. There is no access to page objects. Plug-ins, in C++, have low level access. Why would you want to do this? Shared XObjects is a design aim of PDF, so that identical content does not have to be duplicated. You cannot change an object ID at all, but you could duplicate objects and hence get new object IDs. But why just make the file bigger?

thomas_2020作成者
Participant
February 21, 2020

Thanks! That explains why I couldn't find anything, it's not really possible/practical.

 

I was looking at this in relation to After applying redactions other information is removed 

Legend
February 21, 2020

An interesting discussion. Thanks for the link, I added to it.