Writing text on the middle of a page of an existing PDF

Discussions about PDF management.
Post Reply
User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Writing text on the middle of a page of an existing PDF

Post by Loïc » Sat Dec 17, 2011 12:29 pm

Code: Select all

        Dim oGdPicturePDF As New GdPicture.GdPicturePDF
        Dim text As String = "Hello World!"
        Dim textSize As Single = 12
        oGdPicturePDF.LoadFromFile("c:\TWAIN_2_1_Spec.pdf", False)
        Dim pageWidth As Single = oGdPicturePDF.GetPageWidth 'Be careful: this function returns value in PDF points unit
        Dim pageHeight As Single = oGdPicturePDF.GetPageHeight 'Be careful: this function returns value in PDF points unit
        Dim fontResName As String = oGdPicturePDF.AddTrueTypeFont("Arial", False, False, False)
        oGdPicturePDF.SelectPage(1)
        oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitPoint)
        oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
        oGdPicturePDF.SetTextSize(textSize)
        Dim textWidth As Single = oGdPicturePDF.GetTextWidth(fontResName, textSize, text)
        oGdPicturePDF.DrawText(fontResName, pageWidth / 2 - textWidth / 2, pageHeight / 2, text)
        oGdPicturePDF.SaveToFileInc("c:\newpdf.pdf")
        oGdPicturePDF.CloseDocument()

Gabriela
Posts: 436
Joined: Wed Nov 22, 2017 9:52 am

Re: Writing text on the middle of a page of an existing PDF

Post by Gabriela » Tue Apr 02, 2019 7:41 am

You can find the refreshed example in the Reference guide here:
DrawText Method (GdPicturePDF)

Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 1 guest