Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Dia, Mes, Ano As Integer
- Public Data, Out_Path As String
- Public myf As Boolean
- Public Sub main()
- 'T_PDF_File = "C:\Users\Judah\Desktop\19-6-1990\DO-19-06-1990FL-1.pdf" 'Path & MyFile
- Each_Page = False 'Se "True", cria um txt para cada página do PDF
- Dim AC_PD As Acrobat.AcroPDDoc
- Dim AC_Hi As Acrobat.AcroHiliteList
- Dim AC_PG As Acrobat.AcroPDPage
- Dim AC_PGTxt As Acrobat.AcroPDTextSelect
- Dim OS_FSO As Object
- Dim OS_TxtFile As Object
- Dim Data, Path As String
- Dim MyFile, MyDir As String
- Dim sqline As Variant
- Out_Path = "C:\Users\Judah\Desktop\OUT\" 'Escolha a pasta para a saída dos txts
- Path = "C:\Lala\"
- MyDir = Dir(Path, vbDirectory)
- Do Until MyDir <> "." And MyDir <> ".."
- MyDir = Dir()
- Loop
- Dia = Left(MyDir, 2)
- If Len(Replace(Dia, "-", "")) = 1 Then
- Dia = Left(MyDir, 1)
- Mes = Mid(MyDir, 3, 2)
- If Len(Replace(Mes, "-", "")) = 1 Then
- Mes = Mid(MyDir, 3, 1)
- End If
- Else:
- Dia = Left(MyDir, 2)
- Mes = Mid(MyDir, 4, 2)
- If Len(Replace(Mes, "-", "")) = 1 Then
- Mes = Mid(MyDir, 4, 1)
- End If
- End If
- m = 3
- o = 1
- Ano = Right(MyDir, 4)
- Data = Dia & "-" & Mes & "-" & Ano
- 'Call cria_pasta 'Função tipo main para criação de subpastas
- Do Until MyDir = ""
- Dia = Left(MyDir, 2)
- If Len(Replace(Dia, "-", "")) = 1 Then
- Dia = Left(MyDir, 1)
- Mes = Mid(MyDir, 3, 2)
- If Len(Replace(Mes, "-", "")) = 1 Then
- Mes = Mid(MyDir, 3, 1)
- End If
- Else:
- Dia = Left(MyDir, 2)
- Mes = Mid(MyDir, 4, 2)
- If Len(Replace(Mes, "-", "")) = 1 Then
- Mes = Mid(MyDir, 4, 1)
- End If
- End If
- Ano = Right(MyDir, 4)
- Data = Dia & "-" & Mes & "-" & Ano
- MyFile = Dir(Path & MyDir & "\")
- If MyFile <> "" Then
- 'myf = False
- Call testa_file(MyFile)
- End If
- ' If MyFile <> "" Then
- ' Call cria_pasta
- ' End If
- If myf = False Then
- Do Until MyFile = ""
- Set OS_FSO = CreateObject("Scripting.filesystemobject")
- Dim Ct_Page As Long
- Dim i As Long, j As Long, k As Long
- Dim T_Str As String
- Dim Hld_Txt As Variant
- Set AC_PD = New Acrobat.AcroPDDoc
- Set AC_Hi = New Acrobat.AcroHiliteList
- AC_Hi.Add 0, 32767
- With AC_PD
- .Open Path & MyDir & "\" & MyFile
- Ct_Page = .GetNumPages
- ' If Ct_Page = -1 Then 'conta a quantidade de páginas
- ' MsgBox "Pages Cannot determine in PDF file '" & T_PDF_File & "'"
- ' .Close
- ' GoTo h_end
- ' End If
- ' If Each_Page = False Then
- ' Set OS_TxtFile = OS_FSO.createtextfile(Out_Path & Replace(MyFile, ".pdf", ".txt")) 'Ano & "\" & Mes & "\" & Data & "\" & Replace(MyFile, ".pdf", "") & ".txt") 'cria o arquivo txt
- ' End If
- For i = 1 To Ct_Page
- T_Str = ""
- Set AC_PG = .AcquirePage(i - 1)
- Set AC_PGTxt = AC_PG.CreateWordHilite(AC_Hi)
- If Not AC_PGTxt Is Nothing Then
- With AC_PGTxt
- For j = 0 To .GetNumText - 1
- 'T_Str = T_Str & .GetText(j)
- sqline = sqline & .GetText(j)
- t1 = Replace(sqline, Chr(10), "")
- Next j
- End With
- End If
- Call exportasql(t1, MyFile)
- t1 = ""
- sqline = ""
- ' If T_Str = "" Then T_Str = "No text found in page " & i
- '
- ' If Each_Page = True Then
- ' Set OS_TxtFile = OS_FSO.createtextfile(Out_Path & "\Page-" & i & ".txt")
- ' OS_TxtFile.write t1
- ' OS_TxtFile.Close
- ' Set OS_TxtFile = Nothing
- ' Else
- ' T_Str = vbCrLf & vbCrLf & "Text In Page - " & i & vbCrLf & vbCrLf & T_Str
- ' OS_TxtFile.write t1
- ' End If
- Next i
- 'If Each_Page = False Then OS_TxtFile.Close
- .Close
- End With
- MyFile = Dir(Path & MyDir & "\")
- For n = 1 To o
- MyFile = Dir()
- Next
- o = o + 1
- Loop
- End If
- MyDir = Dir(Path, vbDirectory)
- For l = 1 To m
- MyDir = Dir()
- Next
- m = m + 1
- o = 1
- 'Dia = Dia + 1
- 'Call cria_pasta
- Loop
- h_end:
- Set OS_TxtFile = Nothing
- Set OS_FSO = Nothing
- Set AC_PGTxt = Nothing
- Set AC_PG = Nothing
- Set AC_Hi = Nothing
- Set AC_PD = Nothing
- End Sub
- Function cria_pasta()
- If Dia <> 32 Then
- If Ano <> tAno Then 'Checa se já existe a subpasta do ano a ser rodado
- Call cria_ano(Ano)
- End If
- If Mes <> tMes Then 'Checa se já existe a subpasta do mes a ser rodado
- Call cria_mes(Mes)
- End If
- If Dia <> tDia Then 'Checa se já existe a subpasta do dia a ser rodado
- Data = Dia & "-" & Mes & "-" & Ano
- Call cria_dia(Data)
- End If
- 'Iguala variáveis temporárias às atuais para serem utilizadas quando a função for chamada novamente
- tDia = Dia
- tMes = Mes
- tAno = Ano
- End If
- End Function
- Function cria_ano(ByVal vAno As String)
- nPath = Out_Path & vAno & "\"
- If Dir(nPath, vbDirectory) = "" Then
- MkDir nPath
- End If
- End Function
- Function cria_mes(ByVal vMes As String)
- nPath = Out_Path & Ano & "\" & vMes & "\"
- If Dir(nPath, vbDirectory) = "" Then
- MkDir nPath
- End If
- End Function
- Function cria_dia(ByVal vDia As String)
- nPath = Out_Path & Ano & "\" & Mes & "\" & vDia & "\"
- If Dir(nPath, vbDirectory) = "" Then
- MkDir nPath
- End If
- End Function
- Function exportasql(ByVal line As Variant, ByVal file As String)
- Dim conexao As ADODB.Connection
- Set conexao = New ADODB.Connection
- Dim cquery, cquery2 As Variant
- strconexao = "Provider=SQLOLEDB.1;" & _
- "Persist Security Info=False;" & _
- "Initial Catalog=OD;" & _
- "Data Source=DESKTOP-GG4VVAA\;" & _
- "User ID=sa;Password=asdf1234;"
- conexao.ConnectionString = strconexao
- conexao.Open
- cquery = "INSERT INTO [dbo].[TEST1] "
- cquery = cquery & "([ANO]"
- cquery = cquery & ",[MES]"
- cquery = cquery & ",[DIA]"
- cquery = cquery & ",[NOME_ARQ]"
- cquery = cquery & ",[CONTEUDO])"
- cquery2 = "VALUES"
- cquery2 = cquery2 & "(" & Ano
- cquery2 = cquery2 & "," & Mes
- cquery2 = cquery2 & "," & Dia
- cquery2 = cquery2 & ",'" & file & "'"
- cquery2 = cquery2 & ",'" & Replace(line, "'", "") & "')" 'Replace(line, "'", "")
- conexao.Execute cquery & cquery2 '& line & "')"
- conexao.Close
- End Function
- Function testa_file(ByVal file As String)
- Dim conexao As ADODB.Connection
- Set conexao = New ADODB.Connection
- Dim cquery, cquery2 As Variant
- Dim RST As New ADODB.Recordset
- strconexao = "Provider=SQLOLEDB.1;" & _
- "Persist Security Info=False;" & _
- "Initial Catalog=OD;" & _
- "Data Source=DESKTOP-GG4VVAA\;" & _
- "User ID=sa;Password=asdf1234;"
- conexao.ConnectionString = strconexao
- conexao.Open
- 'file = "LALALALA.pdf"
- Set RST = conexao.Execute("SELECT [NOME_ARQ] FROM [OD].[dbo].[TEST1] WHERE [NOME_ARQ] = '" & file & "'")
- 'file1 = RST("NOME_ARQ")
- If RST.BOF = True Then
- myf = False
- Else:
- myf = True
- End If
- RST.Close
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement