VB6 Add image to PDF
Posted: Thu Aug 08, 2019 5:01 pm
Hi All,
I'm trying to create a PDF in VB6 (Maintaining legacy systems)
I need to add 4 images into the PDF, I have attached the following code but it is not working for some reason, no errors or anything.
I'm trying to create a PDF in VB6 (Maintaining legacy systems)
I need to add 4 images into the PDF, I have attached the following code but it is not working for some reason, no errors or anything.
Code: Select all
Dim pRow As Integer, cRow As Integer, printOF As Boolean, pQty As Integer
Dim myY As Integer
Dim fontArial As Long, fontArialB As Long, fontCourierNew As Long, fontCourierNewB As Long, nImage As Long
If cmdSave.Visible = True Then Call cmdSave_Click
printOF = True
pdf.PdfNewPdf Environ("temp") & "XXXXXXXXXXX"
pdf.PdfSetMeasurementUnits 1 'measure unit is millimeters
pdf.PdfSetPageDimensions 210, 297 'Pages dimensio
myY = 290: myPageNo = 0
Dim fRow As Integer, tRow As Integer
If gdParts.Row <= gdParts.RowSel Then
fRow = gdParts.Row: tRow = gdParts.RowSel
Else
fRow = gdParts.RowSel: tRow = gdParts.Row
End If
For pRow = fRow To tRow
If gdParts.TextMatrix(pRow, 0) <> "" Then
BarcodeX1.Caption = Trim(gdParts.TextMatrix(pRow, 2)) & "#" & gdParts.TextMatrix(pRow, 1) & "#" & Format(dtBuild, "ddmmyyyy") & "#" & Mid(gdParts.TextMatrix(pRow, 2), 1, 8) & "#"
SavePicture BarcodeX1.Picture, Environ("temp") & "\" & BarcodeX1.Caption & ".bmp"
If printOF = True Then
printOF = False
fontCourierNew = pdf.PdfAddFont("Courier New") 'Add Courier new font
fontCourierNewB = pdf.PdfAddFont("Courier New", True) 'Add Courier new bold font
pdf.PdfNewPage
pdf.PdfDrawTextAlign 105, myY, "XXXX- " & Format(dtBuild, "ddd, d-MMM-yyyy"), fontCourierNewB, 16, 2
myY = myY - 10
pdf.PdfDrawTextAlign 10, myY, "XXXX", fontCourierNewB, 12, 0
pdf.PdfDrawTextAlign 40, myY, "XXXX", fontCourierNewB, 12, 0
pdf.PdfDrawTextAlign 80, myY, "XXX", fontCourierNewB, 12, 2
pdf.PdfDrawTextAlign 100, myY, "XXXX", fontCourierNewB, 12, 0
myY = myY - 8
End If
Dim barcodeID As Integer
barcodeID = pdf.PdfAddImageFromFile(Environ("temp") & "\" & BarcodeX1.Caption & ".bmp")
gdParts.Row = pRow
If gdParts.Row = pRow Then
Call gdParts_EnterCell
Else
gdParts.Row = pRow
End If
pdf.PdfDrawTextAlign 10, myY, gdParts.TextMatrix(pRow, 0) & ")" & gdParts.TextMatrix(pRow, 1), fontCourierNew, 12, 0
pdf.PdfDrawTextAlign 40, myY, gdParts.TextMatrix(pRow, 2), fontCourierNew, 12, 0
pQty = gdParts.TextMatrix(pRow, 4)
pdf.PdfDrawTextAlign 80, myY, pQty, fontCourierNew, 12, 2
pdf.PdfDrawCircle 80, myY + 1, 5, 0.5
pdf.PdfDrawTextAlign 100, myY, gdParts.TextMatrix(pRow, 3), fontCourierNew, 12, 0
myY = myY - 8
'pdf.PdfDrawImage barcodeID, 10, myY, 500, 500
For cRow = 1 To vwComps.ListItems.Count
pdf.PdfDrawTextAlign 40, myY, vwComps.ListItems(cRow).Text, fontCourierNew, 12, 0
'Printer.CurrentX = 2250: Printer.Print vwComps.ListItems(cRow).Text;
pdf.PdfDrawTextAlign 100, myY, vwComps.ListItems(cRow).SubItems(1), fontCourierNew, 12, 0
'Printer.CurrentX = 5000: Printer.Print vwComps.ListItems(cRow).SubItems(1)
myY = myY - 5
Next cRow
myY = myY - 3
pdf.PdfDrawLine 0, myY, 210, myY, 0.5
myY = myY - 9
If myY < 35 Then
printOF = True
myY = 290
pdf.PdfEndPage
End If
End If
'Kill Environ("temp") & "\" & BarcodeX1.Caption & ".bmp"
Next pRow
If myY <> 295 Then pdf.PdfEndPage
pdf.PdfSavePdf
Set olMsg = Nothing
Set olObj = Nothing