OpenOffice SDK: convert document to PDF - c++

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.

Related

Download image using Dynamics 365 Web API

I am trying to download the image from Dataverse using Dynamics Web API.
I am able to succeed in that using {{webapiurl}}sample_imageattributedemos(d66ecb6c-4fd1-ec11-a7b5-6045bda5603f)/entityimage/$value
But when I try to download the full/actual size image - I am getting the file with the reduced size - {{webapiurl}}sample_imageattributedemos(d66ecb6c-4fd1-ec11-a7b5-6045bda5603f)/entityimage/$value?fullsize=true.
I tried to download the image using the sample code where additionally I have added CanStoreFullImage = true attribute.
Please find below code snippet for the reference:
CreateAttributeRequest createEntityImageRequest = new CreateAttributeRequest
{
EntityName = _customEntityName.ToLower(),
Attribute = new ImageAttributeMetadata
{
SchemaName = "EntityImage", //The name is always EntityImage
//Required level must be AttributeRequiredLevel.None
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
DisplayName = new Microsoft.Xrm.Sdk.Label("Image", 1033),
Description = new Microsoft.Xrm.Sdk.Label("An image to show with this demonstration.", 1033),
CanStoreFullImage = true,
IsPrimaryImage = false,
}
};
How can I achieve this - to download the full size image using Web API?
the correct syntax is size=full, not fullsize=true
to build such requests you can use my tool Dataverse REST Builder, you can find the operations to deal with Image fields under the Manage Image Data request type

Saving Aspose.Slides.Presentation prevents file from being opened

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.

Using NAudio/Nlayer to mix two mp3 files

In reference to this question: NoDriver calling acmFormatSuggest on Azure
My hosting server does not allow me to install anything or register dlls. I am using Naudio to mix to mp3 files and it gave me the error NoDriver calling acmFormatSuggest.
I downloaded and installed Nlayer in my application and modified the code to look like this:
var builderBackground = new Mp3FileReader.FrameDecompressorBuilder(wf => new Mp3FrameDecompressor(wf));
var builderMessage = new Mp3FileReader.FrameDecompressorBuilder(wf => new Mp3FrameDecompressor(wf));
Mp3FileReader mpbacground = new Mp3FileReader(ThumbAudioMP3, builderBackground); Mp3FileReader mpMessage = new Mp3FileReader(stream, builderMessage);
background = WaveFormatConversionStream.CreatePcmStream(mpbacground);
message = WaveFormatConversionStream.CreatePcmStream(mpMessage);
var mixer = new WaveMixerStream32(); var messageOffsetted = new WaveOffsetStream(message, TimeSpan.FromSeconds(0), TimeSpan.Zero, TimeSpan.FromSeconds(seconds));
I get the same NoDriver calling acmFormatSuggest error in the line WaveFormatConversionStream.CreatePcmStream(...
Can someone tell me how I should be doing this? Any documentation on Nlayer?
You don't need the WaveFormatConversionStream.CreatePcmStream lines. The Mp3FileReader classes will already emit PCM.

Deleting a file from sharepoint using web service

I am trying to delete a file from a sharepoint document library.
My application is in C#, which uses the web services of sharepoint.
Would like to know how this can be done.
Thanks in advance.
Delete a Document in SharePoint using Web Services
1.Add Web Reference to http://[your site]/_vti_bin/Lists.asmx
2.You need Document ID, Library Name, and Url to the document to be deleted
var spWebServiceLists = "http://[your site]/_vti_bin/Lists.asmx";
var listService = new Lists
{
Credentials = CredentialCache.DefaultCredentials,
Url = spWebServiceLists
};
string id = 10;
string library = #"Shared Documents";
string url = #"http://[your site]/Shared Documents/Test.docx";
string xml = "<Method ID='1' Cmd='Delete'>" +
"<Field Name='ID'>" + id + "</Field>" +
"<Field Name='FileRef'>" + HttpUtility.UrlDecode(url) + "</Field>" +
"</Method>";
/*Get Name attribute values (GUIDs) for list and view. */
System.Xml.XmlNode ndListView = listService.GetListAndView(library, "");
string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;
/*Create an XmlDocument object and construct a Batch element and its
attributes. Note that an empty ViewName parameter causes the method to use the default view. */
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
batchElement.SetAttribute("OnError", "Continue");
batchElement.SetAttribute("ListVersion", "1");
batchElement.SetAttribute("ViewName", strViewID);
/*Specify methods for the batch post using CAML. To update or delete,
specify the ID of the item, and to update or add, specify
the value to place in the specified column.*/
batchElement.InnerXml = xml;
XmlNode item;
item = listService.UpdateListItems(library, batchElement);
I just tested this code and works well.
For more information please see following links
Lists.UpdateListItems Method
How to: Update List Items
If you work with SharePoint 2010, you can use CSOM to access SharePoint web services. This link could be helpful to execute crud operations. If you work with SharePoint 2013 there is also CSOM API, it has similar funcitonality as in 2010.

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);