【问题标题】:Set Fit to Visible in Pdf from excel vba从 excel vba 在 Pdf 中将适合设置为可见
【发布时间】:2017-03-06 07:19:15
【问题描述】:

我正在尝试将 excel 工作表导出为 pdf。有什么方法可以使用 VBA 将 pdf 属性设置为fit to visible。 谢谢

下面是我正在使用的代码 sn-p

With wksSalesAndQuotaScoreCard
        '.PageSetup.LeftMargin=Application.InchesToPoints(0.7)
        .PageSetup.LeftMargin = Application.InchesToPoints(0.7)
        .PageSetup.RightMargin = Application.InchesToPoints(0.7)
        .PageSetup.TopMargin = Application.InchesToPoints(0.75)
        .PageSetup.BottomMargin = Application.InchesToPoints(0.75)
        .PageSetup.HeaderMargin = Application.InchesToPoints(0.3)

        .PageSetup.Orientation = xlLandscape
        .PageSetup.PrintTitleRows = "_SalesandQuotaScoreCardView"
        .PageSetup.CenterHorizontally = True
        .PageSetup.Order = xlDownThenOver
        .PageSetup.FitToPagesWide = 1
        ''.PageSetup.Zoom = 50
        Set rngSalesAndQuotaView = Range(.Shapes("_SalesandQuotaViewFrame").TopLeftCell.Offset(0, -1), .Shapes("_SalesandQuotaViewFrame").BottomRightCell.Offset(1, 0))
        rngSalesAndQuotaView.Select
    End With

    wksScoreCardPayoutView.Select
    wksSalesAndQuotaScoreCard.Select False
    Selection.ExportAsFixedFormat xlTypePDF, IncludeDocProperties:=True, openafterpublish:=True
    wksCustomizeScoreCard.Activate

【问题讨论】:

  • 出于理解原因,请分享您已经完成的编码
  • @FatTony 我想将pdf的缩放级别设置为fittovisible
  • 您是否尝试过录制您手动对 PDF 执行操作的宏?
  • 您使用的是哪个 pdf 查看器?

标签: excel pdf-generation vba


【解决方案1】:

Adobe 有一组代码可供您在打开文档时使用:

http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf

请注意,这些命令仅适用于经批准的 Adob​​e Reader,并非所有 PDF 阅读器都接受这些命令。

您可能必须让 Acrobat 手动设置条件per this answer on the Adobe Help Forums

关于 OP:“如何设置默认以 100% 打开所有 PDF 放大倍率?”

使用 Acrobat Pro,运行批处理(序列)/动作来运行 “打开选项”序列。此序列允许设置值 PDF 文档属性的初始视图选项卡下的所有项目。

关于 PDF 的文档属性 > 初始视图:访问打开的 PDF 的文档属性(Ctrl+D、Cmd+D)。转到初始视图选项卡。 顶部窗格(布局和放大)允许配置:

导航选项卡:仅页面 |书签面板和页面 |页面面板和 页 |附件面板和页面 |图层面板和页面页面布局: 默认 |单页 |单页连续 |两个向上(面对) | 二合一(封面) |两合一连续(封面)放大倍率: 默认 |实际尺寸 |适合页面 |适合宽度 |适合身高 |合身 可见 |放大百分比(25% 到 6400%)

“默认”以外的配置设置决定了 PDF 的格式 最初查看。

初始视图中所有窗格中所有值的设置可能是 通过使用批处理序列/操作为一个或多个 PDF 建立 (需要 Acrobat Pro)。

此功能在企业环境中使用 大型文档集合部署在 LAN/WAN“电子图书馆”中 为最终用户提供一致的初始视图。

它还为内容作者提供了一种机制来建立 他们的部署内容(例如 PDF 文档)的初始视图 分布在光存储介质上的集合)。

关于创建的 PDF 的典型默认初始视图:当 PDF 通过 Acrobat 创建 PDF 文档的默认初始视图 布局和放大倍数是: --|导航:仅页面 --|页面布局:默认 --|放大倍率:默认 --|打开页面:1

关于 Open Parameters 文档 - 虽然此文档确实 提供一些命令行选项文档的主要重点是 使用 URL 打开 URL 的目标 PDF 的初始打开。

值得注意的是,该文档是特定于 URL 而不是 适用于 UNC 链接(与 LAN/WAN 的链接)。

【讨论】:

    【解决方案2】:

    如果我理解了您的要求,您需要调整打印区域的宽度和高度(因为导出为 PDF 就像打印一样)。你有.PageSetup.FitToPagesWide = 1 语句,现在你还需要.FitToPagesTall = 1,所以你的代码看起来像:

        With wksSalesAndQuotaScoreCard
                '.PageSetup.LeftMargin=Application.InchesToPoints(0.7)
                .PageSetup.LeftMargin = Application.InchesToPoints(0.7)
                .PageSetup.RightMargin = Application.InchesToPoints(0.7)
                .PageSetup.TopMargin = Application.InchesToPoints(0.75)
                .PageSetup.BottomMargin = Application.InchesToPoints(0.75)
                .PageSetup.HeaderMargin = Application.InchesToPoints(0.3)
    
                .PageSetup.Orientation = xlLandscape
                .PageSetup.PrintTitleRows = "_SalesandQuotaScoreCardView"
                .PageSetup.CenterHorizontally = True
                .PageSetup.Order = xlDownThenOver
                .PageSetup.FitToPagesWide = 1
                .FitToPagesTall = 1
                ''.PageSetup.Zoom = 50
                Set rngSalesAndQuotaView = Range(.Shapes("_SalesandQuotaViewFrame").TopLeftCell.Offset(0, -1), .Shapes("_SalesandQuotaViewFrame").BottomRightCell.Offset(1, 0))
                rngSalesAndQuotaView.Select
        End With
    

    如果这不是解决方案,请为您解释一下fittovisible 是什么。

    【讨论】:

    • 我想在导出的 pdf 中将缩放百分比设置为某个级别。这样用户在打开它时不必手动设置它。我曾尝试使用.pagesetup.zoom,但此属性不会改变导出 pdf 的缩放级别。我正在寻找一种方法来设置导出的 pdf 的缩放级别。
    • .pagesetup.zoom 会影响您的打印区域将占据多少打印页面的表面,因此如果您将其设置为.pagesetup.zoom = 10,那么您要导出为 PDF 的大部分 A4 页面将是空白的, 除了左上角的这个小区域。
    • 据我所知,PDF 文件不包含任何指定特定缩放比例的参数,该参数将在打开文件时使用。这取决于您打开文件的方式。例如,您可以在 Acrobat Professional 中设置默认缩放。如果您在互联网上发布您的 PDF,您可以通过 URL 中的一些参数来修改打开缩放,请参阅:partners.adobe.com/public/developer/en/acrobat/…
    【解决方案3】:

    “缩放级别”不是 PDF 文件的文档属性,而是应用程序属性。最多,我们能做的,直接从 excel 宏打开 PDF 文件,并使用“SendKeys”设置所需的缩放级别。

    请参阅下面对我有用的代码:

    Function PDFOpenFile(inPath As String, inPageNo As Long, inZoom As Variant)
     'This function opens the PDF document with the specified
     'Page number and zoom level
     'The Page Number and Zoom Level are simulated through SendKeys method
     '  ************ Important *******************
     ' When the macro runs, do not use the keyboard
     ' else the SenKeys may not function as desired
    
     ThisWorkbook.FollowHyperlink inPath, NewWindow:=True
     SendKeys ("^+N" & inPageNo & "~^" & inZoom), True
    End Function
    
    Sub MyDocument()
     ' After file name, the firt parameter is for page no, the second parameter    is for zoom level
     PDFOpenFile "D:\MyFile.pdf", 3, 3
    
     ' Zoom Level Details
     '0: Full Page
     '1: Zoom to 100%
     '2: Page Width
     '3: Fit visible
     '4: visible width / Reflow
    
     ' These zoom level are visible in acrobat reader. Go to "View > Zoom" and see the shortcut mentioned
     ' If the shortcuts are different for your case, you may modify the parameter passed as argument
    End Sub
    

    【讨论】:

      【解决方案4】:

      我使用 PDFCreator 打印了一张“无缩放”和“在一页上放一张纸”的表格。两者的区别是

      .Zoom = 100
      

      .Zoom = False
      .FitToPagesWide = 1
      .FitToPagesTall = 1
      

      我认为这将取决于“打印机”。当您简单地另存为 PDF 时,您不会获得这些选项,但结果也不错。

      Range("A1:H34").Select
      Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
      "C:\myfile.pdf", Quality:= _
       xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
       OpenAfterPublish:=False
      

      我认为很大程度上取决于您创建 PDF 的方式。

      【讨论】:

        【解决方案5】:

        打印设置因计算机而异,因为只有默认打印机定义了“打印区域”。在 Excel、Word 等中也是如此。

        因此,您无法为所有计算机定义它,除非您访问文档的所有计算机都设置为相同的默认打印机。

        【讨论】:

          【解决方案6】:

          我认为这是作为打印区域设置,您需要先在 excel 中设置,然后再导出为 PDF。首先在页面布局中或在上面代码的“With”块中执行此操作,然后运行导出为 PDF 的代码。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-11-22
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-06-03
            • 1970-01-01
            相关资源
            最近更新 更多