Printing to a Printer, setting the printer to write a file

The Amyuni PDF Converter is our Printer Driver that enables you to convert any documents to PDF format. If you have any questions about installing and using the Amyuni PDF Converter please post them here.
Post Reply
John_h_bergman
Posts: 13
Joined: Tue Apr 13 2004

Printing to a Printer, setting the printer to write a file

Post by John_h_bergman »

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
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

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.
John_h_bergman
Posts: 13
Joined: Tue Apr 13 2004

I mean to save the output as something other than..

Post by John_h_bergman »

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).
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

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.
John_h_bergman
Posts: 13
Joined: Tue Apr 13 2004

How to convert to PCL

Post by John_h_bergman »

:D 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.
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Yes, you are right, when checking your question with our developers, i have been told that you can generate pcl files by simply printing your files to any pcl driver available in Windows. This doesn't need any specific too.

Have a nice day ! :)
John_h_bergman
Posts: 13
Joined: Tue Apr 13 2004

That is why...

Post by John_h_bergman »

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....
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

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

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.
John_h_bergman
Posts: 13
Joined: Tue Apr 13 2004

Printing to File

Post by John_h_bergman »

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...
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

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.
John_h_bergman
Posts: 13
Joined: Tue Apr 13 2004

Print to File

Post by John_h_bergman »

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.
Jose
Amyuni Team
Posts: 553
Joined: Tue Oct 01 2002
Contact:

Post by Jose »

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
John_h_bergman
Posts: 13
Joined: Tue Apr 13 2004

Thank you, but...

Post by John_h_bergman »

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.
Post Reply