Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.
Fri May 22, 2020 2:49 pm
Hello, how are you?
I'm working on a searchable pdf creation process.
I already have the OCR process and I can extract the text from the images.
However, how could I do to create an invisible text layer on a pdf page with spire? Can I do this with the API?
Thank you for your attention!
-

gafforelli
-
- Posts: 37
- Joined: Sat Sep 15, 2018 6:38 pm
Mon May 25, 2020 1:57 am
Hello,
Thanks for your inquiry and sorry for the late reply as weekend.
Please refer to the code below. If there is any question, please provide your input file as well as your expected output for reference.
- Code: Select all
Dim doc As PdfDocument = New PdfDocument
doc.LoadFromFile("test.pdf")
Dim page As PdfPageBase = doc.Pages(0)
Dim font As PdfTrueTypeFont = New PdfTrueTypeFont(New Font("Arial", 20, FontStyle.Regular))
Dim layer As PdfLayer = doc.Layers.AddLayer("text", PdfVisibility.Off)
Dim pcA As PdfCanvas = layer.CreateGraphics(doc.Pages(0).Canvas)
Dim pf As PdfStringFormat = New PdfStringFormat
'draw text
pcA.DrawString("Spire.PDF for .NET", font, New PdfPen(PdfBrushes.Red, 1), New PointF(20, 20))
'save the document to file
doc.SaveToFile("AddLayers.pdf", FileFormat.PDF)
Sincerely,
Rachel
E-iceblue support team
-


rachel.lei
-
- Posts: 1571
- Joined: Tue Jul 09, 2019 2:22 am