Forum rules DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
I am adding a PDF document as an image and what I want to do is add the date and time under the image, and I was hoping you could advise how to do this.
Below is the following code that I am using to add the image:
Dim nID As Integer = MISData.Instance.frmMain.docPreview.Inst.Str2ID("op.document.addImage", False)
Dim Op As PDFXEdit.IOperation = MISData.Instance.frmMain.docPreview.Inst.CreateOp(nID)
Dim input As PDFXEdit.ICabNode = Op.Params.Root("Input")
input.v = MISData.Instance.frmMain.docPreview.Doc
Dim options As PDFXEdit.ICabNode = Op.Params.Root("Options")
options("Page").v = 0
options("Pos.top").v = areaTop
options("Pos.left").v = areaLeft
options("Pos.right").v = areaRight
options("Pos.bottom").v = areaBottom
options("AlignMode").v = 1
options("AsStamp").v = False
Dim fsInst As PDFXEdit.IAFS_Inst = CType(MISData.Instance.frmMain.docPreview.Inst.GetExtension("AFS"), PDFXEdit.IAFS_Inst)
Dim destPath As PDFXEdit.IAFS_Name = fsInst.DefaultFileSys.StringToName(Application.StartupPath & "\Resources\MasterStamp.pdf")
options("Src").v = destPath
Op.Do()
Also, if possible could you point me to the code section (once you give me the link) to place PDF document text, or textbox I'll use the flatten annots command if nneded.
I have had a look at the Core API demo project that zarko kindly pointed me towards, thank you for your help. I am however still facing an issue with placing the text, the below gives no error, but however does not write any text to the PDF.
Obviously doing something wrong, and was hoping you would be able to assist.
Dim rc As PXC_Rect = Nothing
rc.top = 600
rc.left = 600
rc.bottom = 500
rc.right = 500
Dim nID As Integer = Me.docPreview.Inst.Str2ID("op.document.addImage", False)
Dim Op As PDFXEdit.IOperation = Me.docPreview.Inst.CreateOp(nID)
Dim input As PDFXEdit.ICabNode = Op.Params.Root("Input")
input.v = Me.docPreview.Doc
Dim options As PDFXEdit.ICabNode = Op.Params.Root("Options")
options("Page").v = 0
options("Pos.top").v = rc.top
options("Pos.left").v = rc.left
options("Pos.right").v = rc.right
options("Pos.bottom").v = rc.bottom
options("AlignMode").v = 1
options("AsStamp").v = True
Dim fsInst As PDFXEdit.IAFS_Inst = CType(Me.docPreview.Inst.GetExtension("AFS"), PDFXEdit.IAFS_Inst)
Dim destPath As PDFXEdit.IAFS_Name = fsInst.DefaultFileSys.StringToName(Application.StartupPath & "\Resources\MasterStamp.pdf")
options("Src").v = destPath
Op.Do()
' Not sure what the below code is used for from the API Core demo?
'Dim x As Double = 1 * 72.0
'Dim y As Double = rc.top - 1 * 72.0
'Dim xs As Double = 3.5 * 72.0
'Dim ys As Double = 1 * 72.0
'Dim ts As Double = 0.45 * 72.0
Dim Font As PDFXEdit.IPXC_Font = Me.docPreview.Doc.CoreDoc.CreateNewFont("ArialMT", 0, 400)
Dim fntsize As Double = 50.0
Dim text As String = "Text Rendering Mode"
Dim nWidth As Double = 0.0
Dim nHeight As Double = 0.0
Dim cc As IPXC_ContentCreator = Me.docPreview.Doc.CoreDoc.CreateContentCreator()
Dim color As PDFXEdit.IColor = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB)
color.SetRGB(0.0F, 0.0F, 0.0F)
cc.SetFillColorRGB(color.RGB)
color.SetRGB(1.0F, 0.0F, 0.0F)
cc.SetStrokeColorRGB(color.RGB)
cc.SaveState()
cc.RestoreState()
cc.SetTextRenderMode(PXC_TextRenderingMode.TRM_None)
cc.SetFont(Font)
cc.SetFontSize(fntsize)
cc.SetTextScale(150)
cc.CalcTextSize(fntsize, text, nWidth, nHeight, -1)
cc.ShowTextLine(rc.left, rc.top, text, -1, CInt(PXC_ShowTextLineFlags.STLF_Baseline))
cc.Detach()
cc.RestoreState()
Dim rc As PXC_Rect = Nothing
rc.top = 700
rc.bottom = 300
rc.left = 100
rc.right = 500
Dim imageSrc As String = Application.StartupPath & "\Resources\MasterStamp.pdf"
Dim textUnderImage As String = "The Text Under Image"
' Add Image
Try
Dim opID As Integer = Me.docPreview.Inst.Str2ID("op.document.addImage", False)
Dim Op As PDFXEdit.IOperation = Me.docPreview.Inst.CreateOp(opID)
Dim input As PDFXEdit.ICabNode = Op.Params.Root("Input")
input.v = Me.docPreview.Doc
Dim options As PDFXEdit.ICabNode = Op.Params.Root("Options")
options("Page").v = 0
options("Pos.top").v = rc.top
options("Pos.left").v = rc.left
options("Pos.right").v = rc.right
options("Pos.bottom").v = rc.bottom
options("AlignMode").v = 1
options("AsStamp").v = False
Dim fsInst As PDFXEdit.IAFS_Inst = CType(Me.docPreview.Inst.GetExtension("AFS"), PDFXEdit.IAFS_Inst)
Dim imageSrcPath As PDFXEdit.IAFS_Name = fsInst.DefaultFileSys.StringToName(imageSrc)
options("Src").v = imageSrcPath
Op.Do()
Catch ex As Exception
End Try
' Add Text Under Image
Try
' Create text-content
Dim font As PDFXEdit.IPXC_Font = Me.docPreview.Doc.CoreDoc.CreateNewFont("ArialMT", 0, 400)
Dim fontSize As Double = 24.0
Dim textWidth As Double = 0.0
Dim textHeight As Double = 0.0
Dim cc As IPXC_ContentCreator = Me.docPreview.Doc.CoreDoc.CreateContentCreator()
Dim color As PDFXEdit.IColor = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB)
color.SetRGB(0.0F, 0.0F, 0.0F)
cc.SetFillColorRGB(color.RGB)
color.SetRGB(1.0F, 0.0F, 0.0F)
cc.SetStrokeColorRGB(color.RGB)
cc.SetTextRenderMode(PXC_TextRenderingMode.TRM_FillStroke)
cc.SetFont(font)
cc.SetFontSize(fontSize)
cc.CalcTextSize(fontSize, textUnderImage, textWidth, textHeight)
Dim textX As Double = (rc.left + rc.right - textWidth) / 2 ' to center label horizontally
Dim textY As Double = rc.bottom - 5
cc.ShowTextLine(textX, textY, textUnderImage, -1, CInt(PXC_ShowTextLineFlags.STLF_Top))
Dim textCon As PDFXEdit.IPXC_Content = cc.Detach()
' Append just created text-content to the existing page-content
Dim opID As Integer = Me.docPreview.Inst.Str2ID("op.addContent", False)
Dim Op As PDFXEdit.IOperation = Me.docPreview.Inst.CreateOp(opID)
Dim input As PDFXEdit.ICabNode = Op.Params.Root("Input")
input.Add().v = Me.docPreview.Doc
Dim options As PDFXEdit.ICabNode = Op.Params.Root("Options")
options("TargetPage") = 0
options("Content").v = textCon
Op.Do()
Catch ex As Exception
End Try
Sorry for possible syntax-issues, because I'm not a very good VisualBasic specialist. And I used Try/EndTry blocks to organize logical scopes in code...