Free Support Forum - aspose.com

System.Drawing.Printing legacy code which needs to be converted using Aspose API

Hi,

I have the legacy code which are using "System.Drawing.Printing.PrintDocument" class currently.

We are utilizing this API to produce *.PS document. May i know whether there is a clue to utilize Aspose PDF dll to produce *.PDF document directly ?

For your information, this application is .NET 1.1 based.

Regards,

hadi teo

Hi,

I have searched through your forums and discovered the following thread:

http://www.aspose.com/community/forums/permalink/204563/204563/showthread.aspx#204563

It seems that the feature has been implemented properly. May i request for the code example to print the PrintDocument into *.PDF with Aspose ?

Regards,

hadi teo

Hi,

I have attached the sample project which modifies the sample code defined from MSDN http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.print.aspx

In order to run this example, you should have "Adobe PDF" printer which included during the installation of Adobe Acrobat.

You can also change the pd.PrinterSettings.PrinterName to your physical printer name so that it can print directly to the physical printer.

Regards,

hadi teo

Hi,

May i request a reply to the following thread ?

Regards,

hadi teo

Hi Hadi,


Please accept my apology for the delayed response. I’m afraid your requirement of converting PostScript document(*.PS) to Pdf is not supported by Aspose.Pdf at the moment. We have already logged a similar feature request in our issue tracking system as PDFNEWNET-20110. I’ve linked your request to the issue id and will keep you updated regarding issue status, via this forum thread.

Please correct me if there is any difference in my understanding and your requirement.

Best Regards,

Hi,

Thanks for your reply. I think there is a misunderstanding here.

My main objective is to use System.Drawing.Printing logic to produce *.PDF document.

I am not sure how can i achieve this objective using Aspose. But there is a thread that raised by a customer which mimics the same scenario.

http://www.aspose.com/community/forums/permalink/204563/204563/showthread.aspx#204563

Currently this application uses System.Drawing.Printing to produce *.PS and subsequently use Acrobat API to convert it into *.PDF.

What i want is to produce directly *.PDF from System.Drawing.Printing.

Hope i clarify my intention clearly.

Regards,

hadi teo

Hi Hadi,


Thanks for your patience and cooperation. In referenced thread, we have implemented PrintController Class to print text file. Please refer code snippet as following. Hopefully it would help you to meet your requirements.

private StreamReader streamToPrint;
private Font printFont;

public void CreatePDFNET_11409(string issueID, string fileName)

{
streamToPrint = new StreamReader(string.Format("{0}{1}.txt", InputPath, issueID));
try
{
printFont = new Font(“Arial”, 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
PrintController pc = new Aspose.Pdf.PrintController();
pc.FileName = fileName;
pd.PrintController = pc;
pd.Print();

}

finally

{
streamToPrint.Close();
}

}

// The PrintPage event is raised for each page to be printed.

private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{

float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;

// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /printFont.GetHeight(ev.Graphics);

// Print each line of the file.
while (count < linesPerPage &&
((line = streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count *printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,leftMargin, yPos, new StringFormat());
count++;

}

// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;

}

Note: Please check printer should be installed on your PC.

Best Regards,