{"id":11099,"date":"2022-07-27T10:05:21","date_gmt":"2022-07-27T17:05:21","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/?p=11099"},"modified":"2022-07-27T13:58:05","modified_gmt":"2022-07-27T20:58:05","slug":"changes-in-export-to-pdf-with-sensitivity-labelling-and-encryption-in-office-add-ins","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/changes-in-export-to-pdf-with-sensitivity-labelling-and-encryption-in-office-add-ins\/","title":{"rendered":"Changes in Export to PDF with sensitivity labeling and encryption in Office Add-ins"},"content":{"rendered":"<p><span data-contrast=\"auto\">Office is shipping a new feature that enables PDFs created from Office using <strong>Export to PDF<\/strong> or <strong>Save As PDF<\/strong> to retain the source document\u2019s labels or encryption into the output PDF. Office also enables Office Add-in developers to hook into and reuse some or all of Office\u2019s PDF creation code. This feature may cause some add-ins to fail and may require development effort to adjust to new Office behavior. This applies to VBA for Word, PowerPoint, Excel.<\/span><\/p>\n<h2><span data-contrast=\"none\">Potential challenges to existing VBA add-ins<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"auto\">For add-ins that use an object model path such as the <\/span><a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/vba\/api\/word.document.exportasfixedformat2\"><span data-contrast=\"none\">Document.ExportAsFixedFormat2 method<\/span><\/a><span data-contrast=\"auto\"> to ask Office to export to PDF, if the add-in doesn\u2019t provide a custom <\/span><b><span data-contrast=\"auto\">IMsoDocExporter<\/span><\/b><span data-contrast=\"auto\"> instance via the <\/span><i><span data-contrast=\"auto\">FixedFormatExtClassPtr<\/span><\/i> <span data-contrast=\"auto\">argument, then the add-in will inherit Office\u2019s PDF code. If the source document is encrypted, the output PDF will also be encrypted with Microsoft IRM protection for PDFs. Your add-in may either fail or fail to produce meaningful results if it does any post-processing without knowing how to decrypt the PDF. Note that add-ins that provide a custom <\/span><b><span data-contrast=\"auto\">IMsoDocExporter<\/span><\/b><span data-contrast=\"auto\"> instance don\u2019t use Office\u2019s PDF encryption<\/span> <span data-contrast=\"auto\">logic and therefore shouldn\u2019t need to mitigate anything \u2014 you\u2019ll need to do your own PDF encryption, if desired.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2 aria-level=\"2\"><span data-contrast=\"none\">Transition period<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"auto\">As the Export to PDF feature launches, we\u2019re introducing a temporary mitigation to allow you time to update your add-ins. We\u2019ve disabled all requests via the object model to keep encryption for PDFs. At the appropriate time, we\u2019ll re-enable honoring the request, resulting in potential encrypted PDFs. <\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Word and PowerPoint offer object model arguments that allow the add-in to request keeping IRM settings for PDFs via the <\/span><b><span data-contrast=\"auto\">ExportAsFixedFormat<\/span><\/b><span data-contrast=\"auto\"> family of functions. Excel currently does not, but the setting defaults to TRUE. We\u2019ll also turn this to FALSE for the same time period to provide you adequate time to update your add-in. Word\u2019s argument is called <\/span><b><span data-contrast=\"auto\">KeepIRM<\/span><\/b><span data-contrast=\"auto\"> while PowerPoint\u2019s is called <\/span><b><span data-contrast=\"none\">KeepIRMSettings<\/span><\/b><span data-contrast=\"none\">. These arguments will be <\/span><span data-contrast=\"auto\">ignored and forced to FALSE for PDFs until we release an update to honor these settings again<\/span><span data-contrast=\"none\">.\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/07\/OM-flows-for-3rd-party-PDF-addins.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-11112\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/07\/OM-flows-for-3rd-party-PDF-addins.jpg\" alt=\"Flows for 3rd party PDF addins\" width=\"1600\" height=\"1675\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/07\/OM-flows-for-3rd-party-PDF-addins.jpg 1600w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/07\/OM-flows-for-3rd-party-PDF-addins-287x300.jpg 287w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/07\/OM-flows-for-3rd-party-PDF-addins-978x1024.jpg 978w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/07\/OM-flows-for-3rd-party-PDF-addins-768x804.jpg 768w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/07\/OM-flows-for-3rd-party-PDF-addins-1467x1536.jpg 1467w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/07\/OM-flows-for-3rd-party-PDF-addins-24x24.jpg 24w\" sizes=\"(max-width: 1600px) 100vw, 1600px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2 aria-level=\"2\"><span data-contrast=\"none\">How to update your Office Add-in<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"auto\">Add-ins need a way to decrypt PDFs programmatically if you want to adjust or alter the PDF file Office creates. The PDF will be encrypted with v2 of Microsoft\u2019s IRM for PDF specification. This results in a Microsoft Information Protection (MIP) encrypted PDF. One such way to decrypt these files is via the <\/span><a href=\"https:\/\/docs.microsoft.com\/en-us\/information-protection\/develop\/\"><span data-contrast=\"none\">MIP SDK<\/span><\/a><span data-contrast=\"auto\">. This can be used to decrypt the PDF on behalf of the user so the add-in can adjust the PDF contents, and then re-encrypt the PDF so as not to strip the protection from the newly encrypted PDF from Office. For an example of how to decrypt the PDF, see <\/span><a href=\"https:\/\/docs.microsoft.com\/information-protection\/develop\/quick-protection-encrypt-decrypt-text-cpp\"><span data-contrast=\"none\">Encrypt\/Decrypt text using the C++ MIP Protection SDK<\/span><\/a><span data-contrast=\"auto\">. For how to get what sensitivity labels the PDF has (if any), see <\/span><a href=\"https:\/\/docs.microsoft.com\/information-protection\/develop\/quick-file-list-labels-cpp\"><span data-contrast=\"none\">List sensitivity labels in a Microsoft Purview Information Protection tenant using C++ MIP SDK<\/span><\/a><span data-contrast=\"auto\">. From there, the MIP SDK can encrypt the PDF again.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Another option is for add-ins to pass FALSE for the <\/span><b><span data-contrast=\"auto\">KeepIRM\/KeepIRMSettings<\/span><\/b><span data-contrast=\"auto\"> flags. This won\u2019t solve the problem for Excel since Excel doesn\u2019t expose this argument to object model users. This also strips labels and encryption in the output PDF unnecessarily and may not be preferable for customers.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Down the road, we\u2019ll provide a preview program for this second phase of PDF protection from Office where organizations can opt-in to validate their flows against the updates where Office again honors the IRM settings flag for PDFs.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p>Happy coding!\nChris Dietsch | Senior Software Engineer | Microsoft Office Add-ins platform<\/p>\n<h3>Additional resources<\/h3>\n<p><a href=\"https:\/\/developer.microsoft.com\/office\">Office Add-ins Developer Center<\/a><\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/office\/vba\/api\/overview\/\">Office VBA Reference<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Office is shipping a new feature that enables PDFs created from Office using Export to PDF or Save As PDF to retain the source document\u2019s labels or encryption into the output PDF. Office also enables Office Add-in developers to hook into and reuse some or all of Office\u2019s PDF creation code.<\/p>\n","protected":false},"author":96864,"featured_media":11120,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11],"tags":[132,18,185,184,183,28,46,141,47],"class_list":["post-11099","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office-add-ins","tag-add-ins","tag-excel","tag-microsoft-excel","tag-microsoft-powerpoint","tag-microsoft-word","tag-office-add-ins","tag-powerpoint","tag-vba","tag-word"],"acf":[],"blog_post_summary":"<p>Office is shipping a new feature that enables PDFs created from Office using Export to PDF or Save As PDF to retain the source document\u2019s labels or encryption into the output PDF. Office also enables Office Add-in developers to hook into and reuse some or all of Office\u2019s PDF creation code.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/11099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/96864"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=11099"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/11099\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/11120"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=11099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=11099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=11099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}