I started with creating the document and saving it and getting the results that I am expecting. When I change my program to just send the document to the printer the formatting is wrong. It is treating the carriage return line feed as a page break. The words are getting cut off around the margin. So instead of printing 2 pages I get 32 pages.
Any help would be appreciated!
Can you tell me why it is reading the crlf as a page break an/or how do I get around this? I tried to upload the word file but was not allowed.
- Code: Select all
Private Sub btnSpire_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSpire.Click
Dim dt As Orders.OrderDataDataTable
Dim dr As Orders.OrderDataRow
Dim da As New OrdersTableAdapters.OrderDataTableAdapter
Dim i As Integer
Dim j As Integer = 0
Dim sOrderID As String = ""
dt = da.GetOrderData()
Dim dialog As New PrintDialog()
dialog.AllowCurrentPage = True
dialog.AllowSomePages = True
dialog.UseEXDialog = True
Dim testDoc As New Document()
dr = dt.Rows(0)
addHeader(dr, testDoc)
addStaticRowHeader(testDoc)
For i = 0 To dt.Rows.Count - 1
dr = dt.Rows(i)
padProduct(dr)
addOrderData(dr, testDoc)
j += 1
'If j = 7 Then
If j = 6 Then
iPageNum += 1
Dim nextPageBody As New Section(testDoc)
Dim nextPageheaderParagraph As Documents.Paragraph = Nothing
If nextPageBody.Paragraphs.Count > 0 Then
nextPageheaderParagraph = nextPageBody.Paragraphs(0)
Else
nextPageheaderParagraph = nextPageBody.AddParagraph()
End If
nextPageBody = testDoc.Sections.LastItem
nextPageheaderParagraph.AppendBreak(BreakType.PageBreak)
addHeader(dr, testDoc)
addStaticRowHeader(testDoc)
j = 0
End If
sOrderID = dr.ORDER_ID
Next i
testDoc.SaveToFile(My.Application.Info.DirectoryPath & "\" & sOrderID & "TEST.doc", FileFormat.Doc)
System.Diagnostics.Process.Start(My.Application.Info.DirectoryPath & "\" & sOrderID & "TEST.doc")
'testDoc.PrintDialog = dialog
'dialog.Document = testDoc.PrintDocument
'dialog.Document.PrintController = New StandardPrintController()
'dialog.Document.Print()
Application.Exit()
End Sub
Private Sub addHeader(ByVal dr As Orders.OrderDataRow, ByRef testDoc As Document)
Dim pageHeader As String
Dim phoneformatPattern As String = "(\d{3})(\d{3})(\d{4})"
Dim strFormattedPhone As String
Dim addy2 As String = ""
Dim body As Section
body = testDoc.AddSection()
body.PageSetup.Orientation = Documents.PageOrientation.Landscape
body.PageSetup.Margins.Top = 0.25F
body.PageSetup.Margins.Bottom = 0.5F
body.PageSetup.Margins.Left = 0.5F
body.PageSetup.Margins.Right = 0.25F
body.PageSetup.DefaultTabWidth = 0.5F
'Create a new paragraph or get the first paragraph
Dim headerParagraph As Documents.Paragraph = Nothing
If body.Paragraphs.Count > 0 Then
headerParagraph = body.Paragraphs(0)
Else
headerParagraph = body.AddParagraph()
End If
If Not dr.IsSHIP_TO_ADDR2Null Then
addy2 = dr.SHIP_TO_ADDR2
End If
strFormattedPhone = Regex.Replace(Trim(dr.BILL_TO_PHONE_NUM), phoneformatPattern, "$1-$2-$3")
pageHeader = " Printed Date : " & Now.ToString("MM/d/yyyy hh:mm:ss tt") & vbCrLf _
& " Page : " & padString((iPageNum + 1).ToString(), 42) & "PBN : " & dr.PRT_BATCH_NUM.ToString() & vbCrLf _
& " Order Date : " & padString(dr.CREATE_DTTIME, 40) & "Phone : " & strFormattedPhone & vbCrLf _
& " Bill To Cust. : " & dr.BILL_TO_NAME & vbCrLf _
& " Customer : " & padString(dr.SHOPPER_ID, 40) & "Email : " & dr.SHOPPER_EMAIL_ID & vbCrLf _
& " Ship To Cust. : " & dr.SHIP_TO_FIRST_NM & " " & dr.SHIP_TO_LAST_NM & vbCrLf _
& " Ship To Address : " & dr.SHIP_TO_ADDR1 & vbCrLf _
& " Ship To Address2: " & addy2 & vbCrLf _
& " Ship To City : " & dr.SHIP_TO_CITY & " " & dr.SHIP_TO_STATE & ", " & dr.SHIP_TO_ZIP & vbCrLf _
& " Order Number : " & padString(dr.ORDER_ID, 38) & "Sub Ord : " & dr.SUB_ORDER_ID & vbCrLf
headerParagraph.AppendText(pageHeader).CharacterFormat.Font = myFont
End Sub
Private Sub addStaticRowHeader(ByRef testDoc As Document)
Dim rowDescrip As Section
Dim statichead As String = ""
rowDescrip = testDoc.Sections.Item(testDoc.Sections.Count - 1)
rowDescrip.PageSetup.Orientation = Documents.PageOrientation.Landscape
rowDescrip.PageSetup.Margins.Top = 0.25F
rowDescrip.PageSetup.Margins.Bottom = 0.5F
rowDescrip.PageSetup.Margins.Left = 0.5F
rowDescrip.PageSetup.Margins.Right = 0.25F
rowDescrip.PageSetup.DefaultTabWidth = 0.5F
'Create a new paragraph or get the first paragraph
Dim rw As Documents.Paragraph = Nothing
If rowDescrip.Paragraphs.Count > 0 Then
rw = rowDescrip.Paragraphs.Item(rowDescrip.Paragraphs.Count - 1)
Else
rw = rowDescrip.AddParagraph()
End If
statichead = "-------------------------------------------------------------------------------------------------------------------" & vbCrLf _
& Space(5) & "Description" & Space(63) & "Item#" & Space(8) & "Dept#" & Space(4) & "Dept" & vbCrLf _
& Space(5) & "Class/Sku" & Space(16) & "UPC #" & Space(35) & "Qty" & Space(6) & "Total Price" & vbCrLf _
& Space(5) & "Color" & Space(10) & "Size" & Space(6) & "MIVenStylNum" & Space(8) & "Attribute 4 Name/Value" & Space(8) & "Attribute 5 Name/Value" & vbCrLf _
& "-------------------------------------------------------------------------------------------------------------------" & vbCrLf
rw.AppendText(statichead).CharacterFormat.Font = myFont
End Sub
Private Sub addOrderData(ByVal dr As Orders.OrderDataRow, ByRef testDoc As Document)
Dim orderDescrip As Section
Dim ordData As String = ""
Dim secCount As Integer = testDoc.Sections.Count
orderDescrip = testDoc.Sections.LastItem
'.Item(0)
'orderDescrip = testDoc.AddSection
orderDescrip.PageSetup.Orientation = Documents.PageOrientation.Landscape
orderDescrip.PageSetup.Margins.Top = 0.25F
orderDescrip.PageSetup.Margins.Bottom = 0.5F
orderDescrip.PageSetup.Margins.Left = 0.5F
orderDescrip.PageSetup.Margins.Right = 0.25F
orderDescrip.PageSetup.DefaultTabWidth = 0.5F
'Create a new paragraph or get the first paragraph
Dim rw As Documents.Paragraph = Nothing
If orderDescrip.Paragraphs.Count > 0 Then
rw = orderDescrip.Paragraphs(0)
Else
rw = orderDescrip.AddParagraph()
End If
insertPictureNEW(dr.SMALL_IMAGE, rw)
ordData = Space(5) & prdITEMDESC & prdITEMID & prdDEPTNUM & prdDEPTDESC & vbCrLf _
& Space(5) & prdCLSSKU & prdUPC & prdORDQTY & prdITEMTOTAL & vbCrLf _
& Space(5) & prdCOLOR & prdSIZE & prdVENSTYLENUM & prdATTR4 & prdATTR5 & vbCrLf _
& "-------------------------------------------------------------------------------------------------------------------" & vbCrLf
rw.AppendText(ordData).CharacterFormat.Font = myFont
End Sub