If you use the 64bit Eclipse IDE, most old Office formats (DOC, XLS, PPT) won't even open. So it really shouldn't be surprising that the SWT framework can't handle them either. You can force these files to open using deprecated API, but even then you can't store XLS files for some reason.
Standalone test:
final File file = // insert file here
Display display = new Display();
Shell shell = new Shell(display);
shell.setText(file.getName());
shell.setLayout(new GridLayout());
shell.setSize(800, 600);
OleFrame frame = new OleFrame(shell, SWT.NONE);
frame.setLayoutData(new GridData(GridData.FILL_BOTH));
final OleClientSite clientSite = new OleClientSite(frame, SWT.NONE, "Excel.Sheet", file);
Button button = new Button(shell, SWT.NONE);
button.setText("Save");
button.addListener(SWT.Selection, e -> clientSite.save(file, true));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
There is no exception, no log, no nothing. It just doesn't save. OleClientSite.isDirty() is not set to false either.
How do I save XLS files using the OLE framework of SWT?
Related
I have the following code:
public async Task<ActionResult<FileResult>> GetCSV()
{
var stringCsv = await _statistics.GetUserCSV();
using (var stream = new MemoryStream())
using (var sw = new StreamWriter(stream, Encoding.UTF8))
{
sw.Write(stringCsv);
sw.Flush();
return File(stream.ToArray(), "text/csv", "thefile.csv");
}
}
If I inspect stringCsv while debugging it looks good, but If I look at the resulting CSV in Excel I get this.
The missing letters are the Swedish letters ÅÄÖ.
What am I doing wrong?
The issue is not coming from your code. It is from the file itself. Try the following:
On a Windows computer, open the CSV file using Notepad.
Click "File > Save As".
In the dialog window that appears - select "ANSI" from the "Encoding" field. Then click "Save".
That's all! Open this new CSV file using Excel - your non-English characters should be displayed properly.
Let me know if it worked.
I am using Aspose.Words for .NET to replace some merge fields in my document and then save the file as a PDF, however, my formatting is getting messed up (even for non-merge fields) by the conversion to PDF (refer to the images). The code is quite simple so I don't see what I'm missing.
The word document, pre-processing:
The generated pdf:
As you can see some of the fields are indented a bit more instead of being nicely aligned.
My code for generating the PDF and replacing the merge fields is:
public async Task<Stream> GenerateContractAsync(string requestRegistrationId)
{
var requestRegistration = await _requestRegistrationRepository
.FindRequestRegistration(requestRegistrationId)
.Include(rr => rr.Request.QualityType)
.Include(rr => rr.User)
.SingleOrDefaultAsync();
var file = await _fileService
.LoadFileAsync("Concept contract.docx");
var user = requestRegistration.User;
var document = new Aspose.Words.Document(file);
document.MailMerge.Execute(
new[]
{
"EmployeeName", "EmployeeDateOfBirth", "EmployeePlaceOfBirth", "EmployeeSSN", "EmployeeCity",
"EmployeeAddress", "ContractStartDate", "EmployeeFunction", "HourlyWage", "WageDeductionApplied"
},
new object[]
{
user.FullName, $"{user.Birthday:dd-MM-yyyy}", "Oss", user.Bsn, user.City,
$"{user.PostalCode}, {user.City}", $"{requestRegistration.Request.StartDate:dd-MM-yyyy}",
requestRegistration.Request.QualityType.Name, $"{requestRegistration.Request.HourlyRate:C}",
user.PayrollTaxDiscountEnabled ? "Ja" : "Nee"
}
);
var mergedDocumentStream = new MemoryStream();
document.Save(mergedDocumentStream, SaveFormat.Pdf);
#if DEBUG
mergedDocumentStream.Seek(0, SeekOrigin.Begin);
await _fileService.SaveFileToDiskAsync($"{user.Id}-{DateTimeOffset.Now:g}.pdf", "", mergedDocumentStream);
#endif
mergedDocumentStream.Seek(0, SeekOrigin.Begin);
return mergedDocumentStream;
}
Any help would be greatly appreciated.
The problem occurs because of missing fonts. Please refer to the following article for details.
How Aspose.Words Uses True Type Fonts
In your case, you need to install 'Verdana', 'Arial' and 'Cambria' fonts on the machine where you are executing this Aspose.Words' code. Simply copying these font files from Windows machine to other MAC machine should work.
I work with Aspose as Developer Evangelist.
I'm creating an add-in in Revit 2017. The addin will export drawing sheets to PDF files. So, whenever I try to export the sheet a dialog box appears to choose the location to save. I tried to turn off the Prompting programmatically by adding a key to the Windows registry (as described in Adobe documentation page 15-16).
Now, the prompting got turned off and now I'm facing an issue. The issue is the Adobe Printer got stuck while creating the pdf file. See the below image: The PDF creating progress bar seems frozen, I waited for more than 10 mins and it didn't create the pdf file.
Can anybody provide any fix?
Appreciate any suggestion.
Edit
here's the code that I've written for this purpose. I hope this may help to identify the problem.
public static bool ExportSheetToPDF(Document doc, string path)
{
using (Transaction tx = new Transaction(doc)
{
tx.Start("Exportint to PDF");
PrintManager pm = doc.PrintManager;
pm.SelectNewPrintDriver("Adobe PDF");
pm.Apply();
pm.PrintRange = PrintRange.Current;
pm.Apply();
pm.CombinedFile = true;
pm.Apply();
pm.PrintToFile = true;
pm.Apply();
pm.PrintToFileName = path + #"\PDF\" + "abc.pdf";
pm.Apply();
SuppressAdobeDialogAndSaveFilePath(path + #"\PDF\" + "abc.pdf");
pm.SubmitPrint();
pm.Apply();
tx.Commit();
}
return true;
}
// Add Registry Key to suppress the dialog box
public static void SuppressAdobeDialogAndSaveFilePath(string value)
{
var valueName = #"C:\Program Files\Autodesk\Revit 2017\Revit.exe";
var reg = currentUser.OpenSubKey(key, true);
var tempReg = reg.OpenSubKey(valueName);
if (tempReg == null)
{
reg = reg.CreateSubKey(valueName);
}
reg.SetValue(valueName, value);
reg.Close();
}
I have explained how you can achieve this by overriding the registry key for Revit.exe process that Adobe uses to generate the next print.
http://archi-lab.net/printing-pdfs-from-revit-why-is-it-so-hard/
Please remember that you still have to print via Revit PrintManager, but then you can set the registry keys before every print to control where the files get saved.
I have a .aspx page and it has a button on click of which a radwindow opens .The radwindow has a new page with content including a button onclick of which a pdf is created and downloaded.I want the pdf to open in a new tab or window , so i made changes to my code -changed attachment to inline
Hashtable deviceInfo = new Hashtable();
deviceInfo.Add("FontEmbedding", "Subset");
deviceInfo.Add("DocumentTitle", String.Format("TrackitManager - {0}", reportToExport.DocumentName));
deviceInfo.Add("DocumentAuthor", "Trackit Systems Pty Ltd");
ReportProcessor reportProcessor = new ReportProcessor();
RenderingResult result = reportProcessor.RenderReport("PDF", reportToExport, deviceInfo);
if (String.IsNullOrEmpty(filename))
filename = result.DocumentName;
context.Response.Clear();
context.Response.ContentType = result.MimeType;
context.Response.Cache.SetCacheability(HttpCacheability.Private);
context.Response.Expires = -1;
context.Response.Buffer = true;
//context.Response.TransmitFile("~/Handlers/EnrollmentPDF.ashx");
context.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename=\"{0}.pdf\"", filename));
context.Response.BinaryWrite(result.DocumentBytes);
context.Response.End();
But this is opening the pdf inside the radwindow itself.I want it to open in a new window but outside the radwindow.
you have to give the correct header and mimeType to tell the browser to download the file
for that you just have to add this line to replace :
context.Response.ContentType = result.MimeType;
by this line :
Response.ContentType = "application/octectstream";
How to read the pdf files in windows 8 app .In my windows 8 application how to open the pdf files .
In manifest file i wrote the below code.
<Extensions>
<Extension Category="windows.fileTypeAssociation">
<FileTypeAssociation Name="pdf">
<SupportedFileTypes>
<FileType>.pdf</FileType>
</SupportedFileTypes>
</FileTypeAssociation>
</Extension>
</Extensions>
and code behind.
string imageFile = #"Images\DX730_EN.pdf";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
if (file != null)
{
// Set the option to show the picker
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
// Launch the retrieved file
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
if (success)
{
// File launched
}
else
{
// File launch failed
}
}
else
{
// Could not find file
}
i could not able to open the pdf file.please tell me where is error?
you can use the LaunchFileAsync method of the Windows.System.Launcher class.
Take a look at this:
http://msdn.microsoft.com/en-us/library/windows/apps/hh701465.aspx
Windows 8 comes with windows Reader to read pdf files .
This link might help you
http://www.howto-connect.com/how-to-view-pdf-file-in-windows-8-what-is-windows-reader/
If that doesn't help, this might
http://social.technet.microsoft.com/Forums/en-US/W8ITProPreRel/thread/b19fc6d8-531f-4cf2-8d6d-f1dc9e93a93d/
The solution is, you can open pdf files on Windows.ApplicationModel.Package.Current.InstalledLocation...
So, put the pdf on local folder and open from it.
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile file= await localFolder.GetFileAsync("myFile.pdf");
if (file != null)
{
// Set the option to show the picker
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
// Launch the retrieved file
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
}