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 Manager
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 Manager
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



 

You must be signed in to post in this forum.