You are viewing limited content. For full access, please sign in.

Question

Question

ExportPdf in WF Designer?

asked on May 26, 2022

I have a simple goal that’s probably just one line of code to be added (or change what’s there) to the following SDK script. A former associate wrote this script and no longer is with the company, so you all are my biggest hope. Here it is:

 

Protected Overrides Sub Execute()
            'Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session

        dim ex as new DocumentExporter


            dim doc as DocumentInfo = Document.GetDocumentInfo(integer.Parse(GetTokenValue("Entry ID")),RASession)

            ex.ExportPages(doc,new PageSet("1-" & doc.PageCount),"\\fsstl06\userdirs\Scanning\Emma_Securian\NB\STL\" & gettokenvalue("Entry ID") & ".tif")

        End Sub

What I want to do is export the document to PDF, assuming I would use the ExportPdf method on “ex”.  Also, how would I add metadata to the file name during the export? Thanks for the help!

0 0

Replies

replied on May 26, 2022

Paul,

Here is your code cleaned up a bit.  Some thoughts;

  • Since the DocumentInfo object exposes a 'Dispose' method you can wrap the code in a Using statement to properly handle cleanup of the object. 
  • I am using native the BoundEntryInfo and BoundEntryID to get a reference to the document that is bound to the Script activity instead of getting the token value of the Starting Entry and then instantiating a DocumentInfo from the static Document class.
  • As far as adding any metadata to the filename you would use the GetTokenValue method to retrieve that value and then concatenate that value into the filename.  (Much like the GetTokenValue("Entry ID") value that your code was using)
  • In the ExportPDF method there is a PdfExportOptions parameter that can be set to tweak options on the exported PDF but for this example I set those to 'None'.
  • Finally, I would probably do some validation to make sure the BoundEntry was indeed a document before executing the code.  (I didn't include that in the example below but could provide it if you need it)

 

        Protected Overrides Sub Execute()
            Dim ex as new DocumentExporter
            Dim pathAndFilename As String = String.Format("\\fsstl06\userdirs\Scanning\Emma_Securian\NB\STL\{0}.pdf", Me.BoundEntryId)

            Using docInfo As DocumentInfo = Me.BoundEntryInfo
                ex.ExportPdf(docInfo, docInfo.AllPages, PdfExportOptions.None, pathAndFilename)
            End Using
        
        End Sub

 

2 0
replied on May 26, 2022 Show version history

I'd recommend using at least the following options for PdfExportOptions so the documents are text searchable and stamps and such don't appear as editable objects (my code is in C# so it'll be a little different).

// Set PDF export options to flatten annotations and include searchable text
PdfExportOptions ExportOptions = PdfExportOptions.RenderAnnotationsAsImage | PdfExportOptions.IncludeText;

NOTE: When setting PdfExportOptions with multiple values, the values are separated by the single pipe/bar character.

 

It's also worth noting that things get a little more complicated if you have Watermarks on the documents from tags because they're not included automatically.

// Initialize document exporter
DocumentExporter dExp = new DocumentExporter();

// Build a list of watermarks and add tag watermarks associated with the document
List<WatermarkSpecification> watermarks = new List<WatermarkSpecification>();
foreach(TagWatermark w in doc.GetTagWatermarks()){
    watermarks.Add(new WatermarkSpecification(w.WatermarkText,w.WatermarkTextSize,w.WatermarkRotation,w.WatermarkPosition,String.Empty,0,String.Empty,0,w.WatermarkIntensity));
}

// Configure document exporter settings
dExp.IncludeAnnotations = true;
dExp.BlackoutRedactions = true;
dExp.PageFormat = DocumentPageFormat.Jpeg;
dExp.Watermarks = watermarks;

 

2 0
You are not allowed to follow up in this post.

Sign in to reply to this post.