> For the complete documentation index, see [llms.txt](https://docs.swingsoftware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.swingsoftware.com/pdf-converter-for-notes/for-developers/lotusscript-code-samples/convert-large-number-of-documents.md).

# Convert large number of documents

This LotusScript agent code converts all documents from view in defined database. The code is suitable for views with large amount of documents.

```

Use "SwPDFMain"

Dim s As NotesSession
Dim db As NotesDatabase

Sub Initialize
	Dim view As NotesView
	Dim doc As NotesDocument
	Dim swPDF As SwPDFCreator, swPDFDoc As SwPDFDocument, swPDFErr As SwPDFError
	Dim OutputFilePath As String
	Dim counter As Long
	
	On Error GoTo Ooops
	
	Set s = New NotesSession
	MsgBox "Agent started!!"

	'Leave this if current db should be used 
	Set db = s.CurrentDatabase
	
	'Use this function to open remote database 
	'Set db = s.Getdatabase("Server", "File", Createonfail)
	
	' Get documents from this database view
	Set view = db.Getview("(($All))")
    Counter = 0
    
	Set swPDF = New SwPDFCreator()
	swPDF.Init("LICENCE KEY HERE")	
	swPDF.PDFSettings.useLowLevelRenderer = True
	
	'Set this to false to avodid download of Internet content.
	'This includes HTML newsletter images and other data that might slow down conversion.
	'Image placeholder is shown instead of real image. 
	swPDF.PDFSettings.EnableHTTPStream = true
	
	Set doc = view.Getfirstdocument()
	While Not(doc Is Nothing)
		Counter = Counter + 1
		
		MsgBox "Processing document " & Counter & " / " & view.Entrycount

		' ***************Set your file path here!*********************
		OutputFilePath = "d:\convertedPDF\" & doc.UniversalID & ".pdf"	
		'*************************************************************		
		Set swPDFDoc = swPDF.ProcessDocument(doc)
		
		If(Not swPDFDoc Is Nothing) Then
			Call swPDFDoc.SaveToFile(OutputFilePath)
		Else
			' There was an error in PDF conversion
			Set swPDFErr = swPDF.GetError()
		End If
		
		'File verification
		If FileExists(OutputFilePath) = false Then
			' There is no output file, so let's log this
			Call logError("File verification failed", doc)
		End If
		
		Set doc = view.GetNextDocument(doc)
	Wend
	Exit Sub

Ooops:
	Msgbox "Error on line " & Erl & " Description: " & Error
	Resume Next
End Sub

Function logError(ErrMsg As String, docSrc As NotesDocument) As Boolean
	Dim docLog As NotesDocument
	
	Set docLog = db.CreateDocument
	
	Call docLog.ReplaceItemValue("Form", "SwErrorLog")
	Call docLog.ReplaceItemValue("ErrorMessage", ErrMsg)
	
	If Not docSrc Is Nothing Then
		Call docLog.ReplaceItemValue("SourceDbServer", docSrc.ParentDatabase.Server)
		Call docLog.ReplaceItemValue("SourceDbPath", docSrc.ParentDatabase.FilePath)
		Call docLog.ReplaceItemValue("SourceDbTitle", docSrc.ParentDatabase.Title)
		Call docLog.ReplaceItemValue("SourceDocUNID", docSrc.UniversalID)
		Call docLog.ReplaceItemValue("SourceDocForm", docSrc.Form(0))
'		docLog.replaceItemValue("AlternateForm", SwPDFSettings.PDFAlternateForm)
	End If
		
	Call docLog.ReplaceItemValue("User", s.UserName)
'	docLog.replaceItemValue("PDFCVersion", SwPDFSettings.ProductVersion);
	Call docLog.ReplaceItemValue("NotesVersion", s.NotesVersion)
'	docLog.replaceItemValue("ConversionType", conversionType);
		
	Call docLog.save(True, True)
End Function


Function FileExists(sFileName As String) As Integer
 'Declare variables..
	Dim iPos As Integer, iPrevPos As Integer
	Dim sFile As String
	
 'Validate passed filename...
	iPos = 0
	Do
		iPrevPos = iPos
		iPos = InStr(iPos + 1, sFileName, "\")
		MsgBox iPos
	Loop Until iPos = 0
	iPos = iPrevPos
	
	sFile = Right$(sFileName, Len(sFileName) - iPos)
	
 'Check to see if file exists and return results...
	If Dir$(sFileName) = sFile Then
		FileExists = True
	Else
		FileExists = False
	End If
End Function
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.swingsoftware.com/pdf-converter-for-notes/for-developers/lotusscript-code-samples/convert-large-number-of-documents.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
