diff --git a/.nuget/NuGet.exe b/.nuget/NuGet.exe index 6bb79fe..94cbc3a 100644 Binary files a/.nuget/NuGet.exe and b/.nuget/NuGet.exe differ diff --git a/OfficeToPDF/ExcelConverter.cs b/OfficeToPDF/ExcelConverter.cs index 6fe539c..fce2a4d 100644 --- a/OfficeToPDF/ExcelConverter.cs +++ b/OfficeToPDF/ExcelConverter.cs @@ -103,6 +103,7 @@ class ExcelConverter: Converter Boolean showFormulas = (Boolean)options["excel_show_formulas"]; Boolean isHidden = (Boolean)options["hidden"]; Boolean screenQuality = (Boolean)options["screen"]; + Boolean fitToPageWidth = (Boolean)options["excel_fit_to_page_width"]; Boolean updateLinks = !(Boolean)options["excel_no_link_update"]; int maxRows = (int)options[@"excel_max_rows"]; int worksheetNum = (int)options["excel_worksheet"]; @@ -174,7 +175,6 @@ class ExcelConverter: Converter { workbook.RunAutoMacros(XlRunAutoMacro.xlAutoOpen); } - // Get any template options SetPageOptionsFromTemplate(app, workbooks, options, ref templatePageSetup); @@ -224,7 +224,6 @@ class ExcelConverter: Converter return (int)ExitCode.WorksheetNotFound; } } - if (showFormulas) { // Determine whether to show formulas @@ -251,7 +250,6 @@ class ExcelConverter: Converter activeWindow.Visible = false; } } - // Keep track of the active sheet if (workbook.ActiveSheet != null) { @@ -288,7 +286,8 @@ class ExcelConverter: Converter if (activeSheet is _Worksheet) { itemIndex = ((Worksheet)activeSheet).Index; - } else if (activeSheet is _Chart) + } + else if (activeSheet is _Chart) { itemIndex = ((Microsoft.Office.Interop.Excel.Chart)activeSheet).Index; } @@ -316,7 +315,6 @@ class ExcelConverter: Converter { pageSetup = ((Worksheet)ws).PageSetup; pageSetup.PrintHeadings = true; - } catch (Exception) { } finally @@ -410,6 +408,14 @@ class ExcelConverter: Converter workbook.SaveAs(tmpFile, fmt, Type.Missing, Type.Missing, Type.Missing, false, XlSaveAsAccessMode.xlNoChange, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing); + // Fit to to one page wide. + if (fitToPageWidth) + { + templatePageSetup["FitToPagesWide"] = 1; + templatePageSetup["FitToPagesTall"] = false; + templatePageSetup["Zoom"] = false; + } + if (onlyActiveSheet) { // Set up a delegate function for times we want to print @@ -471,21 +477,20 @@ class ExcelConverter: Converter { workbook.PrintOutEx(ActivePrinter: printer, PrintToFile: true, PrToFileName: destination); }; - if (HasTemplateOption(options)) + + // Set up the template page setup options on all the worksheets + // in the workbook + var worksheets = workbook.Worksheets; + for (int wsIdx = 1; wsIdx <= worksheets.Count; wsIdx++) { - // Set up the template page setup options on all the worksheets - // in the workbook - var worksheets = workbook.Worksheets; - for (int wsIdx = 1; wsIdx <= worksheets.Count; wsIdx++) - { - var ws = worksheets[wsIdx]; - var wps = (ws is _Worksheet) ? ((_Worksheet)ws).PageSetup : ((_Chart)ws).PageSetup; - SetPageSetupProperties(templatePageSetup, wps); - ReleaseCOMObject(wps); - ReleaseCOMObject(ws); - } - ReleaseCOMObject(worksheets); + var ws = worksheets[wsIdx]; + var wps = (ws is _Worksheet) ? ((_Worksheet)ws).PageSetup : ((_Chart)ws).PageSetup; + SetPageSetupProperties(templatePageSetup, wps); + ReleaseCOMObject(wps); + ReleaseCOMObject(ws); } + ReleaseCOMObject(worksheets); + if (String.IsNullOrEmpty((string)options["printer"])) { try @@ -666,18 +671,20 @@ protected static void SetPageSetupProperties(Hashtable tps, PageSetup wps) { return; } - var wpsType = wps.GetType(); for (int i = 0; i < templateProperties.Length; i++) { - object[] value = { tps[templateProperties[i]] }; - try + if (tps.ContainsKey(templateProperties[i])) { - wpsType.InvokeMember(templateProperties[i], System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.SetProperty, Type.DefaultBinder, wps, value); - } - catch(Exception) - { - Console.WriteLine("Unable to set property {0}", templateProperties[i]); + object[] value = { tps[templateProperties[i]] }; + try + { + wpsType.InvokeMember(templateProperties[i], System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.SetProperty, Type.DefaultBinder, wps, value); + } + catch (Exception) + { + Console.WriteLine("Unable to set property {0}", templateProperties[i]); + } } } } diff --git a/OfficeToPDF/OfficeToPDF.csproj b/OfficeToPDF/OfficeToPDF.csproj index 11975dc..d8c3abb 100644 --- a/OfficeToPDF/OfficeToPDF.csproj +++ b/OfficeToPDF/OfficeToPDF.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,7 +11,7 @@ Properties OfficeToPDF OfficeToPDF - v4.0 + v4.8 512 @@ -48,6 +48,7 @@ DEBUG;TRACE prompt 4 + false x86 @@ -57,6 +58,7 @@ TRACE prompt 4 + false true @@ -67,6 +69,7 @@ prompt false false + false bin\x64\Release\ @@ -78,6 +81,7 @@ false false false + false bin\x86\Release-signed\ @@ -89,6 +93,7 @@ false false false + false bin\x64\Release-signed\ @@ -100,6 +105,7 @@ false false false + false diff --git a/OfficeToPDF/PowerpointConverter.cs b/OfficeToPDF/PowerpointConverter.cs index a68e91a..cdb3c9a 100644 --- a/OfficeToPDF/PowerpointConverter.cs +++ b/OfficeToPDF/PowerpointConverter.cs @@ -162,6 +162,7 @@ class PowerpointConverter : Converter // sneaky method of getting the presentation - create an empty presentation // and insert the slides from the original file. Fonts fonts = null; + Boolean bitmapMissingFonts = !(Boolean)options["powerpoint_ref_fonts"]; try { fonts = activePresentation.Fonts; @@ -195,7 +196,7 @@ class PowerpointConverter : Converter { try { - activePresentation.ExportAsFixedFormat(outputFile, PpFixedFormatType.ppFixedFormatTypePDF, quality, MSCore.MsoTriState.msoFalse, PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, printType, MSCore.MsoTriState.msoFalse, null, PpPrintRangeType.ppPrintAll, "", includeProps, true, includeTags, true, pdfa, Type.Missing); + activePresentation.ExportAsFixedFormat(outputFile, PpFixedFormatType.ppFixedFormatTypePDF, quality, MSCore.MsoTriState.msoFalse, PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, printType, MSCore.MsoTriState.msoFalse, null, PpPrintRangeType.ppPrintAll, "", includeProps, true, includeTags, bitmapMissingFonts, pdfa, Type.Missing); } catch (Exception) { if (!String.IsNullOrEmpty((string)options["fallback_printer"])) { diff --git a/OfficeToPDF/Program.cs b/OfficeToPDF/Program.cs index 545c0db..79b2765 100644 --- a/OfficeToPDF/Program.cs +++ b/OfficeToPDF/Program.cs @@ -105,6 +105,7 @@ static void Main(string[] args) options["excel_active_sheet"] = false; options["excel_no_link_update"] = false; options["excel_no_recalculate"] = false; + options["excel_fit_to_page_width"] = false; options["excel_max_rows"] = (int) 0; options["excel_worksheet"] = (int) 0; options["excel_delay"] = (int) 0; @@ -129,6 +130,8 @@ static void Main(string[] args) options["original_filename"] = ""; options["original_basename"] = ""; options["powerpoint_output"] = ""; + options["powerpoint_ref_fonts"] = false; + options["pdf_page_mode"] = null; options["pdf_page_mode"] = null; options["pdf_layout"] = null; options["pdf_merge"] = (int) MergeMode.None; @@ -162,7 +165,7 @@ static void Main(string[] args) { "excel_delay", "Excel delay milliseconds" } }; - Regex switches = new Regex(@"^/(version|hidden|markup|readonly|bookmarks|merge|noquit|print|(fallback_)?printer|screen|pdfa|template|writepassword|password|help|verbose|exclude(props|tags)|excel_(delay|max_rows|show_formulas|show_headings|auto_macros|template_macros|active_sheet|worksheet|no_recalculate|no_link_update)|powerpoint_(output)|word_(show_hidden|header_dist|footer_dist|ref_fonts|no_field_update|field_quick_update(_safe)?|max_pages|keep_history|no_repair|fix_table_columns|show_(comments|revs_comments|format_changes|ink_annot|ins_del|all_markup)|markup_balloon)|pdf_(page_mode|append|prepend|layout|clean_meta|owner_pass|user_pass|restrict_(annotation|extraction|assembly|forms|modify|print|accessibility_extraction|full_quality))|working_dir|\?)$", RegexOptions.IgnoreCase); + Regex switches = new Regex(@"^/(version|hidden|markup|readonly|bookmarks|merge|noquit|print|(fallback_)?printer|screen|pdfa|template|writepassword|password|help|verbose|exclude(props|tags)|excel_(delay|max_rows|show_formulas|show_headings|auto_macros|template_macros|active_sheet|worksheet|no_recalculate|no_link_update|fit_to_page_width)|powerpoint_(output|ref_fonts)|word_(show_hidden|header_dist|footer_dist|ref_fonts|no_field_update|field_quick_update(_safe)?|max_pages|keep_history|no_repair|fix_table_columns|show_(comments|revs_comments|format_changes|ink_annot|ins_del|all_markup)|markup_balloon)|pdf_(page_mode|append|prepend|layout|clean_meta|owner_pass|user_pass|restrict_(annotation|extraction|assembly|forms|modify|print|accessibility_extraction|full_quality))|working_dir|\?)$", RegexOptions.IgnoreCase); for (int argIdx = 0; argIdx < args.Length; argIdx++) { string item = args[argIdx]; @@ -1074,11 +1077,14 @@ page settings from the first worksheet in the template the file. Applies when converting with Excel. /excel_no_link_update - Do not update links when opening Excel files. /excel_no_recalculate - Skip automatic re-calculation of formulas in the workbook. + /excel_fit_to_page_width - Scale each page to fit on one page wide. /excel_template_macros - Run Auto_Open macros in the /template document before conversion by Excel /excel_worksheet - Only convert worksheet in the workbook. First sheet is 1 /powerpoint_output - Controls what is generated by output. Possible values are slides, notes, outline, build_slides, handouts and multi-page handouts using handout2, - handout3, handout4, handout6 and handout9. The default is slides. + handout3, handout4, handout6 and handout9. The default is slides. + /powerpoint_ref_fonts - When fonts are not available, a reference to the font is used in + the generated PDF rather than a bitmapped version. The default is /word_header_dist - The distance (in points) from the header to the top of the page. /word_footer_dist - The distance (in points) from the footer to the bottom diff --git a/OfficeToPDF/Properties/AssemblyInfo.cs b/OfficeToPDF/Properties/AssemblyInfo.cs index 11bf119..842a2ee 100644 --- a/OfficeToPDF/Properties/AssemblyInfo.cs +++ b/OfficeToPDF/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.0.3")] -[assembly: AssemblyFileVersion("1.9.0.3")] +[assembly: AssemblyVersion("1.9.2.0")] +[assembly: AssemblyFileVersion("1.9.2.0")] diff --git a/OfficeToPDF/README.txt b/OfficeToPDF/README.txt index 650ae73..077495e 100644 --- a/OfficeToPDF/README.txt +++ b/OfficeToPDF/README.txt @@ -71,6 +71,7 @@ The following optional switches can be used: the file. Applies when converting with Excel /excel_no_link_update - do not update links when opening Excel files /excel_no_recalculate - skip automatic re-calculation of formulas in the workbook + /excel_fit_to_page_width - Scale each page to fit on one page wide. /excel_template_macros - run Auto_Open macros in the /template document before conversion by Excel /excel_worksheet - only convert worksheet in the workbook. First sheet is 1 /fallback_printer - prints the image to the postscript printer with name if the export failes - requires GhostScript diff --git a/OfficeToPDF/app.config b/OfficeToPDF/app.config index a6469ea..f659eed 100644 --- a/OfficeToPDF/app.config +++ b/OfficeToPDF/app.config @@ -1,14 +1,14 @@ - + - - + + - + diff --git a/README.md b/README.md index 8775f94..510a665 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ The following optional switches can be used: | /excel_auto_macros | run Auto_Open macros in Excel files before conversion | | /excel_no_link_update | do not update links when opening Excel files | | /excel_no_recalculate | skip automatic re-calculation of formulas in the workbook | +| /excel_fit_to_page_width | Scale each page to fit on one page wide | | /word_header_dist _pts_ | the distance (in points) from the header to the top of the page | | /word_footer_dist _pts_ | the distance (in points) from the footer to the bottom of the page | | /word_field_quick_update | perform a fast update of fields in Word before conversion | diff --git a/docs/Documentation.html b/docs/Documentation.html index 05d198e..eefa7ea 100644 --- a/docs/Documentation.html +++ b/docs/Documentation.html @@ -124,6 +124,10 @@

Command line switches

skip automatic re-calculation of formulas in the workbook +/excel_fit_to_page_width +Scale each page to fit on one page wide. + + /word_header_dist <pts> the distance (in points) from the header to the top of the page @@ -153,6 +157,10 @@

Command line switches

when fonts are not available, a reference to the font is used in the generated PDF rather than a bitmapped version. The default is for a bitmap of the text to be used +/powerpoint_ref_fonts +when fonts are not available, a reference to the font is used in the generated PDF rather than a bitmapped version. The default is for a bitmap of the text to be used + + /pdf_clean_meta <type> allows for some meta-data to be removed from the generated PDF.
<type> can be: