Knowledgebase

Back to Articles List

How do I delete document info from a PDF file using PXCp_SetDocumentInfoExW?

Question:

How do I delete document Info from a PDF file using PXCp_SetDocumentInfoExW?

Using PXCp_SetDocumentInfoExW I can set info in a PDF file.
But how can I delete them?
I tried setting them to a blank string, but it doesn't seem to work, the value of another property is set. Why?

Code:

var str_name, str_value : string;
PXCp_SetDocumentInfoExW(pdf, PWChar(WideString(str_name)), PWChar(WideString(str_value)));

Answer:

You can clear an Info string using Low-Level API, but if setting it to empty will be enough, you may call PXCp_SetDocumentInfoExW:

PXCp_SetDocumentInfoExW(hPdfDocument, L"Key name to clear", L"")

The only way to truly clear the Info String, currently, though, is to use the Low-Level API (see code example below).

Code (C++ Example):

PDFDocument hDocument;
HRESULT hr;
//Read document
HPDFSTRING pKey = NULL;
do
{
  HPDFDICTIONARY Dict;
  hr = PXCp_llGetDocTrailer(hDocument, &Dict);
  if (IS_DS_FAILED(hr))
    break;
  if (Dict == NULL)
    break;
  HPDFVARIANT pInfoVar;
  hr = PXCp_DictionaryGetKeyByStr(Dict, "Info", 4", pInfoVar);
  if (IS_DS_FAILED(hr))
    break;
  DPDFVariant_Type t;
  hr = PXCp_VariantGetType(pInfoVar, &t);
  if (IS_DS_FAILED(hr))
    break;
  if (t != PVT_OBJREF)
  {
    // Actually info should be indirect dictionary
    break;
  }
  HPDFOBJECT pInfoObj;
  hr = PXCp_VariantGetObject(pInfoVar, &pInfoObj);
  if (IS_DS_FAILED(hr))
    break;
  if (pInfoObj == NULL)
    break;
  HPDFDICTIONARY pInfoDict;
  hr = PXCp_ObjectGetDictionary(pInfoObj, &pInfoDict);
  if (IS_DS_FAILED(hr))
    break;
  if (pInfoDict == NULL)
    break;
  pKey = PXCp_StringCreate();
  if (pKey == NULL)
    break;
  hr = PXCp_StringSetA(pKey, "My custom info")
  if (IS_DS_FAILED(hr))
    break;
  hr = PXCp_DictionaryClearValue(pInfoDict, pKey, TRUE);
} while (FALSE);
if (pKey != NULL)
  PXCp_StringDelete(pKey);

Note:

You will  need the PDF-XChange PRO SDK license to be able to use the Low-Level API functions in anything other than evaluation mode.

The Low-Level API is a set of powerful functions allowing developers to access the very heart of a PDF page/file and make changes of the most fundamental nature - with this power comes a price, indiscriminate use of the Low-Level API functions will undoubtedly lead to file corruption and problems - these functions are not to be used in haste and we accept no responsibility whatsoever for developers use of these functions - use with caution!

 When requesting support regarding the Low-Level API functions you will be expected to have a thorough working knowledge of the PDF format and the associated documentation from Adobe - we regret we cannot and will not 'educate' developers in this vast and complex subject.

We do provide limited documentation in the PDF-ToolsV4SDK.pdf Help File (Topic 3.2 Low-Level API, pg. 377)

The best reference for the Low-Level API is The Adobe PDF Reference, Sixth Edition, is available as a PDF portfolio from Adobe but has been superseded by the ISO 32000-1 document. Both documents provide a description of the PDF file format and are intended primarily for developers of PDF producer applications that create PDF files directly. These documents also contain enough information to allow developers to write PDF consumer applications that read existing PDF files and interpret or modify their contents.

The Document management - PDF - Part 1 First Edition is an ISO approved copy of the ISO 32000-1 Standards document. By agreement with ISO, Adobe Systems Incorporated is allowed to offer this version of the ISO standard as a free PDF file on their web site. It is not an official ISO document but the technical content is identical including the section numbering and page numbering.

 

Was this article helpful?
Yes No Somewhat