PrintDocument object information to PDF?

Hi,

I was looking at a way to convert Printdocument inormation into PDF or another file format, and was suggested to take a look into Aspose, since we are already considering other products of Aspose.

I stumbled upon this thread :

https://forum.aspose.com/t/119436

which gave me the impression that in the current version it is possible to convert, but I didn't find any further info yet, so I am not sure whether it is possible or not with you software.

My situation:

currently I am sending information in my project to printdocument classes and send it to the printer and to the printpreview pane, which works perfectly by calling the Print method of the Printdocument object.

But I also need a way to send the information as attachment in an email to the customer. We want this attachment to be a PDF file, since that seems the most clean way to send our information.
So we would like to have the information that the PrintDocument objects generate, exported to a PDF file we save on a shared networkdrive.

So my question is :

Is it possible, in VB.net code, to send the content of a Printdocument object to one of the objects you provide (in a DLL?) and generate a PDF-file with it?

Something in the lines of

AsposeObject.SavetoPDF(PrintdocObject, destinationfolder)

Hi Steven,


Thanks for your inquiry. Please look into a similar thread. Hopefully it will serve the purpose.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Steven,


Thanks for contacting support and sorry for the delayed response.

In order to accomplish your requirement, please try using the following code snippet. Before executing this code, please ensure that printer is configured with your system.

[C#]

private StreamReader
streamToPrint;<o:p></o:p>

private System.Drawing.Font printFont;

public void CreatePDFNET_11409(string issueID, string fileName)

{

streamToPrint = new StreamReader(string.Format("{0}{1}.txt", InputPath, issueID));

try

{

printFont = new System.Drawing.Font("Arial", 10);

PrintDocument pd = new PrintDocument();

pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);

Aspose.Pdf.Generator.PrintController pc = new Aspose.Pdf.Generator.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;

}

sorry for the late feedback, I was on holiday and jus got back.

For my purposes it was not needed to add a streamreader, since I already got the printdocument implemented and its print methd as well.

this worked for me :

FilePath = fileName
DocumentToSave = “Childobject of the printdocument class with print method implemented”
Dim PrintController As New Aspose.Pdf.Generator.PrintController
PrintController.FileName = FilePath
DocumentToSave.PrintController = PrintController
DocumentToSave.Print()

But I have a few additional questions:

Normally you can add a series of attributes to a pdf file, such as preventing the pdf from being copied, printed, added certificates, etc.

Is there a way to add options like this to the pdf file?

The main purpose is that the recipient of the file cannot copy or edit the content of the PDF.

edit: double post

Hi Steven,

Thanks for your feedback. You can set privileges on your PDF document using Aspose.PDF. Please check following documentation link for details/code snippet. Hopefully it will serve the purpose.

Please feel free to contact us for any further assistance.

Best Regards,

Problem with the provided links is that the code for existing pdf does no work, because the system still has the file in use after creating it using the Aspose PrintController class (see code earlier in this thread)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

The constructor of the FileSecurity is the one that throws an exception.<o:p></o:p>

I tried to set the printcontroller and the document to nothing, but that
didn’t do anything.<o:p></o:p>

<o:p> </o:p>

FilePath = fileName
DocumentToSave = “Childobject of the printdocument class with print method implemented”
Dim PrintController As New Aspose.Pdf.Generator.PrintController
PrintController.FileName = FilePath
DocumentToSave.PrintController = PrintController
DocumentToSave.Print()


Dim privilege As Aspose.Pdf.Facades.DocumentPrivilege = Aspose.Pdf.Facades.DocumentPrivilege.ForbidAll

privilege.ChangeAllowLevel = 1

privilege.AllowPrint = False

privilege.AllowCopy = True

Dim FileSecurity As New Aspose.Pdf.Facades.PdfFileSecurity(FilePath, FilePath)

FileSecurity.SetPrivilege(privilege)

Rereading this piece of code, I realise that I probably have to set the priviliges before calling the PrintDocument.Print method, but how do I assign the priviliges then?

I do not have the Aspose.Pdf.Generator.Pdf object on
which I can set the security poperty.<o:p></o:p>

<o:p> </o:p>

Right now I have 2 objects to work with: <o:p></o:p>

The printdocument object<o:p></o:p>

The Aspose printcontroller object

Hi Steven,


Sorry for the delayed response. We are looking into the issue and will get back to you soon.

Best Regards,