Page 1 of 1

Flattening with PDFXEditCore.x86.dll

Posted: Wed Jun 12, 2019 1:31 pm
by sbensen

We have a license for PDFXEditCore.x86.dll.

Would like to know whether this dll will support the flattening operation. If so, can you please send the usage of it. A sample code will help.


Re: Flattening with PDFXEditCore.x86.dll

Posted: Wed Jun 12, 2019 8:43 pm
by sbensen
Is there any way we can programmatically achieve the UI functionality of Comments->flattening, with any API calls?

We have license for the PDFXEdit version of the dll. It is highly appreciated if you can tell a way to do this using the PDF Xchange editor API’s. The below code is written in

Dim filename As String = "C:\pdf-to-flatten.pdf"
Dim filename2 As String = "C:\flattened.pdf"

Dim m_CurDoc As PDFXCoreAPI.IPXC_Document
Dim pdfInst As PDFXCoreAPI.PXC_Inst
Dim acroForm As PDFXCoreAPI.IPXC_AcroForm

pdfInst = New PDFXCoreAPI.PXC_Inst()

m_CurDoc = pdfInst.OpenDocumentFromFile(filename, Nothing)
acroForm = m_CurDoc.AcroForm()

acroForm.FlattenAllFields() 'this line should flatten the PDF but the saved PDF(flattened.pdf) is not flatten. How can we achieve this?

Re: Flattening with PDFXEditCore.x86.dll

Posted: Thu Jun 13, 2019 6:34 am
by Sasha - Tracker Dev Team
Hello sbensen,

Try using the Editor SDK's ... ts_flatten operation. There is a code sample on how to use that.


Re: Flattening with PDFXEditCore.x86.dll

Posted: Thu Sep 19, 2019 2:16 am
by sbensen
A response to this post was this link ... ts_flatten.

But how can I open a PDF from a filepath, flatten it and save the file. Is this possible in PDFXedit?

If possible can you provide the code , I need to accomplish something similar to this.

Dim doc As PDFXEdit.IPXV_Document = Nothing
Dim strPDFFileName As String = String.Empty
Dim pSInt As PDFXEdit.IPXS_Inst
Dim inst As PDFXEdit.PXV_Inst
Dim pagesCnt, i, j As UInt64
Dim annot As PDFXEdit.IPXC_Annotation
Dim page As PDFXEdit.IPXC_Page
Dim nSquareAtom As UInteger
Dim annotsCnt As UInteger
Dim nID As Integer
Dim op As PDFXEdit.IOperation
Dim input As PDFXEdit.ICabNode
Dim options As PDFXEdit.ICabNode
strPDFFileName = "C:\Files\samplefile.pdf"
doc = oPDFCtrl.Inst.Doc(0)

inst = New PDFXEdit.PXV_Inst
pSInt = inst.GetExtension("PXS")

nSquareAtom = pSInt.StrToAtom("Square")
nID = inst.Str2ID("op.annots.flatten", False)
op = inst.CreateOp(nID)
input = op.Params.Root("Input")

pagesCnt = doc.CoreDoc.Pages.Count
For i = 0 To pagesCnt
page = doc.CoreDoc.Pages(i)
annotsCnt = page.GetAnnotsCount()
For j = 0 To annotsCnt
annot = page.GetAnnot(j)
If (annot.Type = nSquareAtom) Then
input.Add().v = annot
End If

options = op.Params.Root("Options")
options("NonPrintableAction").v = "Flatten"
options("FieldsAction").v = "LeftAsIs".
Catch ex As Exception
End Try
End Sub


Re: Flattening with PDFXEditCore.x86.dll

Posted: Tue Sep 24, 2019 7:11 am
by Sasha - Tracker Dev Team
Hello sbensen,

The operation takes either the document or an array of the needed annotations. You will need the IPXV_Document or IPXC_Document depending on whether you need to open it visually or not. After using methods like OpenDocFromPath, you will obtain the needed interface that you need to pass as the operation's input. Then, fill of the needed options and launch the operation. After all of this - use the Write/Save method for the document and if you have opened it via the IPXC level, do not forget to Close() the document.