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

Question

Question

Create document/set metadata/add pages

SDK
asked on June 26, 2017 Show version history

Good afternoon,

I am working on a c# application for a client.  One of the tasks is for it to insert a document, set some metadata and import any supporting document provided.  I have everything working except for the importing of supporting documents.  These documents will be in the form of PDF/ms-office format/or other types of content that is compatible with Laserfiche.  I will not have access to the physical documents, no local copy to read from.  So - only a binary or string representation that has been pulled from SQL or some other data store.  This data is being passed into my routine as documentContents below.



                FolderInfo parentFolder = Folder.GetFolderInfo(folder, _currentSession);
                DocumentInfo document = new DocumentInfo(_currentSession);
                document.Create(parentFolder, documentName, EntryNameOption.None);
                document.SetTemplate(templateName);

////////////////stuck here :(
                byte[] documentBytes = Encoding.UTF8.GetBytes(documentContents);
                PageInfo newPage = document.AppendPage();
                System.IO.Stream pageStream = newPage.WritePagePart(PagePart.Image, documentBytes.Length);
                pageStream.Write(documentBytes, 0, documentBytes.Length);
                pageStream.Dispose();
                newPage.Save();
////////////////stuck here :(

                document.SetFieldValues(fv);
                document.Save();
                return document;

The end result of this call is as follows:

Any help or guidance would be appreciated.  I will continue to scour the support/answers forum as well. 

 

0 0

Replies

replied on June 26, 2017

Version II looks like this.  No errors generated but also no document is available.

Hard coded pdf mime type

documentContents = I opened a PDF into notepad and pasted the contents into my testing app

                byte[] documentBytes = Encoding.ASCII.GetBytes(documentContents);
                using (System.IO.Stream edocStream = document.WriteEdoc("application/pdf", documentBytes.Length))
                {
                    edocStream.Write(documentBytes, 0, documentBytes.Length);
                }
                document.Extension = ".pdf";

At least Laserfiche knows it is supposed to be a PDF which is a positive sign... i think.

 

0 0
replied on June 26, 2017

Yes, this is a step in the right direction.  Pages can only contain single tiff images, you can't put pdfs in there.

Encoding.ASCII.GetBytes(documentContents)

This is probably not right.  Find out what kind of encoding the data was stored in SQL with.  If it really is a text field then my guess would be base64 encoding, but it's also possible it's stored in SQL as a blob and you just need to get the bytes directly.

0 0
replied on June 26, 2017

Thanks for the update.  For my dumbed down test just to get this working...  I am literally loading this PDF into notepad/cutting/pasting it into my test form - this is the contents of documentContents.

I think I have tried all of the encoding options C# has for me and none have panned out.  I feel really stumped at the moment.

                byte[] documentBytes = Encoding.Default.GetBytes(documentContents);
                using (System.IO.Stream edocStream = document.WriteEdoc("application/pdf", documentBytes.LongLength))
                {
                    edocStream.Write(documentBytes, 0, documentBytes.Length);
                }
                document.Extension = ".pdf";

 

hello.pdf (81.14 KB)
0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.