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);
}
Related
I have a Gmail attachment PDF with multiple scanned pages. When I use Google Apps Script to save the blob from the attachment to a Drive file, open the PDF manually from Google Drive, then select Open With Google Docs, all of the text from the PDF is displayed as a Google Doc. However, when I save the blob as a Google Doc with OCR, only the text from the image on the first page is saved to a Doc, accessed either manually or by code.
The code to get the blob and process it is:
function getAttachments(desiredLabel, processedLabel, emailQuery){
// Find emails
var threads = GmailApp.search(emailQuery);
if(threads.length > 0){
// Iterate through the emails
for(var i in threads){
var mesgs = threads[i].getMessages();
for(var j in mesgs){
var processingMesg = mesgs[j];
var attachments = processingMesg.getAttachments();
var processedAttachments = 0;
// Iterate through attachments
for(var k in attachments){
var attachment = attachments[k];
var attachmentName = attachment.getName();
var attachmentType = attachment.getContentType();
// Process PDFs
if (attachmentType.includes('pdf')) {
processedAttachments += 1;
var pdfBlob = attachment.copyBlob();
var filename = attachmentName + " " + processedAttachments;
processPDF(pdfBlob, filename);
}
}
}
}
}
}
function processPDF(pdfBlob, filename){
// Saves the blob as a PDF.
// All pages are displayed if I click on it from Google Drive after running this script.
let pdfFile = DriveApp.createFile(pdfBlob);
pdfFile.setName(filename);
// Saves the blob as an OCRed Doc.
let resources = {
title: filename,
mimeType: "application/pdf"
};
let options = {
ocr: true,
ocrLanguage: "en"
};
let file = Drive.Files.insert(resources, pdfBlob, options);
let fileID = file.getId();
// Open the file to get the text.
// Only the text of the image on the first page is available in the Doc.
let doc = DocumentApp.openById(fileID);
let docText = doc.getBody().getText();
}
If I try to use Google Docs to read the PDF without OCR directly, I get Exception: Invalid argument, for example:
DocumentApp.openById(pdfFile.getId());
How do I get the text from all of the pages of the PDF?
DocumentApp.openById is a method that can only be used for Google Docs documents
pdfFile can only be "opened" with the DriveApp - DriveApp.getFileById(pdfFile.getId());
Opening a file with DriveApp allows you to use the following methods on the file
When it comes to OCR conversion, your code works for me correctly to convert all pages of a PDF document to Google Docs, so you error source is likely come from the attachment itself / the way you retrieve the blob
Mind that OCR conversion is not good at preserving formatting, so a two page PDF might be collapsed into a one-page Docs - depneding on the formatting of the PDF
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.
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?
Can I load a local HTML file (with images and ...) into a WebView?
Just setting the Source parameter does not do the trick.
You can load it from a file as long as the file is part of the app package, e.g.:
WebView2.Source = new Uri("ms-appx-web:///assets/text.html");
From WebView.Navigate
WebView can load content from the application’s package using
ms-appx-web://, from the network using http/https, or from a string
using NavigateToString. It cannot load content from the application’s
data storage. To access the intranet, the corresponding capability
must be turned on in the application manifest.
For a 'random' file, I suppose you could prompt user via file picker to select the file then read it into a string and use NavigateToString, but the user experience there may be a bit odd depending on what you're trying to accomplish.
I was working at this problem for a long time and I found a way to do that:
At first you should save it in InstalledLocation folder. If you haven't option to create a new .html file you can just use file.CopyAsync(htmlFolder, fname + ".html");
Look into my example:
StorageFolder htmlFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFolderAsync(#"HtmlFiles", CreationCollisionOption.GenerateUniqueName);
IStorageFile file = await htmlFolder .CreateFileAsync(fname + ".html", CreationCollisionOption.GenerateUniqueName);
and than you can easily open your .html file:
var fop = new FileOpenPicker();
fop.FileTypeFilter.Add(".html");
var file = await fop.PickSingleFileAsync();
if (file != null)
{
string myPath = file.Path.Substring(file.Path.IndexOf("HtmlFiles"));
myWebview.Navigate(new Uri("ms-appx-web:///" + myPath));
}
Remember just only from InstalledLocation you can open it with ms-appx-web:///