By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

Formatted report shows different when exporting to PDF

tuxalot
100+
P: 200
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:
Expand|Select|Wrap|Line Numbers
  1. Dim lns As Lines
  2. Dim lngHeight As Long
  3. Dim ctl As Control
  4.  
  5. Set lns = New Lines 'create new Lines collection
  6. Set lns.Parent = Me 'set reference to current report
  7.  
  8. lns.Add 0 'add line to far left
  9.  
  10. For Each ctl In Me.GroupHeader0.Controls 'loop through controls in detail section
  11. If ctl.Height > lngHeight Then lngHeight = ctl.Height        'find tallest control
  12.         'If ctl.ControlType = acTextBox Then lns.Add (ctl.Left + ctl.Width) 'add a line to the right of each text box
  13. If ctl.Tag = "vert" Then lns.Add (ctl.Left + ctl.Width)        'add a line to the right of each text box
  14.  
  15.     Next
  16.  
  17.     lns.Lengths = lngHeight 'Set all line heights to the tallest control's height
  18.  
  19.     lns.Draw        'draw lines
  20.     Set lns = Nothing
  21.     Set ctl = Nothing
Code to print to PDF directly:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, "rptIndivSurveySec", acFormatPDF, MyFilename, False, , , _                                         
  2. acExportQualityPrint
How can I print direct to PDF and retain the formatting?

Any help appreciated.
Jan 13 '12 #1
Share this Question
Share on Google+
11 Replies


NeoPa
Expert Mod 15k+
P: 31,263
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.
Jan 13 '12 #2

tuxalot
100+
P: 200
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.
Jan 13 '12 #3

NeoPa
Expert Mod 15k+
P: 31,263
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 :-)
Jan 13 '12 #4

tuxalot
100+
P: 200
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.
Jan 13 '12 #5

NeoPa
Expert Mod 15k+
P: 31,263
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.
Jan 13 '12 #6

dsatino
100+
P: 393
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.
Jan 13 '12 #7

dsatino
100+
P: 393
Oh, and NeoPa, Access 2003 does have a PDF plug-in (As long as you have Adobe Acrobat)
Jan 13 '12 #8

NeoPa
Expert Mod 15k+
P: 31,263
... 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.
Jan 13 '12 #9

tuxalot
100+
P: 200
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:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "reportname", acViewNormal, , , acHidden
then while that is open, save to PDF?
Jan 14 '12 #10

tuxalot
100+
P: 200
Got it. The above works. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "ReportName", acViewPreview, , , acHidden
  2. DoCmd.OutputTo acOutputReport, "ReportName", acFormatPDF, MyFilename, False, , , _                                        
  3. acExportQualityPrint
  4. DoCmd.Close acReport, "ReportName", acSaveNo
Jan 14 '12 #11

NeoPa
Expert Mod 15k+
P: 31,263
Good thinking Tux :-)
Jan 15 '12 #12

Post your reply

Sign in to post your reply or Sign up for a free account.