Printing to a Printer, setting the printer to write a file
-
- Posts: 13
- Joined: Tue Apr 13 2004
Printing to a Printer, setting the printer to write a file
I'd like to take the PDF and print it to a file. I understand how to select the printer, but I am not quite clear as to what point (or how to) actually set the printer's file name - I do not want the printer prompting for the file.
I am using C#/.Net. Any pointers, or sample code would be great!
Thanks,
John
I am using C#/.Net. Any pointers, or sample code would be great!
Thanks,
John
Hello,
Please find here a C# sample:
private void btnPrintTextObject_Click(object sender, System.EventArgs e)
{
CDIntfEx.CDIntfEx PDF = new CDIntfEx.CDIntfExClass() ;
PDF.DriverInit ( PDFprinter);
PDF.DefaultDirectory = "c:\\temp";
//Complete path of resulting PDF document
PDF.DefaultFileName = "c:\\temp\\fromCsharp.pdf";
//Set printer as default
PDF.SetDefaultPrinter();
PDF.FileNameOptionsEx = (int)(sNoPrompt + sUseFileName);
PDF.EnablePrinter (strLicenseTo, strActivationCode);
//Print Something
printDocument1.Print();
PDF.RestoreDefaultPrinter();
PDF.FileNameOptions = 0;
}
Hope this helps.
Please find here a C# sample:
private void btnPrintTextObject_Click(object sender, System.EventArgs e)
{
CDIntfEx.CDIntfEx PDF = new CDIntfEx.CDIntfExClass() ;
PDF.DriverInit ( PDFprinter);
PDF.DefaultDirectory = "c:\\temp";
//Complete path of resulting PDF document
PDF.DefaultFileName = "c:\\temp\\fromCsharp.pdf";
//Set printer as default
PDF.SetDefaultPrinter();
PDF.FileNameOptionsEx = (int)(sNoPrompt + sUseFileName);
PDF.EnablePrinter (strLicenseTo, strActivationCode);
//Print Something
printDocument1.Print();
PDF.RestoreDefaultPrinter();
PDF.FileNameOptions = 0;
}
Hope this helps.
-
- Posts: 13
- Joined: Tue Apr 13 2004
I mean to save the output as something other than..
What I meant was I need to save the contents of the PDF as something other than a format that the PDf product supports (PCL for example).
Hello,
Currently we do not have a tool to convert pdf files to pcl, but we have some modules to convert pdf files to RTF, HTML, Excel, and Jpeg.
For more information please feel free to contact support@amyuni.com
Thanks.
Currently we do not have a tool to convert pdf files to pcl, but we have some modules to convert pdf files to RTF, HTML, Excel, and Jpeg.
For more information please feel free to contact support@amyuni.com
Thanks.
-
- Posts: 13
- Joined: Tue Apr 13 2004
How to convert to PCL
That is why I want to print to a printer and save it as a file. If I print to a PCL printer, but save it as a file, I have just converted the PDF to a PCL.
-
- Posts: 13
- Joined: Tue Apr 13 2004
That is why...
That is why I am looking for a .net example of how to actually save the output of a printer to a file... I cannot seem to get it to work, even using PINVOKE to get to the Win32 api....
Unfortunately, I don't have a sample C# code that prints to file. Maybe some C# developers browsing this forum would be able to post the code you need.
However, if you are our customer and if you have the PDF Creator product, you can use the PrintToFile function of the PDF Creator.
Please find below a C# code that uses this function
Hope this helps.
However, if you are our customer and if you have the PDF Creator product, you can use the PrintToFile function of the PDF Creator.
Please find below a C# code that uses this function
Code: Select all
private void btnPrint_Click(object sender, System.EventArgs
e)
{
Int32 EndPage;
string m_printername;
m_printername = "Generic PostScript Printer";
ACPDFCREACTIVEX.PDFCreactiveXClass pdf1 = new
ACPDFCREACTIVEX.PDFCreactiveXClass();
//Set License info
pdf1.SetLicenseKey(sLicenseTo, sActivationCode);
//Open file to print
pdf1.Open (@"c:\temp\export.pdf","");
//Get totalpages
EndPage = pdf1.PageCount;
pdf1.PrintToFileName = @"c:\temp\invoice.ps";
pdf1.StartPrint (m_printername, 1);
//Print in a loop
for (int StartPage = 1; StartPage < EndPage;
StartPage++)
{
pdf1.PrintPage (StartPage);
}
pdf1.EndPrint();
}
Hope this helps.
-
- Posts: 13
- Joined: Tue Apr 13 2004
Printing to File
What printer driver does this code use to print? If I use print-to-file, doesn't it just generate a PDF, by whatever name?
The whole point of printing via a regular printer driver is to ultimately end up in either PCL or Postscript...
The whole point of printing via a regular printer driver is to ultimately end up in either PCL or Postscript...
Hello John,
This code doesn't use a printer driver, it uses one of our applications, the PDF Creator.
The PDF Creator is a PDF viewer / editor, it enables you to view, edit and print pdf files and to create pdf files from scratch without any user interaction.
One function of the PDF Creator is called PrintToFile, it enables developers to print a pdf file to pcl or ps.
If you have the PDF Creator you can use it to generate ps files.
If not, you can use any windows driver or any PCL printer from windows but I don't have specific names, you need to search windows site to download a printer driver.
Unfortunately, I dont have a C# sample that saves the output to a file, I can provide you with a C# sample that prints to specific printer if this helps.
Have a nice day.
This code doesn't use a printer driver, it uses one of our applications, the PDF Creator.
The PDF Creator is a PDF viewer / editor, it enables you to view, edit and print pdf files and to create pdf files from scratch without any user interaction.
One function of the PDF Creator is called PrintToFile, it enables developers to print a pdf file to pcl or ps.
If you have the PDF Creator you can use it to generate ps files.
If not, you can use any windows driver or any PCL printer from windows but I don't have specific names, you need to search windows site to download a printer driver.
Unfortunately, I dont have a C# sample that saves the output to a file, I can provide you with a C# sample that prints to specific printer if this helps.
Have a nice day.
-
- Posts: 13
- Joined: Tue Apr 13 2004
Print to File
Unfortunately, we have the PDFConverter product.
Can you supply two snippets of code?
1. How do I print to a specific printer
2. In either C# or C++, how do I configure the printer to print to a file?
I will use Com-Interop to make this work.
Can you supply two snippets of code?
1. How do I print to a specific printer
2. In either C# or C++, how do I configure the printer to print to a file?
I will use Com-Interop to make this work.
Hello,
The code snippet below will enable the PrintToFile checkbox in the printer's dialog box (no the PDF Converter but windows). Therefore, allowing you to print to a ps or pcl printer.
Hope this helps?
// Declare the PrintDocument object.
private System.Drawing.Printing.PrintDocument docToPrint =
new System.Drawing.Printing.PrintDocument();
// This method will set properties on the PrintDialog object and
// then display the dialog.
private void Button1_Click(System.Object sender,
System.EventArgs e)
{
// Allow the user to choose the page range he or she would
// like to print.
PrintDialog1.AllowSomePages = true;
// Show the help button.
PrintDialog1.ShowHelp = true;
//Selects the PrintToFile checkbox
printDialog1.AllowPrintToFile = true;
printDialog1.PrintToFile = true;
// Set the Document property to the PrintDocument for
// which the PrintPage Event has been handled. To display the
// dialog, either this property or the PrinterSettings property
// must be set
PrintDialog1.Document = docToPrint;
DialogResult result = PrintDialog1.ShowDialog();
// If the result is OK then print the document.
if (result==DialogResult.OK)
{
docToPrint.Print();
}
}
// The PrintDialog will print the document
// by handling the document's PrintPage event.
private void document_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
// Insert code to render the page here.
// This code will be called when the control is drawn.
// The following code will render a simple
// message on the printed document.
string text = "In document_PrintPage method.";
System.Drawing.Font printFont = new System.Drawing.Font
("Arial", 35, System.Drawing.FontStyle.Regular);
// Draw the content.
e.Graphics.DrawString(text, printFont,
System.Drawing.Brushes.Black, 10, 10);
}
Thanks
The code snippet below will enable the PrintToFile checkbox in the printer's dialog box (no the PDF Converter but windows). Therefore, allowing you to print to a ps or pcl printer.
Hope this helps?
// Declare the PrintDocument object.
private System.Drawing.Printing.PrintDocument docToPrint =
new System.Drawing.Printing.PrintDocument();
// This method will set properties on the PrintDialog object and
// then display the dialog.
private void Button1_Click(System.Object sender,
System.EventArgs e)
{
// Allow the user to choose the page range he or she would
// like to print.
PrintDialog1.AllowSomePages = true;
// Show the help button.
PrintDialog1.ShowHelp = true;
//Selects the PrintToFile checkbox
printDialog1.AllowPrintToFile = true;
printDialog1.PrintToFile = true;
// Set the Document property to the PrintDocument for
// which the PrintPage Event has been handled. To display the
// dialog, either this property or the PrinterSettings property
// must be set
PrintDialog1.Document = docToPrint;
DialogResult result = PrintDialog1.ShowDialog();
// If the result is OK then print the document.
if (result==DialogResult.OK)
{
docToPrint.Print();
}
}
// The PrintDialog will print the document
// by handling the document's PrintPage event.
private void document_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
// Insert code to render the page here.
// This code will be called when the control is drawn.
// The following code will render a simple
// message on the printed document.
string text = "In document_PrintPage method.";
System.Drawing.Font printFont = new System.Drawing.Font
("Arial", 35, System.Drawing.FontStyle.Regular);
// Draw the content.
e.Graphics.DrawString(text, printFont,
System.Drawing.Brushes.Black, 10, 10);
}
Thanks
-
- Posts: 13
- Joined: Tue Apr 13 2004
Thank you, but...
I cannot use the print dialog because I am running on a server (ie as a server-based application). The person requesting the operation is sitting somewhere on the LAN (or internet) away from the actual computer doing the work.