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