Add text under image

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

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.
Post Reply
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Add text under image

Post by lidds »

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:

Code: Select all

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()
Thanks in advance

Simon
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Add text under image

Post by lidds »

I was wondering if anyway could help on this?

Thanks

Simon
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Add text under image

Post by zarkogajic »

Hi Simon,

"add the date and time under the image"

Like text item?

If so, check Core demo on GitHub on how to add items (/text) on a page...

-žarko
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Add text under image

Post by lidds »

Hi žarko,

Could you please give me the link to the core demo, I have the fulldemo, and using the below link it does not seem to contain a CoreDemo project:

https://github.com/tracker-software/PDFEditorSDKExamples/tree/master/CSharp

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.

Thanks for your help

Simon
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Add text under image

Post by zarkogajic »

Simon,

https://github.com/tracker-software/PDFCoreSDKExamples

Add content: https://github.com/tracker-software/PDFCoreSDKExamples/blob/master/CSharp/CoreAPIDemo/Content.cs

p.s.
I guess you know: CoreAPI is part of SDK api - so no need to also install Core dll, just request ipxc instance from ipxv:

pxcInst = (PDFXEdit.IPXC_Inst)pdfCtl.Inst.GetExtension("PXC");

User avatar
Paul - Tracker Supp
Site Admin
Posts: 6829
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

Re: Add text under image

Post by Paul - Tracker Supp »

Thanks for helping out there Zarko!
Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Add text under image

Post by lidds »

Hi zarkogatic & Tracker support,

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.

Code: Select all

		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()
Thanks

Simon
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Add text under image

Post by Vasyl-Tracker Dev Team »

Hi lidds.

Here is 'refined' code sample to place the text under image:

Code: Select all

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...

HTH.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Add text under image

Post by lidds »

Thank you so much this worked perfectly.

Simon
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17820
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Add text under image

Post by Tracker Supp-Stefan »

:)
Post Reply