Publié Tue, 02 Jul 2019 06:42:44 GMT par Danny Davidson Senior Developer

Using Platform Services, can a document be downloaded WITH its stamps included (such as you would by opening the Web Client and selecting download -- any format there would include stamps)? I am fluent in using Platform Services to download documents and have configured "KeepAnnotations" to "true", but this question is about Stamps, not Annotations. There is no mention of this that I can find in the Platform Services documentation. In fact, not much mention of Stamps except in the direction of Stamping documents, not viewing those stamps. I was hoping there was, perhaps, a property of the FileDownload object --- but could not find one. Client is using DW version 6.11, but I would be interested in answers in more recent versions also.

Publié Tue, 02 Jul 2019 15:48:50 GMT par Joe Kaufman Bell Laboratories Inc No longer there
Danny,

I think I figured it out...

The comments for the DocuWare FileDownloadBase type helped:
 
public abstract class FileDownloadBase
{
    //
    // Summary:
    //     Creates a new instance of this class
    public FileDownloadBase();

    //
    // Summary:
    //     Specifies the annotation layers to be included in the output file.
    //
    // Remarks:
    //     This list is used only when KeepAnnotations flag is set to true; if this flag
    //     is set to false, then this list is ignored and no layers are included. In order
    //     to keep all layers, just set KeepAnnotations to true and pass an empty list or
    //     do not specify a list at all.
    [Dolphin]
    [XmlElement("Layers")]
    public List<int> Layers { get; set; }
    //
    // Summary:
    //     If this flag is true then the annotations are rendered in the PDF file, otherwise
    //     the annotations are removed.
    //
    // Remarks:
    //     This flag applies only to the PDF target format.
    [DefaultValue(true)]
    [XmlAttribute]
    public bool KeepAnnotations { get; set; }
}

So, the Layers property doesn't really matter, but KeepAnnotations only works for a target of PDF. I was using "Auto". When I switched it to be specifically "PDF", annotations and stamps downloaded with the file!

This is what my download routine looks like now in C#:
 
public static string SaveDocumentToFile(this Document document, string fileName = "")
{
    LastError = "";
    try
    {
        if (document.FileDownloadRelationLink == null)
        {
            document = document.GetDocumentFromSelfRelation();
        }

        FileDownloadType targetFileType = FileDownloadType.Auto;
        if (document.ContentType.ToUpper() == "application/pdf".ToUpper())
        {
            // Be specific about PDF otherwise KeepAnnotations will not work as desired.
            targetFileType = FileDownloadType.PDF;
        }

        var downloadResponse = document.PostToFileDownloadRelationForStreamAsync(
            new FileDownload()
            {
                TargetFileType = targetFileType,
                KeepAnnotations = true
            }).Result;

        var contentHeaders = downloadResponse.ContentHeaders;
        string defaultFileName = contentHeaders.ContentDisposition.FileName;
        // If there is a space in the file name, the content header filename will place escaped double-quote marks around the
        // file name. This is a problem for other file-name manipulation routines.
        defaultFileName = defaultFileName.Replace('"', ' ').Trim();
        string defaultExtension = VFP.JUSTEXT(defaultFileName);
        if (fileName.Length == 0)
        {
            // No file name passed in, so we should get a default file name for saving the document.
            fileName = VFP.PUTFILE(defaultFileName, defaultExtension, "Save As");
        }
        // If file name is empty at this point, it indicates user cancellation.
        if (fileName.Length == 0) return "";

        using (FileStream file = File.Create(fileName))
        {
            using (Stream stream = downloadResponse.Content)
            {
                stream.CopyTo(file);
            }
        }
        return fileName;
    }
    catch (Exception ex)
    {
        LastError = ex.Message;
        return "";
    }
}

Nevermind the "VFP" static function calls -- those are part of my VFP library that uses VFP function names to do things in native C#. The bottom line is that the file that gets pulled down specifically targets PDF if the content type of the document is in fact PDF, and then KeepAnnotations is honored properly. You don't need to set Layers to anything at all. You can also disregard "LastError" -- that is a static member field I use to set the last error if one occurs.

Hope this helps!

Thanks,
Joe Kaufman

 
Publié Wed, 03 Jul 2019 20:11:47 GMT par Danny Davidson Senior Developer
Joe,
Thanks so much for getting on this. Your answer helped explain part of my problem and I was able to solve the other part that I caused myself. In fact, now I wish I could rename the title of this post because the title will describe the issue backwards. Let me explain what I found... I am going to keep the concept of STAMP and ANNOTATION separate by capitalizing them.

First, it is ALWAYS possible to "download document WITH its STAMPS included". STAMPS always come over with the document when downloaded from Platform Services in any setting. My problem here was that I was not directly outputting the returned stream to a file. I had several process that determine the returned format of the result and transform them appropriately (unzip, convert image to pdf, etc). The last part of my process is that I merge the returned results into a single result and that is where I was losing the STAMPS. Thus, it is also possible to "download document WITHOUT its STAMPS included" by not flattening the file prior to merge ... as I proved accidentally.

Second, it is as you showed possible to "download document WITH its ANNOTATIONS included" by going thru the process you prescribe. Set you "TargetFIleType" to "FileDownloadType.PDF", not "FileDownloadType.Auto" and set the "KeepAnnotations" to "true". One can turn ANNOTATIONS on and off in this way ... but one CANNOT turn off STAMPS this way. I was already using the PDF setting because otherwise my conversion process fails later on. 

Sorry for all the capitalizations, but I hope this post helps some folks out there.

Joe.. thanks again for your help,
Danny Davidson
Publié Wed, 03 Jul 2019 20:39:28 GMT par Joe Kaufman Bell Laboratories Inc No longer there
Danny,

Glad you got things figured out! I am appreciative of your post because I realized using the straight HTTP calls from non-NET environments was not bringing down stamps and annotations. I had to utilize the longer URL to get those to come down, so now that works, too (in Visual FoxPro).

You state, "STAMPS always come over with the document when downloaded from Platform Services in any setting."... That was not the case for me. The first thing I did when I started researching your question was stamp a document and draw some annotations on it, and neither came down when I pulled the file down (just using a straight stream to file). Only when I changed the target type to PDF and set KeepAnnotations to true did they come down. (This behavior was the same using .NET and Visual FoxPro.) I never had a scenario where just one or the other showed up -- it was both or neither in every scenario I tried. Granted, I stopped testing various combinations of properties once I was able to get stamps and annotations to pull down, but still...

I think this thread should be helpful to future platform users downloading files!

Thanks,
Joe Kaufman



 
Publié Mon, 20 Jul 2020 15:43:54 GMT par Andrés Ledo
Hi, 

I tried with the code and works fine, but I have a problem with it. In the download document I get the UTC date.

How can change the date culture to Spain? (dd/MM/yyyy utc +2)
 
Publié Tue, 21 Jul 2020 07:39:00 GMT par Simon H. Hellmann Toshiba Tec Germany Imaging Systems GmbH IT-Consultant Document Management Solutions
Hi Andrés, 

DocuWare stores all dates in UTC format. You always need to do the conversion yourself if you want to do something with the local date. 
See this doc from Microsoft: https://docs.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones

Hope this helps. 

Greetings from Germany, 
Simon H. Hellmann
DocuWare System Consultant
Publié Tue, 21 Jul 2020 08:19:44 GMT par Andrés Ledo
Hi Simon, 

The problem is with stamp date. When downloading it from the Web, the date comes out correctly, but when doing it from the api it is downloaded in the MM\dd\yyyy utc format and I have not found any way to format it ...
Publié Mon, 08 Feb 2021 14:30:12 GMT par Fabian Kall - left 01.22
A somewhat aged thread, but I had the same problem and would like to give my solution:

Your client application needs to have an information about what localisation You want to have whenever You're retrieving data through the API. Per default it probable assumes english culture and language.

This is an information You can supply when You create Yuur ServiceConnection object.
The various static methods to do that accept an optional attribute 'httpClienHandler' of type HttpMessageHandler.

You can new up an HttpMessageHandler and then call the "add"-method on it's CookieContainer to add an object of type Cookie. The overloaded constructor of a cookie object can accept two String objects for the Culture information and language, as well as some other stuff that you will have available anyway like the domain.

As long as Your ServiceConnection is alove it will then be scoped with those localisation information which amongst othe things will mean that the automatic dates in workflow task stamps will be localised accordingly.

Here's a snippet to get You started:

Uri uri = new Uri($"{Settings.DwBaseUrl}/docuware/platform");
HttpClientHandler handler = new HttpClientHandler();
handler.CookieContainer.Add(new Cookie("DWFormatCulture", settings.DWFormatCulture, "/", uri.Host)); 
handler.CookieContainer.Add(new Cookie("DWLanguage", settings.DWLanguage, "/", uri.Host));
connection = ServiceConnection.Create(uri, username(), password(), httpClientHandler: handler, userAgent: userAgent);
 

You must be signed in to post in this forum.