Hi
I don't have a Printer at the moment, I was using a Brother Thermal Label Printer and always managed to code for it quite straightforwardly.
I have posted here some code that I created as an answer to a previous question and, I think I tested it on the Printer I mentioned. Of couse, you have no need for the overall function f this code to print contents of a folder.
Anyway, I suspect that you already know how to do all that I show here, but the main point of interest for your question may be the Doc.Settings at line 26, where you may find if your Printer is actually set to the various size that you expect/think that it is. Worth a look anyway.
' Print all files if a folder
' either PDF or XPS
Option Strict On
Option Explicit On
Imports System.Drawing.Printing
Public Class Form1
Dim WithEvents PDoc As New PrintDocument
' Dim PrinterName As String = "Microsoft XPS Document Writer"
Dim PrinterName As String = "Microsoft Print to PDF"
Dim stringToPrint As String = String.Empty
'Dim stringToPrint As String = IO.File.ReadAllText("C:\Users\lesha\Desktop\TestDoc.txt")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
StartPrint(My.Computer.FileSystem.SpecialDirectories.Desktop)
Close()
End Sub
Sub StartPrint(f As String)
Dim OutFile As String = String.Empty
For Each d As String In IO.Directory.GetFiles(f, "*.txt")
stringToPrint = IO.File.ReadAllText(d)
Dim exten As String = ".txt"
If PrinterName.Contains("Print to PDF") Then exten = ".pdf"
OutFile = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "TestData", IO.Path.GetFileNameWithoutExtension(d) & exten)
With PDoc
With .PrinterSettings
.PrinterName = PrinterName
.PrintFileName = OutFile
.Copies = 1
.PrintToFile = True
End With
.Print()
End With
Next
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PDoc.PrintPage
' This example Prints the Text from a text
' File. It can be made to print anything
' you just have to tell it what needs to
' be Printed (and take care of any further
' pages to be printed)
' ******* FROM MS DOCS *******
Dim charactersOnPage As Integer = 0
Dim linesPerPage As Integer = 0
' Sets the value of charactersOnPage to the number of characters
' of stringToPrint that will fit within the bounds of the page.
e.Graphics.MeasureString(stringToPrint, Me.Font, e.MarginBounds.Size,
StringFormat.GenericTypographic, charactersOnPage, linesPerPage)
' Draws the string within the bounds of the page
e.Graphics.DrawString(stringToPrint, Me.Font, Brushes.Black,
e.MarginBounds, StringFormat.GenericTypographic)
' Remove the portion of the string that has been printed.
stringToPrint = stringToPrint.Substring(charactersOnPage)
' Check to see if more pages are to be printed.
e.HasMorePages = stringToPrint.Length > 0
End Sub
End Class