Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
brendang
New Member.
1594 views

Printing to PDF

Jump to solution

Hi

Up to now, In Net Express, and Visual Cobol indeed, we have been able to print directly to Adobe PDF by setting the default printer to Adobe PDF and using the PC_PRINTER... routines.  We would typically call PC_PRINTER_OPEN with flags set to 4 or 8 to define orientation.  A dialog box "Save PDF File As..." is displayed and we press the Save button and the PDF file is created and Adobe is opened and that is all fine.

Now, in Visual Cobol we are looking at using the System.Drawing.Printing.PrintDocument class and the Print() method to make use of better pormatting.  This works fine when the default printer is an actual physical printer.  With the default printer set to Adobe PDF the process just hangs when the Print() method is called, a message box appears saying it is printing page 1 of the document but the PrintPage event handler is never executed.  Changing PrinterSettings::PrinterName in code has the same results.


It what I am trying not possible or am I missing something?  Any ideas?


Thank you

Brendan

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

RE: Printing to PDF

Jump to solution

I installed the Adobe Acrobat DC trial so that I could test this and it works correctly for me. I am using VC 2.3 update 1 and the test program that follows.

This is a simple Windows Forms program where I have a button on the form with a click event and then I drag a PrintDialog control and a PrintDocument control to the form, I add a PrintPage event to the PrintDocument control. When I click the button it will present me with a Printer Dialog. If I select the Abobe PDF and click print it will display the dialog to create the PDF file and then displays it after it is complete.

I would suggest that you try the following example to see if it works for you.

       class-id printpdf.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       
       working-storage section.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           goback.
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           set printDialog1::AllowSomePages to true
           set printDialog1::ShowHelp to true
           set printDialog1::Document to printDocument1
           declare result as type DialogResult = printDialog1::ShowDialog
      
           if result = type DialogResult::OK
              invoke printDocument1::Print
           end-if
       end method.

       method-id printDocument1_PrintPage final private.
       procedure division using by value sender as object e as type System.Drawing.Printing.PrintPageEventArgs.
       
           invoke type MessageBox::Show("Event fired!")
           declare mytext as string = "In document_PrintPage method."
      
           declare printFont as type System.Drawing.Font = new type System.Drawing.Font
              ("Arial", 35, type System.Drawing.FontStyle::Regular)
           *> Draw the content.
      
           invoke e::Graphics::DrawString(mytext, printFont,
              type System.Drawing.Brushes::Black, 10, 10)
      
       end method.
      
       end class.
 
      
0 Likes
3 Replies
brendang
New Member.

RE: Printing to PDF

Jump to solution

Sorry, forgot to say we're using Visual Cobol 2.1, Visual Studio 2010 on Windows XP.  Will be upgrading soon.

Brendan

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Printing to PDF

Jump to solution

I installed the Adobe Acrobat DC trial so that I could test this and it works correctly for me. I am using VC 2.3 update 1 and the test program that follows.

This is a simple Windows Forms program where I have a button on the form with a click event and then I drag a PrintDialog control and a PrintDocument control to the form, I add a PrintPage event to the PrintDocument control. When I click the button it will present me with a Printer Dialog. If I select the Abobe PDF and click print it will display the dialog to create the PDF file and then displays it after it is complete.

I would suggest that you try the following example to see if it works for you.

       class-id printpdf.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       
       working-storage section.
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           goback.
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           set printDialog1::AllowSomePages to true
           set printDialog1::ShowHelp to true
           set printDialog1::Document to printDocument1
           declare result as type DialogResult = printDialog1::ShowDialog
      
           if result = type DialogResult::OK
              invoke printDocument1::Print
           end-if
       end method.

       method-id printDocument1_PrintPage final private.
       procedure division using by value sender as object e as type System.Drawing.Printing.PrintPageEventArgs.
       
           invoke type MessageBox::Show("Event fired!")
           declare mytext as string = "In document_PrintPage method."
      
           declare printFont as type System.Drawing.Font = new type System.Drawing.Font
              ("Arial", 35, type System.Drawing.FontStyle::Regular)
           *> Draw the content.
      
           invoke e::Graphics::DrawString(mytext, printFont,
              type System.Drawing.Brushes::Black, 10, 10)
      
       end method.
      
       end class.
 
      
0 Likes
Highlighted
brendang
New Member.

RE: Printing to PDF

Jump to solution

Hi Chris

Thank you for your help, I have got it working now.  I think the fact that the "Save As..." dialog box was not showing as a separate icon in the taskbar when I was debugging might have given me the impression that the code was hanging.

Thank you again

Brendan

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.