Reply to topic  [ 10 posts ] 
Printing from visual basic 2010 
Author Message
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
Hi,

I'm writing a program for a specific purpose... I'll explain it here, in case there's an easier way of doing this that I've overlooked.

I've been told that the exam papers we use are now ready to download, but the papers have to have an indivual code printed on them... a different number for every exam paper.

The number of sheets in each paper can vary and the amount of papers for each session can also change.

We also need to print a site code on each paper, as well as a topic code.

so far I've reached the stage where I can enter all of the information on a form and the variables are as follows:

Code:
    Public start_page_kilos As Integer
    Public start_page_hundreds As Integer
    Public start_page_tens As Integer
    Public start_page_units As Integer
    Public start_page_number As Integer
(These numbers are for the start page, and I use them to calculate the start page - I have used this because we may have to print in batches, so rather than setting it to one, we can start from 201, (for example))

    Public end_page_kilos As Integer
    Public end_page_hundreds As Integer
    Public end_page_tens As Integer
    Public end_page_units As Integer
    Public end_page_number As Integer
(Same as the start page, but for the end page...)

    Public total_pages_tens As Integer
    Public total_pages_units As Integer
    Public total_pages_number As Integer
(this is used to calculate how many sheets per exam paper)

    Public full_prefix As String
    Public short_prefix As String
    Public full_subject As String
    Public short_subject As String
(The prefix is the site code and the subject is the... subject)

    Public print_string As String
    Public page_counter As Integer
    Public test_text As String
(These are two variables)

   


I've reached the stage where I can create PDF files but whatever I do it insists on printing each page individually. I am hoping that there is a control code I can print to force it to start a new page, (we used to call it form feed in the olden days) but I'm currently at a loss... has anyone got any ideas?

TIA

:D

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Mon Jan 31, 2011 5:21 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
Second post, as the first was getting a bit long...

I can supply source code, if required, but if anyone knows of a way to send plain text to a printer in VB 2010, (preferably with control codes) that'd be a winner.

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Mon Jan 31, 2011 5:25 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
*bump*

Any ideas?

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Wed Feb 02, 2011 10:48 am
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 6:44 pm
Posts: 4141
Location: Exeter
Reply with quote
I'm afraid I'm clueless on this, but showed it to one of the guys at work who isn't. I'm just copying his email back verbatim:

Code:
1.           Namespace My
2.               ''' <summary>
3.               ''' Represents the lost VB6 functionality of a Printer object
4.               ''' </summary>
5.               ''' <remarks>Usage: My.Printer.Print(text)</remarks>
6.               Public Class Printer
7.                   Private Shared Lines As New Queue(Of String)
8.                   Private Shared _myfont As Font
9.                   Private Shared prn As Printing.PrintDocument
10.       
11.               Shared Sub New()
12.                   _myfont = New Font(SystemFonts.DefaultFont.FontFamily, 0.16, FontStyle.Regular, GraphicsUnit.Inch)
13.                   prn = New Printing.PrintDocument
14.                   AddHandler prn.PrintPage, AddressOf PrintPageHandler
15.               End Sub
16.       
17.               Public Shared Sub Print(ByVal text As String)
18.                   Dim linesarray() = text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
19.       
20.                   For Each line In linesarray
21.                       Lines.Enqueue(line)
22.                   Next
23.                   prn.Print()
24.               End Sub
25.       
26.               Private Shared Sub PrintPageHandler(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
27.                   Dim sf As New StringFormat()
28.                   Dim vpos As Single = e.PageSettings.HardMarginY
29.       
30.                   Do While Lines.Count > 0
31.                       Dim line As String = Lines.Dequeue
32.                       Dim sz As SizeF = e.Graphics.MeasureString(line, _myfont, e.PageSettings.Bounds.Size, sf)
33.       
34.                       Dim rct As New RectangleF( _
35.                           e.PageSettings.HardMarginX, vpos, _
36.                           e.PageBounds.Width - e.PageSettings.HardMarginX * 2, _
37.                           e.PageBounds.Height - e.PageSettings.HardMarginY * 2)
38.       
39.                       e.Graphics.DrawString(line, _myfont, Brushes.Black, rct)
40.                       vpos += sz.Height
41.                       If vpos > e.PageSettings.Bounds.Height - e.PageSettings.HardMarginY * 2 Then
42.                           e.HasMorePages = True
43.                           Exit Sub
44.                       End If
45.                   Loop
46.               End Sub
47.           End Class
48.       End Namespace


Just as My.Printer.print(text)

_________________
"The woman is a riddle inside a mystery wrapped in an enigma I've had sex with."


Wed Feb 02, 2011 11:28 am
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
Thanks Jon, I'll have a look when I get home.

:D

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Wed Feb 02, 2011 1:39 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
OK, It's update time... I found a PDF file on the Internetz yesterday, and the code below seems to work.

Obviously I'll have to do some tweaking, but we are getting there... :D

Code:
Private Sub PrintDocument1_PrintPage( _
ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles PrintDocument1.PrintPage
Static pageNum As Integer
Dim prFont As New Font("Verdana", 24, GraphicsUnit.Point)
e.Graphics.DrawString( _
"PAGE " & pageNum + 1, prFont, _
Brushes.Black, 700, 1050)
e.Graphics.DrawRectangle(Pens.Blue, 0, 0, 300, 100)
e.Graphics.DrawString( _
"Printing with VB 2005", prFont, _
Brushes.Black, 10, 10)
‘ Add more printing statements here
‘ Following is the logic that determines whether we’re done printing
pageNum = pageNum + 1
If pageNum <= 3 Then
e.HasMorePages = True
Else
e.HasMorePages = False
pageNum = 0
End If
End Sub

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Thu Feb 03, 2011 9:39 am
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
OK, final update time... The application is more or less complete now, (I need to put some more Division codes in, but until someone actually sends them to me I can't do anything about that) but aside from that it's working and all happy shiny! :D

I've just been told that I have to demonstrate it during a big meeting on monday... *gulp*

Thanks guys!

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Fri Feb 18, 2011 12:16 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
Apparently it wasn't the final update...

After my meeting/presentation yesterday there are strange grumbling noises being made, because some people don't like the idea of printing the papers out then running my program and purring the pre-printed forms through again, in order to print the additional information on the page.

I did a quick Google and there's an app called foxit which would do the job, (add the information to an existing PDF file) but do we collectively know of a way that I can insert text into an existing pdf file from Visual basic 2010?

I tried looking at the Adobe SDK but that only seems to work on VB 2005... unless I'm missing something

Thanks.

Edit to add:

Another thought springs to mind... how about opening the pdf file, adding the text then saving a new copy ready to print?

I'll look into it when I turn on the pc, but in the meantime if anyone gas any thoughts on this...

:D

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Tue Feb 22, 2011 10:50 am
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:58 pm
Posts: 8767
Location: behind the sofa
Reply with quote
I have a nagging feeling you could just do this in Office as a mail merge.

_________________
jonbwfc's law: "In any forum thread someone will, no matter what the subject, mention Firefly."

When you're feeling too silly for x404, youRwired.net


Thu Feb 24, 2011 1:41 am
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Fri Apr 24, 2009 7:55 am
Posts: 7935
Location: Manchester.
Reply with quote
JJW009 wrote:
I have a nagging feeling you could just do this in Office as a mail merge.


Thanks JJ, and apologies for the delay in reply. I think a quick recap may be in order.

I had a conversation with my boss who explained a problem to me... They are sent exam papers in PDF format, which they print out and send to individual sites.

They wanted a way of putting an individual mark on the papers, for tracking purposes.

They did approach the reprographics department, but it seems that they can only print the information as a watermark, which makes the papers unreadable.

I developed a Windows app which allows them to print the information at the top of the pages, but it means printing the exams papers then putting the printed sheets back into the printer.

They want to know if there is a way to embed the information straight into the PDF file.

I know, (but they don't seem to realise it) that my solution is by far the easiest method, but if there were a way that I could embed the information into the PDF files from within a VB .NET app it would be a final solution. My problem is that I don't know anything about embedding into PDFs from VB or Office, but as I know a bit of VB, and have the basic program already made that seems to be the sensible option.

That's where I'm at right now... anyone know about embedding data into a PDF from VB .NET (2010)?

Thanks.

:D

_________________
okenobi wrote:
John's hot. No denying it. But he's hardly Karen now, is he ;)

John Vella BSc (Hons), PGCE - Still the official forum prankster and crude remarker :P
Sorry :roll:
I'll behave now.
Promise ;)


Thu Mar 03, 2011 9:58 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.