View Single Post
 
Old 03-04-2024, 01:43 PM
Jakov93 Jakov93 is offline Windows 10 Office 2010
Advanced Beginner
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default Adjust Page Size Using PrintOut Method for File Print to PDF by VBA

Hi,
I use this code to print the document by "Application.PrintOut" method to PDF file, I don't want it by "ExportAsFixedFormat" because I have an issue with this method (italic text loses formatting).
Code:
Sub SaveAsPDF()
    Dim sPrinter As String
    Dim strDocName As String
    Dim strPath As String
    Dim intPos As Integer
    'Find position of extension in filename
    strDocName = ActiveDocument.Name
    strPath = ActiveDocument.Path & "\"
    intPos = InStrRev(strDocName, ".")
    strDocName = Left(strDocName, intPos - 1)
    strDocName = strPath & strDocName & ".pdf"
    On Error GoTo lbl_Exit
    sPrinter = Application.ActivePrinter
    ActivePrinter = "Microsoft Print to PDF"
    Application.DisplayAlerts = False
    ActiveDocument.PrintOut _
        OutputFileName:=strDocName, _
        PrintToFile:=True
lbl_Exit:
    Application.DisplayAlerts = True
    Application.ActivePrinter = sPrinter
    Exit Sub
End Sub
The code works perfectly, but the only problem is the size of the output file is not as my document size
I always use A4 (210*297 mm), when I use ExportAsFixedFormat method, the output file is the same size as my document size,
but when I use "Application.PrintOut" method, the output file size is 215*279 mm, which is different from A4 size and causes some problems when printing on paper.
I changed the default paper size in "Microsoft Print to PDF" printer, but the problem persists, (see attached files).
Test_PrintOut_Method.pdf
Test_ExportAsFixedFormat_Method.pdf
So how to fix this issue?
Thanks
Reply With Quote