Formatted report shows different when exporting to PDF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tuxalot
    New Member
    • Feb 2009
    • 200

    Formatted report shows different when exporting to PDF

    I have code that adds vertical lines in a report to create an "excel like" table or sorts. When doing a print preview all is well and the report formats correctly. However, when saving directly to PDF the formatting is lost. Here is my code (not sure if this helps). This code also makes use of (2) classes and I can include those as well if needed.

    Code to add vertical lines - in the reports GroupHeader On Print event:
    Code:
    Dim lns As Lines
    Dim lngHeight As Long
    Dim ctl As Control
    
    Set lns = New Lines 'create new Lines collection
    Set lns.Parent = Me 'set reference to current report
    
    lns.Add 0 'add line to far left
    
    For Each ctl In Me.GroupHeader0.Controls 'loop through controls in detail section
    If ctl.Height > lngHeight Then lngHeight = ctl.Height        'find tallest control
            'If ctl.ControlType = acTextBox Then lns.Add (ctl.Left + ctl.Width) 'add a line to the right of each text box
    If ctl.Tag = "vert" Then lns.Add (ctl.Left + ctl.Width)        'add a line to the right of each text box
    
        Next
    
        lns.Lengths = lngHeight 'Set all line heights to the tallest control's height
    
        lns.Draw        'draw lines
        Set lns = Nothing
        Set ctl = Nothing
    Code to print to PDF directly:
    Code:
    DoCmd.OutputTo acOutputReport, "rptIndivSurveySec", acFormatPDF, MyFilename, False, , , _                                         
    acExportQualityPrint
    How can I print direct to PDF and retain the formatting?

    Any help appreciated.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    The obvious answer appears to be to design the lines into the report itself. You've said nothing so far that explains why this might not be appropriate in your case.

    Comment

    • tuxalot
      New Member
      • Feb 2009
      • 200

      #3
      Thanks NeoPa. The field height is not consistent throughout the table so the code I am using adjusts the line height appropriately for the height of the fields' contents.
      Last edited by tuxalot; Jan 13 '12, 05:10 PM. Reason: Not clear

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        In that case it may still be simpler to design lines in the report and just update the Height properties of them all when required.

        PS. Such information really belongs in the question post as it's relevant to the approach to be taken. I'm sure you'll remember for next time :-)

        Comment

        • tuxalot
          New Member
          • Feb 2009
          • 200

          #5
          I will look into that option - thanks for the direction NeoPa. I had hoped there was a way to invoke a hidden report as a print preview and save the PDF from that, thus retaining my formatting.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            I can't say. I still use 2003 and that doesn't include the option to print to PDF at all :-D I'm just basically theorising as I go.

            Comment

            • dsatino
              Contributor
              • May 2010
              • 393

              #7
              2 things:
              1. if the line is not on the last saved version, I don't think it will print. So if you go this way, you may need to programatically save the report, print, then delete the lines, then save, then close.

              2. Even if it's there, it may not PDF. I lose formatting such as lines, boxes, and even sides of boxes all the time. They are perfectly visible in the print preview, print fine to an actual printer, but just disappear on the PDF. You should probably google PDF related issues to get to the bottom of it.

              Comment

              • dsatino
                Contributor
                • May 2010
                • 393

                #8
                Oh, and NeoPa, Access 2003 does have a PDF plug-in (As long as you have Adobe Acrobat)

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #9
                  ... and I've actually used that ;-)

                  That's not Access 2003 though (It's Adobe Acrobat). I would not expect my experience with Acrobat to be of much help with the inbuilt facility to print to PDF format in later versions of Access.

                  Comment

                  • tuxalot
                    New Member
                    • Feb 2009
                    • 200

                    #10
                    Even if it's there, it may not PDF. I lose formatting such as lines, boxes, and even sides of boxes all the time. They are perfectly visible in the print preview, print fine to an actual printer, but just disappear on the PDF. You should probably google PDF related issues to get to the bottom of it.
                    Thanks dsatino. However if I do a print preview then create a PDF from that, the formatting is retained.

                    I suppose if I could open the report in print preview hidden then save the PDF from that, it may work. Something like:
                    Code:
                    DoCmd.OpenReport "reportname", acViewNormal, , , acHidden
                    then while that is open, save to PDF?

                    Comment

                    • tuxalot
                      New Member
                      • Feb 2009
                      • 200

                      #11
                      Got it. The above works. Here is my code:
                      Code:
                      DoCmd.OpenReport "ReportName", acViewPreview, , , acHidden
                      DoCmd.OutputTo acOutputReport, "ReportName", acFormatPDF, MyFilename, False, , , _                                        
                      acExportQualityPrint
                      DoCmd.Close acReport, "ReportName", acSaveNo

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32633

                        #12
                        Good thinking Tux :-)

                        Comment

                        Working...