How to customize the paper size in my code?

PDF-XChange Drivers API (only) V4/V5
This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - VERSION 4 & 5 - Please use the PDF-Tools SDK Forum for Library DLL assistance.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Post Reply
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

How to customize the paper size in my code?

Post by fbao »

I want to print my excel file to PDF with customized paper size in Excel Macro using VBA. Here's my code which can print the file but the paper size seems not changed. Can anyone help me? Any reply will be appreciated. Thanks a lot.

Code: Select all

Public PDFPFactory As New PXCComLib.CPXCControlEx
Public PDFPrinter As PXCComLib.CPXCPrinter

Public Sub PDFPrintInit()

    'Initialize printer

    Set PDFPrinter = PDFPFactory.Printer("", "PDF-XChange 4.0 Sample", "<YOUR REG CODE>", "<YOUR DEV CODE>")
    pname = PDFPrinter.Name
    PDFPrinter.SetAsDefaultPrinter
    
    'Config printer
    PDFPrinter.ResetDefaults
    With PDFPrinter
        'Set paper size
        .Option("Paper.SheetSizeIndex") = -2
        .Option("Paper.SheetWidth") = 1200
        .Option("paper.SheetHeight") = 300
        .Option("Save.Path") = ""
        .Option("Save.File") = "MyTest.pdf"
        .Option("Save.SaveType") = "Save"
        .Option("Save.ShowSaveDialog") = "No"
        .Option("Save.WhenExists") = "Overwrite"
        .Option("Compression.Text") = "Yes"
        .Option("Compression.ASCII") = "No"
        .Option("Compression.Color.Enabled") = "Yes"
        .Option("Compression.Color.Method") = "Auto"
        .Option("Compression.Indexed.Enabled") = "Yes"
        .Option("Compression.Indexed.Method") = "Auto"
        .Option("Compression.Mono.Enabled") = "Yes"
        .Option("Compression.Mono.Method") = "Auto"
        .Option("Save.RunApp") = "Yes"
        .Option("Saver.ShowProgress") = "No"
    End With
End Sub
    
    
    
Public Sub PDFClose()
    
    PDFPrinter.RestoreDefaultPrinter
    Set PDFPrinter = Nothing
    Set PDFFactory = Nothing
End Sub

Public Sub PDFPrint()
    
    ' Select used cells
    Worksheets("Sheet1").Activate
    
    PDFPrintInit
        
    ActiveSheet.UsedRange.Select
        
    Selection.PrintOut
    
    PDFClose
    
End Sub
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17941
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to customize the paper size in my code?

Post by Tracker Supp-Stefan »

Hi fbao,

You will need to set the custom size in excel as it is overriding the settings the driver has.

Regards,
Stefan
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Thanks, Stefan.

How to set the paper size in excel? If I print the file in excel manually, choose the printer "PDF-XChange 4.0", then in the properties window, set the page size to custom, the file will be printed to PDF in the excat customized size. How can I implement this in my code?

This is really important to my project. Any help will be appreciated.

All the best,
Fei
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17941
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to customize the paper size in my code?

Post by Tracker Supp-Stefan »

Hi Fei,

Here is the PageSetup Object
and the PaperSize Property for it

Best,
Stefan
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Thank you, Stefan.

I tried to set PageSetup.PaperSize = xlPaperUser behind the code which sets the values of Paper.SheetWidth and Paper.SheetHeight of PDFPrinter. But it still didn't work out. I got this error message:

"unable to set the papersize property of the pagesetup class" on the line "PageSetup.PaperSize = xlPaperUser".

Any advice?

Code: Select all

Public PDFPFactory As New PXCComLib.CPXCControlEx
Public PDFPrinter As PXCComLib.CPXCPrinter

Public Sub PDFPrintInit()

    'Initialize printer

    Set PDFPrinter = PDFPFactory.Printer("", "PDF-XChange 4.0 Sample", "<YOUR REG CODE>", "<YOUR DEV CODE>")
    pname = PDFPrinter.Name
    PDFPrinter.SetAsDefaultPrinter
    
    'Config printer
    PDFPrinter.ResetDefaults
    With PDFPrinter
        'Set paper size
        .Option("Paper.SheetSizeIndex") = 17
        .Option("Paper.SheetWidth") = 1200
        .Option("paper.SheetHeight") = 300
        .Option("Save.Path") = ""
        .Option("Save.File") = "MyTest.pdf"
        .Option("Save.SaveType") = "Save"
        .Option("Save.ShowSaveDialog") = "No"
        .Option("Save.WhenExists") = "Overwrite"
        .Option("Compression.Text") = "Yes"
        .Option("Compression.ASCII") = "No"
        .Option("Compression.Color.Enabled") = "Yes"
        .Option("Compression.Color.Method") = "Auto"
        .Option("Compression.Indexed.Enabled") = "Yes"
        .Option("Compression.Indexed.Method") = "Auto"
        .Option("Compression.Mono.Enabled") = "Yes"
        .Option("Compression.Mono.Method") = "Auto"
        .Option("Save.RunApp") = "Yes"
        .Option("Saver.ShowProgress") = "No"
    End With
End Sub
    
    
    
Public Sub PDFClose()
    
    PDFPrinter.RestoreDefaultPrinter
    Set PDFPrinter = Nothing
    Set PDFFactory = Nothing
End Sub

Public Sub PageSetup()
'
' PageSetup Macro
' Set Page Setup parameters
'
    'Application.ActivePrinter = PDFPrinter.Name
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0)
        .RightMargin = Application.InchesToPoints(0)
        .TopMargin = Application.InchesToPoints(0)
        .BottomMargin = Application.InchesToPoints(0)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0)
        .PaperSize = xlPaperUser
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .PrintQuality = 300
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlPortrait
        .Draft = False
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
        .EvenPage.LeftHeader.Text = ""
        .EvenPage.CenterHeader.Text = ""
        .EvenPage.RightHeader.Text = ""
        .EvenPage.LeftFooter.Text = ""
        .EvenPage.CenterFooter.Text = ""
        .EvenPage.RightFooter.Text = ""
        .FirstPage.LeftHeader.Text = ""
        .FirstPage.CenterHeader.Text = ""
        .FirstPage.RightHeader.Text = ""
        .FirstPage.LeftFooter.Text = ""
        .FirstPage.CenterFooter.Text = ""
        .FirstPage.RightFooter.Text = ""
    End With
    'ActiveWindow.SelectedSheets.PrintPreview
End Sub


Public Sub PDFPrint()
    
    ' Select used cells
    Worksheets("Sheet1").Activate
    
    PDFPrintInit
    
    PageSetup
        
    ActiveSheet.UsedRange.Select
        
    Selection.PrintOut
    
    PDFClose
    
End Sub

All the best,
Fei
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

I am wondering that in SDK all the properties of Paper section actually are corresponding to the properties of layout section on the paper setting page when config the printer manually.

When setting the printer properties manually, I tried 2 different ways:
Test 1. If I just change the Sheet Size to "custom", and set Size to, e.g., 1200 X 300, while keep the Paper Size as "Standard: A4", then the printout will still be at size of A4.

Test 2. On the contrary, if I change the Paper Size to "Custom: 1200 X 300 mm", and leave the Sheet Size as "Auto", then I will get a printout at the size of 1200 X 300.

So I'm thinking that in my code, if I want to print a file in a customized size, it might not be enough only to set Paper.SheetSizeIndex = -2, Paper.SheetWidth = 1200 and Paper.SheetHeight = 300, becuase it looks like what I did in Test 1.

Therefore, are there any other properties, like Paper.PaperWidth or Paper.PaperHeight, for us to do it? If not, how can I implement what I did in Test 2 programmatically?

Sorry for so many questions and thank you for your help.

All the best,
Fei
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Hi!

Anything new about my questions?

All the best,
Fei
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: How to customize the paper size in my code?

Post by Corwin - Tracker Sup »

Hi Fei,

Please, try to modify your code to this:

Code: Select all

Dim v As Long
v = -2
With PDFPrinter
  .Option("Paper.SheetSizeIndex") = v
  ...
  .ApplyOptions 0
End With
HTH.
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Thanks. I tried the code and it didn't work, :( The sheetsize of the printout did change to what I set in code, 1200 X 300. But the paper size is still A4. Here are my code and the printout pdf.

Code: Select all

Public PDFPFactory As New PXCComLib.CPXCControlEx
Public PDFPrinter As PXCComLib.CPXCPrinter

Public Sub PDFPrintInit()

    'Initialize printer

    Set PDFPrinter = PDFPFactory.Printer("", "PDF-XChange 4.0 Sample", "<YOUR REG CODE>", "<YOUR DEV CODE>")
    pname = PDFPrinter.Name
    PDFPrinter.SetAsDefaultPrinter
    Dim v As Long
    v = -2
    
    'Config printer
    PDFPrinter.ResetDefaults
    With PDFPrinter
        'Set paper size
        .Option("Paper.SheetSizeIndex") = v
        .Option("Paper.SheetWidth") = 1200
        .Option("paper.SheetHeight") = 300
        .Option("Save.Path") = ""
        .Option("Save.File") = "MyTest.pdf"
        .Option("Save.SaveType") = "Save"
        .Option("Save.ShowSaveDialog") = "No"
        .Option("Save.WhenExists") = "Overwrite"
        .Option("Compression.Text") = "Yes"
        .Option("Compression.ASCII") = "No"
        .Option("Compression.Color.Enabled") = "Yes"
        .Option("Compression.Color.Method") = "Auto"
        .Option("Compression.Indexed.Enabled") = "Yes"
        .Option("Compression.Indexed.Method") = "Auto"
        .Option("Compression.Mono.Enabled") = "Yes"
        .Option("Compression.Mono.Method") = "Auto"
        .Option("Save.RunApp") = "Yes"
        .Option("Saver.ShowProgress") = "No"
        .ApplyOptions (0)
    End With
End Sub
    
    
    
Public Sub PDFClose()
    
    PDFPrinter.RestoreDefaultPrinter
    Set PDFPrinter = Nothing
    Set PDFFactory = Nothing
End Sub

Public Sub PageSetup()
'
' PageSetup Macro
' Set Page Setup parameters
'
    'Application.ActivePrinter = PDFPrinter.Name
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0)
        .RightMargin = Application.InchesToPoints(0)
        .TopMargin = Application.InchesToPoints(0)
        .BottomMargin = Application.InchesToPoints(0)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0)
        '.PaperSize = xlPaperUser
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .PrintQuality = 300
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlPortrait
        .Draft = False
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
        .EvenPage.LeftHeader.Text = ""
        .EvenPage.CenterHeader.Text = ""
        .EvenPage.RightHeader.Text = ""
        .EvenPage.LeftFooter.Text = ""
        .EvenPage.CenterFooter.Text = ""
        .EvenPage.RightFooter.Text = ""
        .FirstPage.LeftHeader.Text = ""
        .FirstPage.CenterHeader.Text = ""
        .FirstPage.RightHeader.Text = ""
        .FirstPage.LeftFooter.Text = ""
        .FirstPage.CenterFooter.Text = ""
        .FirstPage.RightFooter.Text = ""
    End With
    'ActiveWindow.SelectedSheets.PrintPreview
End Sub


Public Sub PDFPrint()
    
    ' Select used cells
    Worksheets("Sheet1").Activate
    ActiveSheet.UsedRange.Select
    
    PDFPrintInit
    
    PageSetup
                
    Selection.PrintOut
    
    PDFClose
    
End Sub
Attachments
MyTest.rar
(9.46 KiB) Downloaded 211 times
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

By the way, I had to comment this line since otherwise it would throw out errors like "Run-time error '1004': Unable to set the PaperSize property of the PageSetup class".

Code: Select all

'.PaperSize = xlPaperUser
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3550
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: How to customize the paper size in my code?

Post by Ivan - Tracker Software »

fbao wrote:Thanks. I tried the code and it didn't work, :( The sheetsize of the printout did change to what I set in code, 1200 X 300. But the paper size is still A4. Here are my code and the printout pdf.
As I see by attached PDF's your code works. What's wrong now ?
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Hi Ivan, thank you for your reply.

Now my problem is that I can't print the excel as large as the sheet size. In the printout pdf, you can see the sheet size is pretty large, while the excel sheet is so small. My goal is to print excel files into pdf which is wide enough so that all the columns/fields can be put in one page. However, in my printout pdf, the excel sheet is still vertically devided into several pages.

For example, there is a spread sheet which has 20 columns and 200 rows. To print it by default, an A4 paper may only contain 10 columns and 100 rows, so the printout pdf has 4 pages totally. If my user wants to look at the contents of column 10 and 11 to find out the relation between them, he has to find them seperately on page 1 and 3 and make sure he's looking at the same row.

What I need to do is to customize the size of the print paper so that one page can contain 20 columns, and maybe also 200 rows which doesn't matter though, so my user can view all the fields of a row on the same page.

Please help me to solve the problem.

All the best,
Fei
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Hi,

I found that if I print the spread sheet manually like this:
1. In excel 2007, click print, choose "PDF-XChange 4.0", click "properties".
2. In the properties window, in "Paper Setting" ->"Paper size" section, choose "Standard A4".
3. In "Paper Setting"->"Layout" section, set "Sheet Size" to "Custom", then "Size" to "1200 X 300".
Then the printout is exactly what I attached previously.

If I chage step 2 above to the following:
2. In the properties window, in "Paper Setting" ->"Paper size" section, choose "Custom" and set "1200 X 300".
Then do step 3 the same as above, the printout is indeed what I want.

Now in my code, it seems that I can only do step 3 which is to set the sheet size to custom, but can't do step 2 which is to set paper size to custom. How can I do this in my code?

Please help me!

All the best,
Fei
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3550
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: How to customize the paper size in my code?

Post by Ivan - Tracker Software »

Please try to add this code:

Code: Select all

  With PDFPrinter
      ' Set Paper size
      .Option("DevMode.PapSize") = 256    ' means custom paper size
      .Option("DevMode.PapWidth") = 1200
      .Option("DevMode.PapHeight") = 300
  End With
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Hi Ivan, thank you for your reply.

I tried the added code and got an error "Invalid procedure call or argument" on the second line

Code: Select all

.Option("DevMode.PapWidth") = 1200
I commented the second line, then got an error on the 3rd line

Code: Select all

.Option("DevMode.PapHeight") = 300
But the 1st line was passed without error

Code: Select all

.Option("DevMode.PapSize") = 256
Any advice?


All the best,
Fei
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3550
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: How to customize the paper size in my code?

Post by Ivan - Tracker Software »

sorry, I was wrong. It should be:

Code: Select all

	.Option("DevMode.PapSize")		= 256;
	.Option("DevMode.CWidth")		= 1200;
	.Option("DevMode.CHeight")		= 300;
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Thanks Ivan. I tried the code, still got the same pdf I attached previously with a very small spread sheet in the center of a large page.

Any new idea, please? Or any other properties of "DevMode"?


All the best,
Fei
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Hi Ivan.

I tried the PDFPrinter initializing part of my code, then in Excel 2007, opened the properties window of the printer "PDF-XChange 4.0 Sample" which was just created by my code, and found that only the sheetsize was changed to custom while the paper size still remained as "Standard A4". This meant that the two lines I added to my code could't change the paper size.

Code: Select all

.Option("DevMode.CWidth")      = 1200;
   .Option("DevMode.CHeight")      = 300;
Here's my code to initialize the PDFPrinter:

Code: Select all

Public Sub PDFPrintInit()

    'Initialize printer

    Set PDFPrinter = PDFPFactory.Printer("", "PDF-XChange 4.0 Sample", "<YOUR REG CODE>", "<YOUR DEV CODE>")
    'pname = PDFPrinter.Name
    PDFPrinter.SetAsDefaultPrinter
    Dim v As Long
    v = -2
    
    'Config printer
    PDFPrinter.ResetDefaults
    With PDFPrinter
        'Set paper size
        .Option("DevMode.PapSize") = 256    ' means custom paper size
        .Option("DevMode.CWidth") = 12000
        .Option("DevMode.CHeight") = 3000
        .Option("Paper.SheetSizeIndex") = v
        .Option("Paper.SheetWidth") = 12000
        .Option("paper.SheetHeight") = 3000
        .Option("Save.Path") = ""
        .Option("Save.File") = "MyTest6.pdf"
        .Option("Save.SaveType") = "Save"
        .Option("Save.ShowSaveDialog") = "No"
        .Option("Save.WhenExists") = "Overwrite"
        .Option("Compression.Text") = "Yes"
        .Option("Compression.ASCII") = "No"
        .Option("Compression.Color.Enabled") = "Yes"
        .Option("Compression.Color.Method") = "Auto"
        .Option("Compression.Indexed.Enabled") = "Yes"
        .Option("Compression.Indexed.Method") = "Auto"
        .Option("Compression.Mono.Enabled") = "Yes"
        .Option("Compression.Mono.Method") = "Auto"
        .Option("Save.RunApp") = "Yes"
        .Option("Saver.ShowProgress") = "No"
        .ApplyOptions (0)
    End With
End Sub
And the screenshot of the printer properties window is as attached.

Any help will be greatly appreciated.

All the best,
Fei
Attachments
printer.rar
(52.43 KiB) Downloaded 205 times
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: How to customize the paper size in my code?

Post by John - Tracker Supp »

Ivan will answer you - but for now moved to the correct - developer forum for the PDF-XChange Drivers API.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Hi.

Any further progress on my question?

Thanks a lot.

All the best,
Fei
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3550
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: How to customize the paper size in my code?

Post by Ivan - Tracker Software »

Cannot reproduce the trouble: have inserted you code into Excel file, put break point into PDFPrint method after PDFPrintInit call, and now I see printers settings:

Image
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Thanks, Ivan.

Would you please try again using the attached excel file and code? I tested the code on the attached file with the break point just after PDFPrintInit call, and got the printer paper size as "Standard A4".

Thank you very much. Hope the problem can be solved before the holiday, :) .

All the best,
Fei

Code: Select all

Public PDFPFactory As New PXCComLib.CPXCControlEx
Public PDFPrinter As PXCComLib.CPXCPrinter

Public Sub PDFPrintInit()

    'Initialize printer

    Set PDFPrinter = PDFPFactory.Printer("", "PDF-XChange 4.0 Sample", "<YOUR REG CODE>", "<YOUR DEV CODE>")
    'pname = PDFPrinter.Name
    PDFPrinter.SetAsDefaultPrinter
    Dim v As Long
    v = -2
    
    'Config printer
    PDFPrinter.ResetDefaults
    With PDFPrinter
        'Set paper size
        .Option("DevMode.PapSize") = 256    ' means custom paper size
        .Option("DevMode.CWidth") = 14000
        .Option("DevMode.CHeight") = 3000
        .ApplyOptions (0)
        .Option("Paper.SheetSizeIndex") = v
        .Option("Paper.SheetWidth") = 14000
        .Option("paper.SheetHeight") = 3000
        .Option("Save.Path") = ""
        .Option("Save.File") = "MyTest6.pdf"
        .Option("Save.SaveType") = "Save"
        .Option("Save.ShowSaveDialog") = "No"
        .Option("Save.WhenExists") = "Overwrite"
        .Option("Compression.Text") = "Yes"
        .Option("Compression.ASCII") = "No"
        .Option("Compression.Color.Enabled") = "Yes"
        .Option("Compression.Color.Method") = "Auto"
        .Option("Compression.Indexed.Enabled") = "Yes"
        .Option("Compression.Indexed.Method") = "Auto"
        .Option("Compression.Mono.Enabled") = "Yes"
        .Option("Compression.Mono.Method") = "Auto"
        .Option("Save.RunApp") = "Yes"
        .Option("Saver.ShowProgress") = "No"
        .ApplyOptions (0)
    End With
End Sub
    
    
    
Public Sub PDFClose()
    
    'PDFPrinter.RestoreDefaultPrinter
    Set PDFPrinter = Nothing
    Set PDFFactory = Nothing
End Sub

Public Sub PageSetup()
'
' PageSetup Macro
' Set Page Setup parameters
'
    'Application.ActivePrinter = PDFPrinter.Name
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0)
        .RightMargin = Application.InchesToPoints(0)
        .TopMargin = Application.InchesToPoints(0)
        .BottomMargin = Application.InchesToPoints(0)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0)
        '.PaperSize = xlPaperUser
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .PrintQuality = 300
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlPortrait
        .Draft = False
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
        .EvenPage.LeftHeader.Text = ""
        .EvenPage.CenterHeader.Text = ""
        .EvenPage.RightHeader.Text = ""
        .EvenPage.LeftFooter.Text = ""
        .EvenPage.CenterFooter.Text = ""
        .EvenPage.RightFooter.Text = ""
        .FirstPage.LeftHeader.Text = ""
        .FirstPage.CenterHeader.Text = ""
        .FirstPage.RightHeader.Text = ""
        .FirstPage.LeftFooter.Text = ""
        .FirstPage.CenterFooter.Text = ""
        .FirstPage.RightFooter.Text = ""
    End With
    'ActiveWindow.SelectedSheets.PrintPreview
End Sub


Public Sub PDFPrint()
    
    ' Select used cells
    Worksheets("Sheet1").Activate
    ActiveSheet.UsedRange.Select
        
    PageSetup
        
    PDFPrintInit
        
    'Selection.PrintOut
    
    PDFPrinter.RestoreDefaultPrinter  'Set break point here
    Set PDFPrinter = Nothing
    Set PDFFactory = Nothing
    
    PDFClose
    
    
End Sub
Attachments
TEST1.rar
(7.76 KiB) Downloaded 179 times
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Hi, there.

Can my problem be reproduced?

Sorry to be so pushy, just my boss is eager to decide which product we should use to move the project on.

Thank you very much.


All the best,
Fei
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Hello!

Just stop by to see if there's any new reply here.

Thanks.

All the best,
Fei
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3550
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: How to customize the paper size in my code?

Post by Ivan - Tracker Software »

To be honest, I cannot reproduce the problem even with your file. On my side, when I set breakpoint on mentioned line, I see paper and sheet size as custom with dimensions of 14000x300 as was specified.

Are you sure you are using the latest build of the driver ?
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Thank you for your reply, Ivan. I'm sorry to bother you just before the holiday.

Yes, I'm sure I used the latest version, because I downloaded the driver and installed it on our server on Dec 23, tested my code there and got the same result. I don't know why you got different thing, is there any configuration in the system printer or Excel?


All the best,
Fei
User avatar
Paul - Tracker Supp
Site Admin
Posts: 6901
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

Re: How to customize the paper size in my code?

Post by Paul - Tracker Supp »

Hi fbao,

can you tell us the OS version and Office versions so we can try to reproduce this with the same please.

regards
Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
fbao
User
Posts: 32
Joined: Mon Nov 02, 2009 7:17 pm

Re: How to customize the paper size in my code?

Post by fbao »

Hi Paul,

I tested the code on my laptop which is installed WinXP Professional SP3 and our server which is installed Windows Server 2003 R2 Standard Edition SP2, and the same version of Office. The excel version is:

Microsoft Office Excel 2007(12.0.6514.5000) SP2 MSO(12.0.6425.1000) Part of Microsoft Office Enterprise 2007


Thank you very much.

All the best,
Fei
Post Reply