How to automatically update fields in Office.js add-in for Word? - ms-word

I have an Office.js add-in that uses custom document properties. To update them i have to use deleteAll() because setting the value or a properties object gives weird generalexceptions and access denieds.
but deleting them all and adding them one by one works fine. But after the properties have been added, I have to press ctlr-A and F9 to update all the changed fields. Some are in headers footers so I have to select those and press ctrl-A/F9 there too.
In my VSTO i needed to call Word.application.activeDocument.fields.update() but is there something similar in Office.js? I scanned the API docs up and down but can't find a call that works. How do I update the fields in the document after I changed them?
In a docx we have a docProps/custom.xml which has something like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="schemas.openxmlformats.org/officeDocument/2006/…" xmlns:vt="schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2" name="Categorie">
<vt:lpwstr>My category</vt:lpwstr>
</property>
</Properties>
If we can bind those to content controls, that would be great. If that can be a 2way binding it would be awesome ;)

Related

How to disable options as printing in generated PDF file?

When I generate a PDF with jasper reports I don't want the user to be able to print it.
Is there some option to make it from the code or does it only depend on the program which visualize it (web browser,adobe etc.).
You can achive this both by using jrxml properties or setting values to the SimplePdfExporterConfiguration if you are exporting from java.
To protected your pdf document (hence in this case disallow printing), first thing you need to do is to encrypt it and be sure that you have nessary libraries for encryption in classpath see How to configure PDF encryption in JasperReports Server 5.6.1
jrxml properties
<property name="net.sf.jasperreports.export.pdf.encrypted" value="true"/>
<property name="net.sf.jasperreports.export.pdf.128.bit.key" value="true"/>
<property name="net.sf.jasperreports.export.pdf.owner.password" value="12345"/>
or
java code
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setEncrypted(true);
configuration.set128BitKey(true);
configuration.setOwnerPassword("1234");
Note we are setting owner password not user password, hence user will be allowed to open without.
Now set the user permissions
net.sf.jasperreports.export.pdf.permissions.allowed
In your case I guess you only like to allow screen readers, if you like to also allow COPY or other actions (see link above) add these with | to your properties
jrxml property
<property name="net.sf.jasperreports.export.pdf.permissions.allowed" value="SCREENREADERS"/>
or
java code
configuration.setPermissions(PdfWriter.ALLOW_SCREENREADERS);
Notice: it is up to the reader/application to respect the permission, hence a developer can always open and do what they want with any PDF document. As example iText contains a flag unethicalreading, if you set it to true, you will be able to have owner access to these documents without knowing the password.

Creating a working copy for Plone 4 custom content types

I have created a custom Plone content type in my package i.e. my.product.
I am in need of integrating a working copy support: so that a "published" document (in my case, a published content type) stays online while it is being edited. Basically, I want to take advantage of 'Working Copy Support (Iterate)' provided by plone.app.iterate to achieve what is explained here. This will provide me with ability to check-in/check-out my changes.
Is this possible in Plone 4 with custom content types using Archetypes? How would one go about it if yes?
I added the following two files inside my.product/my/product/profiles/default folder and it appears to work:
diff_tool.xml
<?xml version="1.0"?>
<object>
<difftypes>
<type portal_type="MyCustomType">
<field name="any" difftype="Compound Diff for AT types"/>
</type>
</difftypes>
</object>
repositorytool.xml
<?xml version="1.0"?>
<repositorytool>
<policymap>
<type name="MyCustomType">
<policy name="at_edit_autoversion"/>
<policy name="version_on_revert"/>
</type>
</policymap>
</repositorytool>
I have never used plone.app.iterate, but this is the generic approach how to solve the problem.
Actions are installed by plone.app.iterate GenericSetup profile. You can see actions here:
https://github.com/plone/plone.app.iterate/blob/master/plone/app/iterate/profiles/default/actions.xml
Pay note to the line *available_expr* which tells when to show the action or not. It points to helper view with the conditition.
The view is defined here
https://github.com/plone/plone.app.iterate/blob/master/plone/app/iterate/browser/configure.zcml#L7
The checks that are performed for the content item if it's archiveable
https://github.com/plone/plone.app.iterate/blob/master/plone/app/iterate/browser/control.py#L47
Most likely the failure comes from if not interfaces.IIterateAware.providedBy condition. Your custom contennt must declare this interface. However, you can confirm this putting a pdb breakpoint in checkin_allowed(self) and step it though line-by-line and see what happens with your content type.

NLog Event Log Target: problems with Source/Provider Name & message format

I'm trying to use NLog to log events for a new application to a file and to the Event Log. I'm almost there, but not quite - I can get events logged to the Event Log, and in the Details/XML view (of the Event Log) everything looks OK. But in the General tab of the viewer, I don't get the event message displayed as expected; instead I get "DRGImporterError"; this matches which happens to be the SymbolicName (see below) from my EventLogMessages.mc file, but when I modified this value and recompiled the error message file, this didn't change. The event log source is 'DRGImporter' as is the application name, so I can't be sure what 'DRGImporterError' actually refers to!
I've manually created and edited the registry entries storing the EventMessageFile location: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\MyAppLog\DRGImporter. Originally, I pointed this key to my custom EventLogMessages.dll, but in trying to debug it, I also set it to one of the standard DLLs under \Windows\Microsoft.NET\..., but it didn't change the outcome.
I have a number of other applications using the same event log, but these use a different logging framework. Nevertheless they work, but more curiously, if I change the source that NLog points to to one of these older ones, NLog entries are logged successfully and the General view in the event log shows the expected text. The only difference I can see from the XML view is the EventRecordID and the timestamp, which is to be expected.
Is there another element to this equation that I am missing?
EventLogMessages.mc:
;//***********Event Definitions**************
MessageId=2000
SymbolicName=MailerError
Language=English
%1.
.
MessageId=2100
SymbolicName=DRGImporterError
Language=English
%1.
.
NLog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true" autoReload="true" internalLogFile="nlog.log" internalLogLevel="Debug">
<targets>
<target name="eventLogHeaderTarget" xsi:type="EventLog" log="Hexadex" source="DRGImporter" eventId="0" layout="${message}" />
</targets>
<rules>
<logger name="appLogHeader" minlevel="Debug" writeTo="eventLogHeaderTarget" />
</rules>

JasperReports XLS export pagination and other issues

I'm having trouble with JasperReports 4.0.2 XLS export. The file comes out but it seems to have certain issues each time, no matter which configuration I try:
Column headers will disappear unless I disable graphics e.g. vertical line separating the headers and the data.
I cannot remove repeating page and column headers and have all the data as a single details block. The page numbers cannot be removed also.
The same template is used for PDF export (which should have pages) and XLS export (which should be without pages). For achieving the desired XLS export I've tried configuring the export with JRXlsExporter parameters in the java code as well as changing properties in the default.jasperreports.properties file.
This far I haven't found any actual documentation on the topic. Few forums posts in the JasperReports site seem not to be working.
The Problem is solved.
Somehow JasperReports ignored the properties set in the java code during the export process with JRXlsExporter class and the properties file. However, the same delcarations did work then added directly to the JRXML file. The working code to remove repeating headers is below:
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.1" value="pageHeader"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.2" value="pageFooter"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.2" value="columnHeader"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
The titles did disappear due to separator line being drawn on top of the titles themself. PDF could handle this but XLS did not. By adding a few pixels of space in between the titles and the separator the problem did solve.

Ribbon not showing up with dynamically generated ribbon XML from the database

I am trying to form ribbon XML with the data from the database and following is what I wrote:-
XNamespace xNameSpace = "http://schemas.microsoft.com/office/2006/01/customui";
XDocument document = new XDocument();
document.Add( new XElement (xNameSpace+"customUI"
, new XElement("ribbon"
, new XElement("tabs"))));
// more code to add the groups and the controls with-in the groups
.......
// code below to add ribbon XML to the document and to add the relationship
RibbonExtensibilityPart ribbonExtensibilityPart = myDoc.AddNewPart<RibbonExtensibilityPart>();
ribbonExtensibilityPart.CustomUI = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(ribbonXml.ToString());
myDoc.CreateRelationshipToPart(ribbonExtensibilityPart);
I don't see any error executing the above. However, when I open the changed document, I dont see my ribbon added. I see following in the CustomUI/CustomUI.xml inside the word:-
<?xml version="1.0" encoding="utf-8"?><customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon xmlns="">
<tabs>
.....
I am not sure how the "xmlns" attribute is getting added to the ribbon element. When I remove that attribute, the ribbon gets showed.
Could anybody throw any idea on where am I going wrong?
I ended up string replacing that string xmlns="" with empty string from the ribbon tag.