Solved

Reading string from PDF without searching whole file.

Posted on 2008-06-20
12
239 Views
Last Modified: 2013-11-26
I am trying to strip a row of characters out of a PDF.  I have code that I obtained from this site, and it works well, but it loops through the whole file.  I would like to be able to stip characters from a certain part of the file everytime just to obtain an account number that constantly changes with each file.
0
Comment
Question by:thomashospital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 21832227
You say...' I would like to be able to strip characters from a certain part of the file everytime just to obtain an account number that constantly changes with each file.'
Do you want to replace a account number?
do you want to just read account number ?
what are you wanting to do?
0
 

Author Comment

by:thomashospital
ID: 21832771
Sorry, I am wanting to read the account num into a variable then rename the file to match the account number.
0
 

Author Comment

by:thomashospital
ID: 21832797
I am pretty sure I can figure out the file rename part and if I cant I will ask in another question.  I just want to read the account number from the pdf at a certain location.
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 27

Expert Comment

by:planocz
ID: 21833281
what are you using to read the PDF file?
0
 

Author Comment

by:thomashospital
ID: 21833377
I have something called pdfbox.
0
 
LVL 27

Expert Comment

by:planocz
ID: 21833613
Do you have a pdf file that I can test with?
0
 

Author Comment

by:thomashospital
ID: 21837892
I will create a testing pdf.  How can I get it to you.
0
 
LVL 27

Expert Comment

by:planocz
ID: 21845855
I have not looked but there is a way to post a file on EE for people to read.
0
 

Author Comment

by:thomashospital
ID: 21984870
It turns out that our problems run deeper than this solution.  Also I was having problems editing a PDF without posting patient information.  Do you have any example code that shows how to extract a string from any PDF so I can go ahead and give you the points for the solution?
0
 
LVL 27

Expert Comment

by:planocz
ID: 21997378
All of the examples I have are made from the full version of Adobe Acrbat which can read all parts of a PDF file.
0
 

Author Comment

by:thomashospital
ID: 22088288
That is fine.
0
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 22131233
Sample code with a test file..
'FORM 1
Imports Microsoft.VisualBasic
Public Class frmW9
    Inherits System.Windows.Forms.Form
 
#Region " Windows Form Designer generated code "
 
    Public Sub New()
        MyBase.New()
 
        'This call is required by the Windows Form Designer.
        InitializeComponent()
 
        'Add any initialization after the InitializeComponent() call
 
    End Sub
 
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
 
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
 
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Public WithEvents PdfRpt As AxPdfLib.AxPdf
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmW9))
        Me.Label1 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.PdfRpt = New AxPdfLib.AxPdf
        CType(Me.PdfRpt, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(4, 12)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(40, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Name:"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(56, 8)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(168, 20)
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = ""
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(184, 96)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "Start"
        '
        'PdfRpt
        '
        Me.PdfRpt.Enabled = True
        Me.PdfRpt.Location = New System.Drawing.Point(12, 72)
        Me.PdfRpt.Name = "PdfRpt"
        Me.PdfRpt.OcxState = CType(resources.GetObject("PdfRpt.OcxState"), System.Windows.Forms.AxHost.State)
        Me.PdfRpt.Size = New System.Drawing.Size(100, 50)
        Me.PdfRpt.TabIndex = 3
        Me.PdfRpt.Visible = False
        '
        'frmW9
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 145)
        Me.Controls.Add(Me.PdfRpt)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label1)
        Me.Name = "frmW9"
        Me.Text = "frmW9"
        CType(Me.PdfRpt, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
 
    End Sub
 
#End Region
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CheckFiles()
        AddData()
    End Sub
    Private Sub frmw9_Resize(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Resize
        PdfRpt.SetBounds(0, 0, Me.ClientRectangle.Width - 15, Me.ClientRectangle.Height - 15)
    End Sub
    Private Sub AddData()
        If TextBox1.Text = String.Empty Then Exit Sub
        FdfAcX = New FDFACXLib.FdfApp
        FdfDoc = FdfAcX.FDFCreate
        W9_Page1()
        PDFView()
    End Sub
    Private Sub PDFView()
        SavePDF()
        'show PDF file here
        With Me
            .PdfRpt.Visible = True
            .PdfRpt.setShowToolbar((True))
            .PdfRpt.LoadFile(sPDFPath)
            Cursor.Current = Cursors.Default
            .Show()
        End With
        Me.WindowState = FormWindowState.Maximized
    End Sub
    Public Sub SavePDF()
        Cursor.Current = Cursors.WaitCursor
 
        sPDFPath = sAppPath & "\Acrobat\W9Test.PDF"
 
        FdfDoc.FDFSaveToFile(sFDFPath)
        FdfDoc.FDFClose()
        FdfDoc = Nothing
        FdfAcX = Nothing
 
        AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
        bOK = AcroExchAVDoc.Open(sFDFPath, "")
        AcroExchPDDoc = AcroExchAVDoc.GetPDDoc
        ' bOK = AcroExchPDDoc.Save(Acrobat.__MIDL___MIDL_itf_acrobat_0000_0005.PDSaveFull, sPDFPath)
        bOK = AcroExchPDDoc.Save(1, sPDFPath)
        AcroExchPDDoc.Close()
        AcroExchAVDoc.Close(True)
        Cursor.Current = Cursors.Default
    End Sub
    Public Sub W9_Page1()
        iCount = 1 'FOR TESTING
        'HERE is where you add your fields
        With FdfDoc
            ' ADD Template to your Form--- On Adobe Acrobat Menu goto the Tools,Forms
            'then to page Templates... create a template name...W9_page_1
            .FDFAddTemplate(True, sMasterPath & "fW9.pdf", "W9_page_1", True)
            .FDFSetValue("f1-" & (iCount), TextBox1.Text.ToString, False)
        End With
    End Sub
 
End Class

Open in new window

W9Test.PDF
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question