We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF documents Merging into 1 and printing

Hi,

I have two questions:

1- We have a requirement where we need to download existing word/pdf documents from URLs on the netowrk and then convert them into 1 PDF output. I can download bytes array from the Urls into individual Memory stream though!

Can i please have an example which could demostrate above?

2- The PDF output from 1 needs to be printed on user's local printer. If the above application is running on a server here in UK and the final PDF output needs to be printed by a remote client(user of the application and triggering through a web interface button) in different part of world, how can the ouput be printed on user's local printer? the only information server contains regarding the user is its printer address(e.g. "HP 1050 " or \\HongKong\Priner) in a business object.

Please reply ASAP

Thanks

Hi Umer,

Thanks for your inquiry.

Umer Javed:

1- We have a requirement where we need to download existing word/pdf documents from URLs on the netowrk and then convert them into 1 PDF output. I can download bytes array from the Urls into individual Memory stream though!

Can i please have an example which could demostrate above?

Please check following code snippet and documenation link for concatenating PDF documents. hopefully it will help you to accomplish your requirements.

FileStream fileStream1 = new FileStream(myDir + "TableDom.pdf", FileMode.Open, FileAccess.Read);

byte[] tmpBytes1 = new byte[fileStream1.Length];

fileStream1.Read(tmpBytes1, 0, Convert.ToInt32(fileStream1.Length));

MemoryStream memoryStream1 = new MemoryStream(tmpBytes1);

FileStream fileStream2 = new FileStream(myDir + "example2.pdf", FileMode.Open, FileAccess.Read);

byte[] tmpBytes2 = new byte[fileStream2.Length];

fileStream2.Read(tmpBytes2, 0, Convert.ToInt32(fileStream2.Length));

MemoryStream memoryStream2 = new MemoryStream(tmpBytes2);

Document pdfDocument1 = new Document(memoryStream1);

Document pdfDocument2 = new Document(memoryStream2);

pdfDocument1.Pages.Add(pdfDocument2.Pages);

pdfDocument1.Save(memoryStreamout);

Umer Javed:

2- The PDF output from 1 needs to be printed on user's local printer. If the above application is running on a server here in UK and the final PDF output needs to be printed by a remote client(user of the application and triggering through a web interface button) in different part of world, how can the ouput be printed on user's local printer? the only information server contains regarding the user is its printer address(e.g. "HP 1050 " or \\HongKong\Priner) in a business object.

Please check documentation link how to set printer name while printing using PdfViewer. Hopefully it will serve the purpose. Moreover, please note if you you are trying to print from a web application to client printer then I'm afraid its not supported, please consider this post.

Please feel free to contact us for any further assistance.


Best Regards,

Dear Tilal,

Thanks for your answer!

Regarding 2, perhaps I have not expressed the requirement much clearly, basically we the web application is a Microsoft Dynamics CRM product which we are solution provider for, this is simply an ASP.net we site running on the network and clients are all part of the network who login on this web product, so think of it like intranet! And this website is running on server and therefore when client clicks print from aspx page, the consoles app written by us is supposed to print some documents for client on its printer!

And client printer information is stored in one of the business entity on this Asp.net application. Can print be sent on the printer for this client(e.g. if located in Hong Kong but still part of UK network)?

My 3rd and last question , how can we set the print job Owner name?(to the actual user who pressed print button on web page) for Aspose.pdf and Aspose.word during print as it is really important to set this from Console app running on server!

Thanks

Umer

Also regarding the example you sent in answer to first question, we are instead retrieving documents from URL and these are of different types, if you see the example below

Byte[] bytes = client.DownloadData("[http://SERVER/Alldocuments/Essays.docx](http://server/Alldocuments/Essays.docx)");

Byte[] bytes1 = client.DownloadData("http:// SERVER/Alldocuments/CV.pdf");

MemoryStream memoryStream = new MemoryStream(bytes);

MemoryStream memoryStream1 = new MemoryStream(bytes1);

Aspose.word.Document pdfDocument = new Aspose.word.Aspose.word.Document(memoryStream);

Aspose.pdf.Document pdfDocument1 = new Aspose.pdf.Document(memoryStream1);

How do I know merge retrieved bytes stream for word with bytes stream for pdf without saving anywhere?

Regards
Umer

Hi Umer,

Umer Javed:

Dear Tilal,

Thanks for your answer!

Regarding 2, perhaps I have not expressed the requirement much clearly, basically we the web application is a Microsoft Dynamics CRM product which we are solution provider for, this is simply an ASP.net we site running on the network and clients are all part of the network who login on this web product, so think of it like intranet! And this website is running on server and therefore when client clicks print from aspx page, the consoles app written by us is supposed to print some documents for client on its printer!

And client printer information is stored in one of the business entity on this Asp.net application. Can print be sent on the printer for this client(e.g. if located in Hong Kong but still part of UK network)?

Thanks for sharing more details. You can set printer name to shared network printer as following. Hopefully it will serve the purpose. Please let us know if you get any issue, we will be more than happy to extend our support.

'set printer name

ps.PrinterName = '\\systemname\printername'

Umer Javed:

My 3rd and last question , how can we set the print job Owner name?(to the actual user who pressed print button on web page) for Aspose.pdf and Aspose.word during print as it is really important to set this from Console app running on server!


We are sorry for the inconvenience. After initial investigation, I've found that the requested feature is not available in Aspose.Pdf. I've logged an investigation ticket as PDFNEWNET-35866 for the enhancement. We will keep you updated about the issue progress via this forum thread.

Moreover, I'm moving the query to Aspose.Total forum. There my colleague from Aspose.Words will answer your query soon.

Best Regards,
Hi Umer,
Thanks for your inquiry.

Umer Javed:

Also regarding the example you sent in answer to first question, we are instead retrieving documents from URL and these are of different types, if you see the example below

Byte[] bytes = client.DownloadData("http://server/Alldocuments/Essays.docx");

Byte[] bytes1 = client.DownloadData("http:// SERVER/Alldocuments/CV.pdf");

MemoryStream memoryStream = new MemoryStream(bytes);

MemoryStream memoryStream1 = new MemoryStream(bytes1);

Aspose.word.Document pdfDocument = new Aspose.word.Aspose.word.Document(memoryStream);

Aspose.pdf.Document pdfDocument1 = new Aspose.pdf.Document(memoryStream1);

How do I know merge retrieved bytes stream for word with bytes stream for pdf without saving anywhere?


I'm afraid, Aspose.Pdf doesn't support any method to know file type from incoming stream. However, you can capture InvalidPdfFileFormatException exception to know whether stream contains PDF file type or not.

Moreover, please note Aspose.Pdf supports only PDF file format for merging. So you need to convert Word document to PDF using Aspose.Words API, before merging it with PDF documents.

Please let us know if we can be of any further assistance.

Regards,

Thanks Tial,

We have written logic to find out if it is word document!We have written logic to find out if it is word document, but how do i actually convert the word document to PDF without saving on disc? once bytes have been retrieved from URL.

I would appreciate for urgent reply as i need to go back to my customer with answers!

Thanks

Umer

Umer Javed:
My 3rd and last question , how can we set the print job Owner name?(to the actual user who pressed print button on web page) for Aspose.pdf and Aspose.word during print as it is really important to set this from Console app running on server!
Hi Umer,

As shared by Tilal, the above stated requirement is not supported. However you can specify the Print Job Owner name using PrinterJobName property of PdfViewer class. Since this property accepts string values, so you can pass username who initiated the print job.

[C#]

//create PdfViewer object<o:p></o:p>

PdfViewer viewer = new PdfViewer();

// bind source PDF file

viewer.BindPdf("c:/pdftest/InLIneHTMLText.pdf");

// specify the name of Print job

viewer.PrinterJobName = "Current User";

// print the document

viewer.PrintDocument();

Umer Javed:
We have written logic to find out if it is word document!We have written logic to find out if it is word document, but how do i actually convert the word document to PDF without saving on disc? once bytes have been retrieved from URL.
Hi Umer,

Once the Word document is retrieved, please use Aspose.Words for .NET to convert the file to PDF format and save the output in Stream object. Then pass the same Stream object to Aspose.Pdf for .NET so that final concatenated/merged PDF file is generated.

Hi Umer,

Thanks for your feedback. Please check following code snippet for converting DOC/DOCX to PDF using Aspose.Words and saving to stream. Please also check documentation link for the details.

FileStream fileStream1 = new FileStream(myDir + “Sample.docx”, FileMode.Open, FileAccess.Read);

byte[] tmpBytes1 = new byte[fileStream1.Length];

fileStream1.Read(tmpBytes1, 0, Convert.ToInt32(fileStream1.Length));

MemoryStream memoryStream1 = new MemoryStream(tmpBytes1);

MemoryStream memoryStreamout = new MemoryStream();

Aspose.Words.Document doc = new Aspose.Words.Document(memoryStream1);

doc.Save(memoryStreamout,Aspose.Words.SaveFormat.Pdf);

Please feel free to contact us for any further assistance.

Best Regards,

Thanks Tilal and Nayyer,

I was making mistake of using same memory strream to save document as PDF whereas your example helped me to create a new memorystreamoutput object and assign resulting PDF.

Appreciate your help.

Umer

Nayyer,

Thanks but i am already using printjobname and it is not helpful. The reason being my customer's users actually login to shared printer(i.e. they swipe their card) and print their jobs according to the ownership!

Is there any chance you could include this feature in next release of Aspose.PDF? And when is that going to be?

As from above you can imagine, It is really important for my customer to have such feature in Aspose.I have already advised them to Buy Aspose.word and Aspose.PDF.

Regards

Umer

Umer Javed:
Thanks but i am already using printjobname and it is not helpful. The reason being my customer’s users actually login to shared printer(i.e. they swipe their card) and print their jobs according to the ownership!

Is there any chance you could include this feature in next release of Aspose.PDF? And when is that going to be?

As from above you can imagine, It is really important for my customer to have such feature in Aspose.I have already advised them to Buy Aspose.word and Aspose.PDF.

Hi Umer,

Thanks for sharing the details.

Since we recently have logged this requirement as PDFNEWNET-35866 in our issue tracking system, the development team requires little time to investigate and figure out if we can support this feature or not. Currently we cannot commit any particular time-frame, but as soon as we have some further updates, we would be more than happy to update you with the status of correction. Please be patient and spare us little time.

Hi Umer,

Thanks for your inquiry.
Umer:
My 3rd and last question , how can we set the print job Owner name?(to the actual user who pressed print button on web page) for Aspose.pdf and Aspose.word during print as it is really important to set this from Console app running on server!
How would you normally specify your credentials when doing printing like this without using Aspose.Words? I think you might be able to use code like on the following page to set credentials while printing:
http://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share

Best regards,

Dear Awais

We have now bult the console application and tested on our dev environment and it looks ok. But when we copy nd run the executable on customer's test environment , we get the attached error.

Customer has already installed Aspose.PDF and Aspose.Words on their test environment. But interestingly the Dlls(Aspose.PDF and Aspose.words) don't appear in GAC either in both our and customer environment.

Please help to resolve the issue ASAP.

Thanks

Umer

Hi Umer,

When installing Aspose.Pdf
for .NET, it’s not installed/copied to GAC of Windows 7. However in order to
run an executable/application based on Aspose.Pdf for .NET, you need to place
Aspose.Pdf.dll in the same directory where .exe is placed.


In case you still face the same issue, please feel free to contact.

The issues you have found earlier (filed as PDFNEWNET-35866) have been fixed in Aspose.Pdf for .NET 9.2.0.

The blog post for this release is created over this link


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Umer,

In reference to PDFNEWNET-33866, we have investigated it and would like to suggest you that you can use property named PrinterJobName for setting and getting print job owner and following links can be useful to get user credentials.

Moreover, a sample code snippet for the purpose would be something like that and you can implement GetCurrentUserCredentials() according to your application type using information stated in above links.

public void PrintDocument()
{
    PdfViewer viewer = new PdfViewer();
    // bind source PDF file
    viewer.BindPdf(@"c:\test.pdf");
    // specify the name of Print job
    viewer.PrinterJobName = GetCurrentUserCredentials();
}

private string GetCurrentUserCredentials()
{
    // The implementation depends of type of running application (ASP.NET, Windows forms, etc.)
    string userCredentials = string.Empty;
    return userCredentials;
}

Please feel free to contact us for any further assistance.
Best Regards,