Saving Aspose.Slides.Presentation prevents file from being opened - aspose

I am attempting to modify a Presentation file with Aspose.Slides.
var fileMemoryStream = new MemoryStream();
await fileMemoryStream.WriteAsync(file.FileData, 0, file.FileData.Length);
Presentation pres = new Presentation(fileMemoryStream);
IDocumentProperties pptProperties = pres.DocumentProperties;
pptProperties.Title = "test";
pres.Save(fileMemoryStream, Aspose.Slides.Export.SaveFormat.Pptx);
fileMemoryStream.Position = 0;
fileData = fileMemoryStream.ToArray();
var contentType = fileProperties.MimeTypes.ContainsKey(file.Extension) ? fileProperties.MimeTypes[file.Extension]: "application"+file.Extension.Replace(".", "/");
var fileConvert = File(fileData, contentType, exemplarFile.DownloadName + file.Extension);
Ff I comment out the pres.Save line, the file works. If I don't, it won't open and I'm left with the message below.
"Powerpoint found a problem with content in path.pptx. Powerpoint can attempt to repair the presentation."
If I comment out pptProperties.Title = "test";, it does not work. setting the fileMemoryStream to zero at the beginning does not work. I must be missing a step in the Aspose process, or the memorystream process. Any ideas?
Note: the file being tested is a pptx file and the Mimetype is correct
application/vnd.openxmlformats-officedocument.presentationml.presentation

I'm not sure what was happening, but saving the pres to a new MemoryStream instead of the current one worked.
If anyone has an idea as to why this is feel free to post, but this is what solved this.

Related

unable to create a document with raw content on dialog flow knowledge bases

i am using com.google.cloud.dialogflow.v2beta1.Document to create document through java rpc,we have a setContent() method which is used creating document with raw content, when i try to create document i am getting below exception.
Caused by: com.google.api.gax.rpc.InvalidArgumentException: Operation
with name
"projects/agent-fa5be/operations/ks-add_document-NDQ0NDQ3MjI5MDA3NTIxMzgyNA"
failed with status = GrpcStatusCode{transportCode=INVALID_ARGUMENT}
and message = CSV documents must have exactly two columns. The
provided document has 1 columns.
when i check dialogflow.v2beta1 Documentation there clearly mentioned content is deprecated use raw_content instead of content. but there is no supported method for raw_content in com.google.cloud.dialogflow.v2beta1.Document
I was experimenting a similar issue. I tried different libraries and techniques until I found something that worked. In my case I've to parse each row as follows:
let input = ['Question1', 'Answer1\n'];
let input2 = ['Question2', 'Answer2\n'];
let base64data = input.toString('base64') + input2.toString('base64');
const request = {
parent: 'projects/PROJECT_ID/knowledgeBases/KNOWLEDGEBASE_ID',
document: {
knowledgeTypes: ['FAQ'],
displayName: 'Echele',
content: base64data,
source: 'rawContent',
mimeType: 'text/csv',
},
};
This allowed my to submit the document, hope it works for you too!
Regards
Please find working solution
String documentName="test.csv";
try {
byte[] bytedata = filedata.toString().getBytes();
ByteString bytestring = ByteString.copyFrom(bytedata);
byte[] bytedata1 = "text/csv".getBytes();
ByteString mimestring = ByteString.copyFrom(bytedata1);
DocumentsSettings docuemtnSettings = DocumentsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();
DocumentsClient documentsClient = DocumentsClient.create(docuemtnSettings);
Document document = Document.newBuilder().setDisplayName(documentName).setContentBytes(bytestring)
.setMimeTypeBytes(mimestring).addKnowledgeTypes(KnowledgeType.FAQ).build();
CreateDocumentRequest createDocumentRequest = CreateDocumentRequest.newBuilder().setDocument(document)
.setParent(knowledgeBaseName).build();
OperationFuture<Document, KnowledgeOperationMetadata> response = documentsClient
.createDocumentAsync(createDocumentRequest);
Document createdDocument = response.get();
System.out.format(" - docuemnt created ID: %s\n", createdDocument.getName());

Roslyn: How to update a document

I'm new to Visual Studio extensions. I'm developing a Menu Command extension to add a using directive to my class. So far, I could successfully create a new Document object containing the changes:
var syntaxTree = await sourceDocument.GetSyntaxTreeAsync();
var unitRoot = syntaxTree.GetCompilationUnitRoot();
var qualifiedName = SyntaxFactory.ParseName("MyApp.Utilities"); // using MayApp.Utilities
var usingDirective = SyntaxFactory.UsingDirective(qualifiedName);
unitRoot = unitRoot.AddUsings(usingDirective);
var newDocument = sourceDocument.WithSyntaxRoot(unitRoot);
The problem is it doesn't reflect the changes back to the source code (or workspace if it's correct term).
Any idea and suggestion is appreciated.

C++/CX - GetFileAsync throws breakpoint error

I am trying to open a xml file from my Assets folder, but unfortunately I am only able to open my xml file by using a FileOpenPicker which is not the most ideal situation when I have to constantly fetch my xml file, without disturbing the user of course.
FileOpenPicker^ openPicker = ref new FileOpenPicker();
openPicker->ViewMode = PickerViewMode::List;
openPicker->SuggestedStartLocation = PickerLocationId::Desktop;
openPicker->FileTypeFilter->Append(".xml");
task<StorageFile^>(
openPicker->PickSingleFileAsync()).then([this](StorageFile^ file) {
if (nullptr != file) {
task<Streams::IRandomAccessStream^>(file->OpenAsync(FileAccessMode::Read)).then([this](Streams::IRandomAccessStream^ stream)
{
IInputStream^ deInputStream = stream->GetInputStreamAt(0);
DataReader^ reader = ref new DataReader(deInputStream);
reader->LoadAsync(stream->Size);
String^ strXml = reader->ReadString(stream->Size);
});
}
});
I am now trying to reconstruct this code into a code which loads up my xml file without letting the user choose. I tried the following approach:
String^ xmlFile = "Assets\MyXmlFile.xml";
StorageFolder^ InstallationFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;
task<StorageFile^>(
InstallationFolder->GetFileAsync(xmlFile)).then([this](StorageFile^ file) {
if (nullptr != file) {
task<Streams::IRandomAccessStream^>(file->OpenAsync(FileAccessMode::Read)).then([this](Streams::IRandomAccessStream^ stream)
{
IInputStream^ deInputStream = stream->GetInputStreamAt(0);
DataReader^ reader = ref new DataReader(deInputStream);
reader->LoadAsync(stream->Size);
String^ strXml = reader->ReadString(stream->Size);
stream->FlushAsync();
});
}
});
I think I get errors at the GetFileAsync which I am not able to solve and I am asking you, the community to try and help me.
Your code worked for me with one modification: the xmlFile string contains a backslash that needs to be escaped:
String^ xmlFile = "Assets\\MyXmlFile.xml";
Note also that if you just right-clicked "Assets" in your project and chose "Add new item", that item may have ended up in your root project folder (which is the default). If you want it to be deployed to the Assets subfolder it will need to physically live there on disk in the assets subdirectory, not just be in the Assets filter. (Unlike in C#, the C++ project "folders" are actually filters and do not reflect physical directory location.)

creating thumbnail from a pdf in coldfusion cfscript

I'm trying to create a thumbnail from a pdf in coldfusion, but no thumbnail gets created and no exception is thrown.
(coldfusion 9)
my code:
var source = "A:\testfolder\test.pdf";
var destination = "A:\testfolder\";
createImageFromPdf(source, destination);
createImageFromPdf function:
public void function createImageFromPdf(required string source, required string destination,
numeric pages = 1, string resolution = "low",
numeric scale = 100, boolean overwrite = true){
var pdf = new pdf();
pdf.setSource(arguments.source);
pdf.thumbnail(pages = arguments.pages, resolution = arguments.resolution,
scale = arguments.scale, overwrite = arguments.overwrite);
}
After running this code, i don't receive errors or exceptions, but no image was generated in A:\testfolder\
I'm probably missing something obvious here, but can't find it.
Also no log records are created in application or exception log, pdf is not protected and I'm sure that the folder is writable.
All help is appreciated.
Thanks.
You just forgot to pass along the destination
pdf.thumbnail(destination=arguments.destination
, pages = arguments.pages
, resolution = arguments.resolution
, scale = arguments.scale
, overwrite = arguments.overwrite);

OpenOffice SDK: convert document to PDF

I'm trying to build an application to convert documents (word, powerpoint) to PDF using the OpenOffice SDK.
I'm using C++ and all I want the application to do is take an input document filename and and output PDF filename, and do the conversion.
Are there any samples or easy way to get started? Most of the documentation I see is using Java.
You can get an example source code here:
http://forum.openoffice.org/en/forum/viewtopic.php?t=3801
I do this with C#, I share with you hoping it helps:
// Connect to a running office and get the service manager
unoidl.com.sun.star.uno.XComponentContext m_xContext = uno.util.Bootstrap.bootstrap();
var mxMSFactory = (XMultiServiceFactory)m_xContext.getServiceManager();
XComponentLoader desktop = (XComponentLoader)mxMSFactory.createInstance("com.sun.star.frame.Desktop");
XComponentLoader xComponentLoader = (unoidl.com.sun.star.frame.XComponentLoader)desktop;
PropertyValue[] properties = new PropertyValue[1];
properties[0] = new PropertyValue();
properties[0].Name = "Hidden";
properties[0].Value = new uno.Any(true);
XComponent xComponent = xComponentLoader.loadComponentFromURL("file:///YOUR .ODT PATH", "_blank", 0, properties);
XTextDocument xDocument = (XTextDocument)xComponent;
XStorable xStorable = (XStorable)xDocument;
PropertyValue[] storeProps = new PropertyValue[3];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = new uno.Any("writer_pdf_Export");
storeProps[1] = new PropertyValue();
storeProps[1].Name = "Overwrite";
storeProps[1].Value = new uno.Any(true);
storeProps[2] = new PropertyValue();
storeProps[2].Name = "SelectPdfVersion";
storeProps[2].Value = new uno.Any(1);
xStorable.storeToURL("file:///YOUR PDF PATH", storeProps);
xDocument.dispose();
The right way to start is reading the Developer's Guide.
Good stuff in our business ain't easy.