Export discontinuous range of pages to PDF

旧城冷巷雨未停 提交于 2020-01-15 10:17:32

问题


I am trying to save a Word template in .pdf format. I need to print the following range (1-3,18). The problem is that using "ExportAsFixedFormat2" does not allow me to select that range or at least I dont know how:

wdapp.ActiveDocument.ExportAsFixedFormat2 OutputFileName:=savenamepdf, ExportFormat:=wdExportFormatPDF, Range:=wdExportFromTo, From:=1, To:=3

If I use "printout" I can select the range and create the pdf file, but when I try to open it I get an error message like it is broken or corrupted:

 wdapp.ActiveDocument.PrintOut OutputFileName:=savenamepdf,_ Range:=wdPrintRangeOfPages, Copies:=1, Pages:="1-3,18"

Anyone knows how to print that range?

here is the whole code block

Select Case cell
   Case 100
      With wdApp                    
        .ActiveDocument.SaveAs2Filename:=savenameword,ReadOnlyRecommended:=False           
        .ActiveDocument.ExportAsFixedFormat2OutputFileName:=savenamepdf,ExportFormat:=wdExportFormatPDF,Range:=wdExportFromTo, From:=1, To:=4
        .ActiveDocument.Close
      End With

   Case 189
      With wdApp
        .ActiveDocument.SaveAs2 savenameword
        .ActiveDocument.PrintOut OutputFileName:=savenamepdf,Range:=wdPrintRangeOfPages, Copies:=1, Pages:="1-3,18"
        .ActiveDocument.Close
      End With
End Select

回答1:


What you want is not supported. The only way around it would be to bring together the content into a different/new document, then save that to PDF.

Or, a copy of the document can be opened in Word, the material that's no wanted deleted, then save the document as PDF.

The PrintOut method to a file generates a text file that can later be sent to the printer. It's in a special format and the Word content is in a binary format. It's not a converter to other file formats, even if you append a pdf extension to the file name, the content won't be PDF.

For more information about what printing to a file is used for:

https://answers.microsoft.com/en-us/windows/forum/windows_vista-windows_programs/what-does-print-to-file-mean/2e73491c-634f-4067-8b7e-c158f647129d

https://word.tips.net/T000462_Printing_to_a_File.html

http://ask-leo.com/what_is_print_to_file_used_for.html



来源:https://stackoverflow.com/questions/57821938/export-discontinuous-range-of-pages-to-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!