Itext 7 Line Feed - itext7

Been trying to add a paragraph linefeed in Itext7. I've read where NEW TEXT("\n") will do it but it's not working.
Dim P As Paragraph = New Paragraph()
With P
.SetTextAlignment(TextAlignment.LEFT)
.SetFontSize(10)
.Add(New Text("My Company LLC. "))
.Add(New Text("\n"))
.Add(New Text("Company Address"))
End With
I'm looking for output of
My Company LLC.
Company Address
I'm getting "My Company LLC. \nCompany Address"
This is driviing mew nuts. WOuld the cure be to use SetFixedPosition?
Thanks
-dan

Still havent found a linefeed option but this works for me.
Dim L1 As Paragraph = New Paragraph(New Text("My Company. ")).SetFixedPosition(50, 800, 600)
Dim L2 As Paragraph = New Paragraph(New Text("My Address ")).SetFixedPosition(50, 790, 600)
Then I just added them to the document and whola it works.

Found a post by: Metro Smurf.
Add(Environment.NewLine) works great (I'm Using itext7)
Dim p2 = New Paragraph()
p2.Add("Dan Tester")
p2.Add(Environment.NewLine)
p2.Add("123 Main St. Suite 3")
p2.Add(Environment.NewLine)
p2.Add("Midlife USA, XXXXX")
p2.SetPaddingBottom(50)
document.Add(p2)
Then add the new paragraph (even in a cell) and all is well.

Related

How to change the fontstyle without creating a new font?

I'm trying to do something that's probably incredibly simple, yet everything I'm trying doesn't seem to work.
I'm making a windows forms app that just lets you preview some custom text using a hand full of different fonts.
What I'm trying to do is change the fontstyle of the label to italics if and when the checkbox is checked. While retaining the current font that it is.
"Display" is the name of my label. "Italicscb" is the name of the check box.
Below is the code I'm currently using:
Private Sub Italicscb_CheckedChanged(sender As Object, e As EventArgs) Handles
Italicscb.CheckedChanged
If Italicscb.CheckState = CheckState.Checked Then
Display.Font = New Font("Arial", 60, FontStyle.Italic)
Else
If Italicscb.CheckState = CheckState.Unchecked Then
Display.Font = New Font("Arial", 60, FontStyle.Bold)
End If
End If
End Sub
This works fine, but it requires me to enter a new font name. Which I don't want. I've tried to assign the current font a variable and plug that in, but that gives me an error.
Dim CF As Font
CF = Display.Font
If Italicscb.CheckState = CheckState.Checked Then
Display.Font = New Font(CF, 60, FontStyle.Italic)
Else
If Italicscb.CheckState = CheckState.Unchecked Then
Display.Font = New Font(CF, 60, FontStyle.Bold)
End If
End If
End Sub
I've also tried putting an if then loop in the individual font option buttons.
No errors, but nothing happens when I check the box.
if Italicscb.CheckState = CheckState.Checked Then
Display.Font = New Font("Freehand521 BT", 60, FontStyle.Italic)
Else
Display.Font = New Font("Freehand521 BT", 60, FontStyle.Bold)
End If
If anyone could point out what I'm doing wrong. I would really appreciate it.
I'm making this for my work by the way.
Thank you.
Image of my userform
First of all, use .Checked instead of .CheckState, so you avoid doing a lot of unnecessary checks:
If Italicscb.Checked Then
'Italic
Else
'Not italic
End If
Now, if you want only to change the fontStyle of Display (using an existing font name and size), you can create a new Font by using the constructor Font(Font, FontStyle), so your code will be:
Private Sub Italicscb_CheckedChanged(sender As Object, e As EventArgs) Handles Italicscb.CheckedChanged
If Italicscb.Checked Then
Display.Font = New Font(Display.Font, FontStyle.Italic)
Else
Display.Font = New Font(Display.Font, FontStyle.Regular)
End If
End Sub
It is also possible to obtain the same result with an elegant single line:
Private Sub Italicscb_CheckedChanged(sender As Object, e As EventArgs) Handles Italicscb.CheckedChanged
Display.Font = New Font(Display.Font, If(Italicscb.Checked, FontStyle.Italic, FontStyle.Regular))
End Sub
Here is the output:

With NPOI, set Word paragraph to Heading 1 style

When using NPOI to create a Word document, how does one set a paragraph to the built-in "Heading 1" style?
Here is what I have tried in F#:
let doc = XWPFDocument()
let p = doc.CreateParagraph()
p.Style <- "Heading 1"
let r = p.CreateRun()
r.SetText("Hello, world")
When I open the generated file in Word, the line "Hello, world" is not in the Heading 1 style.
Here is what I did:
Using Word,
Create a new Blank document.
Include a paragraph that has the style(s) of interest.
Save the document to your project folder.
In code using NPOI,
Load the blank document.
Delete the contents of the document.
Write to your document, setting the paragraph style with the styleId.
Here is an example:
use fsSrc = new FileStream("blank.docx", FileMode.Open, FileAccess.Read)
let doc = XWPFDocument(fsSrc)
while doc.RemoveBodyElement(0) do ()
let p = doc.CreateParagraph()
p.Style <- "Heading1"
let r = p.CreateRun()
r.SetText("Hello, world")
Today I learned...
The default styles are not included when creating a new XWPFDocument().
The styles are identified by their styleId, not their user friendly names. The styleId for "Heading 1" is Heading1.

How put Image location dynamically Crystal report from byte array

My problem is simple but I don't find the solution.
I know how modifiy dynamically a picture when I've the path.
But In my project I collect signature of people. I don't want file (not secure enough) then I store it in database (I use signature_pad and server side I use
Dim dataUri = MesDonnees.Img
Dim encodedImage = dataUri.Split(",")(1)
Bdd.field = Convert.FromBase64String(encodedImage)
...
But I don't solve how put it in footer of my document...
I read some works but always it's from details section and I just have string type, number, boolean... not byte or something
Thanks for your help
UPDATE
I've an idea. Try to link this image to ashx file
Dim IdAtt As Long = CLng(HelperParams.GetParamURL("IdAttach"))
Dim Typ As Integer = CInt(HelperParams.GetParamURL("Typ"))
Dim LesDatas As New MyEntities
Dim Att As Attachement = GetMonAttachement(IdAtt, LesDatas)
If Att IsNot Nothing Then
context.Response.ContentType = "image/png"
If Typ = 1 Then
context.Response.BinaryWrite(Att.SignCollaborateur)
Else
If Att.SignClient Is Nothing Then
Dim Vid() As Byte = New Byte(0) {}
context.Response.BinaryWrite(Vid)
Else
context.Response.BinaryWrite(Att.SignClient)
End If
End If
context.Response.Flush()
context.Response.End()
End If
Catch ex As Exception
End Try
If I put in IE: http://localhost:63888/Signature.ashx?IdAttach=4&Typ=2
I've my picture
But I try to create SignClient parameter et assign it location (x-2)
cryRpt.SetParameterValue("SignClient", "~/Signature.ashx?IdAttach=4&Typ=2")
cryRpt.SetParameterValue("SignClient", HttpContext.Current.Server.MapPath("/Signature.ashx") & "?IdAttach=4&Typ=2")
cryRpt.SetParameterValue("SignClient", "http://localhost:63888/Signature.ashx?IdAttach=4&Typ=2")
This 3 methods don't work.
I try to put directly : http://localhost:63888/Signature.ashx?IdAttach=4&Typ=2 in location (x-2) of image tabs : idem
I put a break point to ashx, never reach. Then I open network tab developpement tool and my ashx never call.
I've an picture in header (logo) and I change picture location with a path file (e:/../logo.png) and it's good.
Someone have an idea?
Finally, after try and try, the only solution I find is
1/ to make subreport (my request return only 1 line)
2/ in subreport delete all section except details section
3/ Create a class with property Contenu as byte()
4/ Add datafield in subreport to this new class and drop the field in detail section
For signaturepad, just put backgroundcolor : rgb(255,255,255) but penColor : (1,1,1)
else (CR or acrobat) show black image.

Patagames PDFium scrolling with Keyboard

I'm a bit in need for some help. I'm trying to scroll a PDF in Patagames PDFium .net control using the keyboard. Unfortunately I can't get it to scroll correctly and am looking for some sample code (VB or C#) to scroll 'line wize (lets say 10 pixels per keypress)' and 'page wize'. Can anybody help me out here? TIA a lot. Ole
Never mind. Found an answer.
Private Sub PdfViewer1_KeyDown(sender As Object, e As KeyEventArgs) Handles PdfViewer1.KeyDown
Dim pageStep As Integer = PdfViewer1.AutoScrollMinSize.Height / PdfViewer1.Document.Pages.Count
Dim lineStep As Integer = pageStep / 30
Dim asp As Point = PdfViewer1.AutoScrollPosition
Select Case e.KeyCode
Case Keys.Up
PdfViewer1.AutoScrollPosition = New Point(asp.X, -asp.Y - lineStep)
Case Keys.Down
PdfViewer1.AutoScrollPosition = New Point(asp.X, -asp.Y + lineStep)
Case Keys.PageUp
PdfViewer1.AutoScrollPosition = New Point(asp.X, -asp.Y - pageStep)
Case Keys.PageDown
PdfViewer1.AutoScrollPosition = New Point(asp.X, -asp.Y + pageStep)
End Select
End Sub

Add image using itextsharp

I am trying to export data in PDF and now i try to add image in PDF using itext sharp i try this but this shows an error ..Is try below code but this shows an error when i add image in PDF file i successfully add text
Private Sub ExportGridToPDF()
Dim headerText As String = "file"
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
GridView1.AllowPaging = False
GridView1.DataBind()
GridView1.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New iTextSharp.text.Document(iTextSharp.text.PageSize.A1, 10.0F, 10.0F, 10.0F, 0.0F)
Dim beginning As New iTextSharp.text.Chunk(headerText)
Dim p1 As New iTextSharp.text.Phrase(beginning)
Dim p2 As New iTextSharp.text.Phrase()
p2.Add(p1)
Dim p As New iTextSharp.text.Paragraph()
p.Add(p2)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
pdfDoc.Add(p)
Dim im As Image = iTextSharp.text.Image.GetInstance(imagepath + "/mikesdotnetting.tif")
pdfDoc.Add(im)
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()
End Sub
in this part
Dim im As Image = iTextSharp.text.Image.GetInstance(imagepath + "/mikesdotnetting.tif")
pdfDoc.Add(im)
and this shows an error in this line
Dim jpg As Image = iTextSharp.text.Image.GetInstance(New Uri(url))
error
**Value of type 'iTextSharp.text.Image' cannot be converted to 'System.Web.UI.WebControls.Image'.**
Any Solution?
You are using two classes named Image from a different package / namespace in the same code. That is ambiguous. You should use fully qualified names.
I'm not a .Net developer, but if this were Java, you'd do something like this:
Dim im As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imagepath + "/mikesdotnetting.tif")
Your problem is caused by the fact that you create a variable jpg that is of type System.Web.UI.WebControls.Image, but you are assigning an object of type iTextSharp.text.Image to that variable. It is obvious that this doesn't work.
When you have two classes with the same name (Image) in two different namespaces System.Web.UI.WebControls and iTextSharp.text, you should avoid introducing ambiguities.
Read Resolving an ambiguous reference for more info.

Resources