|
-
Dec 26th, 2023, 02:04 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Centre Paragraph Text using ItextSharp
I have been trying to centre text unsuccessfully for 2 days now so unfortunately i now need help from the pros.
I am using below example found in a youtube video to create a pdf file with text and image for a report app i am working on.
I can centre a image but no luck with cantering text horizontally in a pdf document.
I am thinking i may have to place text in a rectangle then possibly centre but not sure so thought i would ask here first.
ps, i am aware library is redundant but itext7 looks so confusing.
Any help or example much appreciated, thankyou
Code:
Dim pdfDoc As New iTextSharp.text.Document
Dim Sstring As String = DdirName
Dim DirToSavePdfTo As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\weights"
Dim DIR_String As String = DirToSavePdfTo & "\" & Sstring & "\" & Sstring & " Weight Report.pdf"
Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream(DIR_String, FileMode.Create))
pdfDoc.Open()
pdfDoc.Add(New iTextSharp.text.Paragraph("Some text"))
pdfDoc.Add(New iTextSharp.text.Paragraph(" "))
'date and time
Dim t As Date = DateTime.Now.ToString()
pdfDoc.Add(New iTextSharp.text.Paragraph(t))
pdfDoc.Add(New iTextSharp.text.Paragraph(" "))
Dim RreportName As String = "Vehicle rego " & TxtVehicleRego.Text & " Van rego " & TxtVanRego.Text & " Report.pdf"
pdfDoc.Add(New iTextSharp.text.Paragraph(RreportName))
pdfDoc.Add(New iTextSharp.text.Paragraph(" "))
-
Dec 26th, 2023, 06:23 AM
#2
Re: Centre Paragraph Text using ItextSharp
I used a Paragraph object
Code:
Dim pdfParagraph As iTextSharp.text.Paragraph
and then set the alignment of that object , have you tried this approach?
Code:
pdfDoc.Open()
pdfParagraph = New iTextSharp.text.Paragraph
pdfParagraph.Alignment = 1
pdfParagraph.Add("Some Text")
pdfDoc.Add(pdfParagraph)
pdfParagraph = Nothing
pdfDoc.Close()
pdfDoc.Dispose()
-
Dec 26th, 2023, 06:34 PM
#3
Thread Starter
Frenzied Member
Re: Centre Paragraph Text using ItextSharp
-
Dec 27th, 2023, 06:34 AM
#4
Re: [RESOLVED] Centre Paragraph Text using ItextSharp
You're welcome, happy to help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|