While updating .docx file using docx4j, Read only fields become editable - docx

In my docx file we have some readonly fields but, While i'm updating docx file using docx4j library that read only fields become editable.
XML Block
In document we have some section and readonly block for guide the user and below that section we have added block for enter value.
Dependency
compile "org.docx4j:docx4j-JAXB-ReferenceImpl:8.3.4"

In Word, Review > Restrict Editing > Editing Restrictions > Filling in Forms
results in the following in the Document Settings part, word/settings.xml:
<w:documentProtection w:edit="forms" w:enforcement="1"/>
Check this value before and after manipulation with docx4j.
If it is changing, then something in your code is changing it.
Basically you want something like:
DocumentSettingsPart documentSettingsPart = getPkg().getMainDocumentPart().getDocumentSettingsPart();
documentSettingsPart.protectRestrictEditing(STDocProtect.FORMS, null, null);
See further https://github.com/plutext/docx4j/blob/VERSION_11_4_7/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/DocumentSettingsPart.java#L311

Related

Why is object in AOT marked with red cross?

I have to extend report's query to add a new field.
I've created extension of a query, joined required datasources and can see new field in the list of fields.
For some reason the report in the AOT is displaying with red cross sign:
In properties i can see error in metadata: "There was an error reading metadata. Make sure the metadata xml file(s) are accessible, are well formed and are not corrupted with duplicate or missing xml elements.
The exception message is: Element named: 'Copy1' of type 'ModelElement' already exists among elements: 'Copy1'.
Parameter name: item
Additional information:
AOT/Reports/Reports/WHSInvent"
There is an .xml of that object in packages local directory, there are no any duplicate names in any node of that report.
Any ideas how it can be fixed?
I've run into this before and there are a two things that come to mind.
Often times it's due to an incorrect merge where changes are merged and metadata is accidentally duplicated (in your case it's possible there are two xml nodes with the same name/id in the .rdl file)
If this report is checked in with corrupt metadata, you need to manually modify the RDL file, which is not great, but hopefully the error contains enough hints. Open the report rdl file in your favourite editor (report likely located in a similar path as this: K:\AosService\PackagesLocalDirectory\YOURMODEL\Reports) and look for an xml node with an attribute Name="Copy1". With luck, you have two duplicate nodes next to each other due to the merge. Remove the offending duplicate node, save, and refresh the AOT in Visual Studio.
If the error is in your local changes only (xml file is corrupted for whatever reason) and you are sure that your source control contains the correct version and you simply wish to overwrite the local contents with the source controlled version, follow these steps. Note: this will overwrite local changes.
First, undo pending changes.
Then force a get latest:

Set docx properties using library .docx

How to set properties like title, author, subject for a file created with docx library for .net ?
docx
The DocX project that you provided appears to be able to easily access the metadata properties that you are referring to and can do so quite easily by using the CoreProperties property as seen below :
// Load your Document
var wordFile = Novacode.DocX.Load(#"your-docx-file-path");
// Access Metadata properties
var props = wordFile.CoreProperties;
The issue here is that this collection of properties is read only, so you won't be able to easily change them. However, you may be able to take a look at what the values look like and attempt to add one manually :
So if you wanted to update the title property (clearly named dc:title), you would simply need to add a new Core Property (via the AddCoreProperty() method) that matched that same name and then save the file to persist the changes :
// Load your Document
var wordFile = DocX.Load(#"your-docx-file-path");
// Update Metadata
wordFile.AddCoreProperty("dc:title", "Example Title");
wordFile.Save();
After doing this, you should be able to re-open the file and see that your changes reflected :
As you can see the dc:title property is now set to "Example Title" as per the example code above.

Exported image filename customization from devexpress ReportPrintTool

I am using Devexpress XtraReport suite in my application which works fine for dynamic reporting requirement except one customization as below:
User is given report preview using ReportPrintTool with dynamic data.
Now, when user tries to export print preview as Image file with 'ExportMode=Different Files' output file names are generated based on report name(i.e. reportName+pageIndex.png) which i need to define based on some dynamic value or say based on a column value provided to report as data source.
Can anybody please guide me how can I achieve this customization?
Reference from: XtraReport default file name in SaveDialog box
Try to set the XtraReport.ExportOptions.PrintPreview.DefaultFileName option (PrintPreviewOptions.DefaultFileName Property).
PrintControl.PrintingSystem.ExportOptions.PrintPreview.DefaultFileName = "column value that you provide"
To know that how to use it, Follow the below reference links:
default name of report during saving - Here some file name standard related issue also descripbed
How modify predefined file name on exporting report
XtraReports - Custom filename when exporting via the reports toolbar

Getting fid of attached file in Drupal 7

I added an additional field with a type "File" to an "article" content type. Now I need to get a fid of the uploaded file in hook_node_view(). I use for this the next code:
$my_form['fid']['#value'] = $node->field_image_svg[$node->language][0]['fid'];
The problem is that when I check "Include file in display" before saving a node, I get a fid correctly. But when I do not check, I get a warning:
Notice: Undefined offset: 0 in testmodule_node_view()
What's the problem? Is there way to get a fid of an uploaded file not depending on whether the file is displayed or not?
You are using the Enable Display field setting for the file field:
When the "Include file in display" checkbox is checked, you allow it to be rendered in the view mode of the node and so your field gets added into the language array of the field_image_svg field:
$node->field_image_svg[$node->language][0]['fid']
If unchecked it will not be allowed to and the language array will not keep the file information:
$node->field_image_svg[$node->language]
So if you want to get the fid not depending on that checkbox and still use it as a setting, you are forced to make a check on wether it exists or not to get rid of the notice and instead get the fid with:
$fid = db_query('SELECT fid FROM {file_usage} WHERE id = :id',array(':id' => $node->nid))->fetchField();
Another solution would be to remove the checbox (in field settings) and manage it to be hidden or shown through Manage display. This will keep the file's information in hook_node_view.
Hope this helps.

Converting RTF to PDF from System

I've createad a rule to transform any file to PDF and copy this one to another folder.
So i can add a file named: "test.rtf" and then the rule create a test.pdf into folder "PDF"..
Till here its ok. If i add a file through alfresco (add content button) it works perfectly...
By the way, on the system that i've developed when i try to add a file then i get my file .rtf correctly in the folder, but the pdf file converted and copied goes without any content...
If i send a rtf file with a table with 10 rows and into the rows i right "testing" then the pdf created goes with the table, and with 10 empty rows...
Someone knows the reason for that?
Im not sure, but maybe when i send the file by the system alfresco starts to convert and copy before completing to create the rtf... someone already got some problem like this one?
The problem you're getting in is that Alfresco first creates an empty file with all the meta-data and then updates the file with the associated content.
So you can do 2 things:
1: create a rule which is triggered on update, instead on create/inbound
2: create a rule which triggers a Javascript file, which will do the transformation and will check on the content size.
Hence it's better to create a rule which checks the content on size.
Create a JavaScript file in Data Dictionary/Scripts.
Check the JavaScript API
Something like this:
if (document != null && document.size > 0){
document.transformDocument("application/rtf");
}

Resources