How to print Cyrillic PDF in C#? Text missing - c#

I use iTextSharp to create document in my programs. All text in documents is Russian, I use Tahoma fonts:
private static void PrepareFonts()
{
_baseTahoma = BaseFont.CreateFont("c:/windows/fonts/tahoma.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
_tahomaBold = new Font(_baseTahoma, 10, Font.BOLD);
_tahoma = new Font(_baseTahoma, 10, Font.NORMAL);
_tahoma16Bold = new Font(_baseTahoma, 18, Font.BOLD);
_tahomaSmall = new Font(_baseTahoma, 8, Font.NORMAL);
}
When document is created, I print it on button click that way:
RegistryKey adobe = Registry.LocalMachine.OpenSubKey(#"Software\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe");
if (adobe != null)
{
string path = adobe.GetValue("").ToString();
GenerateDocuments();
Process proc = new Process();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";
string pdfFileName = _invoice.FullName;
proc.StartInfo.FileName = path;
proc.StartInfo.Arguments = #"/p /h " + pdfFileName;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
if (!proc.WaitForExit(5000))
proc.Kill();
}
proc.EnableRaisingEvents = true;
proc.Close();
}
But on the paper there are only lines from tables without any characters. There's no text or numbers.
In requirements specification is written that user must print documents on button click and I have to do it that way. Manual opening document and "Print as image" are not possible.
Can anyone give suggestion, how can I print Cyrillic document?

#Drac When I open the file, I see Cyrillic characters; when I print the file (normal printing), I see Cyrillic characters. If some printer isn't able to print the document correctly, you need to look at your printer driver (maybe you're using the wrong one) or your printer.

Related

c# generate thumbnails from raw images

I have an Asp.net Web forms application,when upload raw image file with format
{ "cr2", "raw", "dng", "nef", "raf", "orf", "srf", "sr2", "arw", "k25", "kdc", "dcr","mos",
"pnx", "crw", "mrw", "pef" , "mef" , "rw2","a7","a7r"}
How can i generate thumbnails from raw image?
You can use dcraw.exe application run on your .net application.you can download it in the link.
First save raw image in local disk and use the code:
string dcrawPath = "dcraw.exe";
ProcessStartInfo startInfo = new ProcessStartInfo();
string inputImagePath= "input Raw Image Path/";
string outputImagePath = "output Raw Image Path/";
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.FileName = dcrawPath;
string commandArg1 = string.Format("\"{0}\"", outputImagePath);
string commandArg2 = string.Format("\"{0}\"", inputImagePath);
startInfo.Arguments = "-u ";
startInfo.Arguments += commandArg1;
startInfo.Arguments += " -e ";
startInfo.Arguments += commandArg2;
startInfo.Arguments += " -T";
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
string stdout = exeProcess.StandardOutput.ReadToEnd();
string stderr = exeProcess.StandardError.ReadToEnd();
Console.WriteLine("Exit code : {0}", exeProcess.ExitCode);
}
Put raw image in inputImagePath variable
You can find image in outputImagePath variable
Try GDPicture.NET component. It supports different RAW formats and easy for use, but is not free. To generate thumbnail use CreateThumbnail or CreateThumbnailHQ method of GdPictureImaging class:
using (var imaging = new GdPictureImaging())
{
int pictureId = imaging.CreateGdPictureImageFromFile(filepath);
if (pictureId == 0)
{
MessageBox.Show("Error: " + imaging.GetStat().ToString());
return;
}
int thumbnailImgId = imaging.CreateThumbnail(pictureId, 20, 20);
imaging.SaveAsPNG(thumbnailImgId, "thumbnail.png");
imaging.ReleaseGdPictureImage(thumbnailImgId);
imaging.ReleaseGdPictureImage(pictureId);
}

Is it possible to retain Hyperlinks from PDF

string ghostScriptPath = #"C:\Program Files (x86)\gs\gs9.09\bin\gswin32.exe";
string inputFileName = Server.MapPath("pdf/myprofile.pdf");
string outputFileName = #"D:\";
string ars = "-dNOPAUSE -sDEVICE=jpeg -r300 -o" + output + "-%d.jpg " + input;
Process proc = new Process();
proc.StartInfo.FileName = ghostScriptPath;
proc.StartInfo.Arguments = ars;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
I'm using asp.net application with c# language. I'm using the code above to convert the PDF to images using Ghost Script. Is it possible to retain Hyperlinks from PDF?
You can use PDFParser to read the PDF as text (into a string) and then parse the string yourself for "http".
Just for completeness:
// create an instance of the pdfparser class
PDFParser pdfParser = new PDFParser();
// extract the text
String result = pdfParser.ExtractText(pdfFile);
if(result.ToLower().Contains("http"))
{
//split the string on known factors like a "\n" and "/" for ending the url.
}

printing pdf without spawning adobe reader?

Presently I'm using the following lines of c# code to automatically print a pdf file to a mobile printer:
string defFile = (Path.Combine(System.Windows.Forms.Application.StartupPath, tkt_no + "_DEF.pdf"));
string rwPrinter = "";
if (GlobalVars.useDefaultPrinter == false)
{
foreach (string strPrinter in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
if (strPrinter.StartsWith("ZDesigner"))
{
rwPrinter = strPrinter;
break;
}
}
}
if (jobdo.Equals("print"))
{
Process process = new Process();
process.StartInfo.FileName = defFile;
if (rwPrinter.Length > 0)
{
process.StartInfo.Verb = "printto";
process.StartInfo.Arguments = "\"" + rwPrinter + "\"";
}
else
{
process.StartInfo.Verb = "print";
}
process.Start();
process.WaitForInputIdle();
Thread.Sleep(10000);
process.Kill();
These above lines are good if the application is on a workstation desktop, but the problem I am having is when it actually prints the pdf file from a Citrix App shortcut, it spawns Adobe Reader (the default for pdf) and doesn't close when print job is done.
So my question is, is there any way to print a pdf document without opening Adobe or similar? Perhaps in the iTextSharp library which I'm using in the same application to populate fields?

Print File without print dialog box

I need your help to print my locally saved file without using print dialog box , i tried out many cases but failed to do so. one case is like;
var pr = new PrintDocument();
pr.PrintController = new System.Drawing.Printing.StandardPrintController();
pr.PrinterSettings = new PrinterSettings();
pr.PrinterSettings.PrintFileName = "E:\\File.docx";
pr.PrinterSettings.PrinterName = fileName.ToString();
pr.Print();
pr.Dispose();
This will start Microsoft Word and print the test.rtf while suppressing the Print dialog box. However, the path must be fully specified.
var settings = new PrinterSettings();
var startInfo = new ProcessStartInfo();
startInfo.FileName = #"C:\Program Files\Microsoft Office\Office\WINWORD.EXE";
startInfo.Arguments = #"test.rtf /q /n /mFilePrintDefault /mFileExit";
var p = Process.Start(startInfo);

process always prints document by default printer

I have a problem with selecting printer to print my document.
My code is :
var filename = #"C:\Users\I\Desktop\test.doc";
PrintDialog pd = new PrintDialog();
pd.PrinterSettings =new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
Process objP = new Process();
objP.StartInfo.FileName = filename;
objP.StartInfo.WindowStyle =
ProcessWindowStyle.Hidden; //Hide the window.
objP.StartInfo.Verb ="print";
objP.StartInfo.Arguments ="/p /h \"" + filename + "\" \"" + pd.PrinterSettings.PrinterName + "\"";
objP.StartInfo.CreateNoWindow = false;
//true;//!! Don't create a Window.
objP.Start();
//!! Start the process !!//
objP.CloseMainWindow();
}
and whatever I choose, process always will use default printer, no matter what value of pd.PrinterSettings.PrinterName is.
What's wrong with my code?
You probably want to use "PrintTo" instead of "print" for the verb. You already set objP.FileName to the filename so there's no need to get complicated in the arguments. Pass the printer name alone there.
var filename = #"C:\Users\I\Desktop\test.doc";
PrintDialog pd = new PrintDialog();
pd.PrinterSettings =new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
Process objP = new Process();
objP.StartInfo.FileName = filename;
objP.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //Hide the window.
objP.StartInfo.Verb ="PrintTo";
objP.StartInfo.Arguments = pd.PrinterSettings.PrinterName;
objP.StartInfo.CreateNoWindow = false;
//true;//!! Don't create a Window.
objP.Start();
//!! Start the process !!//
objP.CloseMainWindow();
}
Try changing pd.PrinterSettings =new PrinterSettings(); to read something like this:
pd.PrinterSettings =new System.Drawing.Printing.PrinterSettings;
By default when you create an instance of printer settings it returns the default printer name just an fyi... you can then try something like this
//sudu code
foreach(string strPrinter in PrinterSettings.InstalledPrinters)
{
// or unless you know the name of the printer then skip this and assign it to the code above
}

Categories

Resources