Free Support Forum - aspose.com

Convert text file to pdf

I am attempting to convert a text file to PDF format. The PDF is created but all that is in it is the disclaimer "Evaluation Only. Created with Aspose.Pdf. Copyright 2002-2011 Aspose Pty Ltd."

I am using a slight variation of your hello world PDF example like so:

Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(sDocInPath)
Dim contents As String = objStreamReader.ReadToEnd()
Dim pdf1 As New Pdf()
Dim sec1 As New Aspose.Pdf.Section(pdf1)
sec1.Paragraphs.Add(New Text(contents))
pdf1.Save(sDocOutPath & sDocNewID & ".pdf")

The contents string does have the text from the file in it, but for some reason it never makes it into the PDF.

Thanks

Tom

Hello Tom,

Thanks for using our products.

Please visit the following link for information on Converting text file to PDF. In case you still face any problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

OK - I have a little more information now, and this may be what is happining with the PDF combine issue as well. If I make a small web app and read and write files locally everything is OK.

BUT, when I have a Web app that is writing to another server I get nothing inside the file. Now I have been able to check the contents in the paragraph object itself - t2.Segments(0).Content - displays the contents of the document and the document is saved to the drive but is empty except for the disclaimer when written.

Tom

It appears it will only save properly to the C: drive. I have tried UNC server path (get empty file written) and a mapped path where it complains about "Could not find a part of the path".

Is this a limitation of the demo version?

One final note - the Words module is saving MS Word Docs as PDF correctly (using the same standard UNC path) in the same function.

Hello Tom,

Thanks for sharing the details.

The Trial version offers the complete set of features as present in Licensed version, except it adds an evaluation watermark in the resultant PDF. Regarding the issue "Could not find a part of the path", I think its occurring because you might not be providing the correct path for network location. Please try using the following code line to save the resultant PDF on network location.

[C#]

pdf1.Save(\\\\127.0.0.1\\Resources\\AsposeTest.Pdf);

In order to test the scenario, I have shared a folder over my system and have accessed it using 127.0.0.1 (local loopback IP). You may specify the name/IP of your desired server/system. Please try using it and in case you face any further query, please feel free to contact. We apologize for your inconvenience.

Yes that is the format I was using. Today it seems to work.

I am still having problems with the PDF kit getting the "Exception occurred during the processing stream: 1". I am really stumped on it, I can take code that works in a little local project and copy it into the application we want to use it in and I get this error. No idea how to debug or what could be causing to fail.

Have a good weekend

Hello Tom,

Can you please share what exact issue you are facing while using Aspose.Pdf.Kit ? More along, please share the details regarding the requirement that you are trying to accomplish.

We are sorry for this inconvenience.

It appears my response did not make it, so to recapitulate.

I have a collection of various types of files Doc, XLS, TXT and PDF (among others) which the user can select from and join together.
The code is a simple case statement that checks for non-PDF files and their type and runs the proper Aspose conversion. The new (or existing) PDF is then stuffed into a stream object wich is collected in an array, similar to your example.

The code to do the joining was copied to a small stub program where it ran without error. The paths to the files was hard coded, both input and output.
But the identical code raised the following error in the main application "Exception occurred during the processing stream: 1" the Inner exception was : "The directory name is invalid." and the Message was: "Exception occurred in method: GetTempFileName() ". A 0byte file was created at the output path

Thanks

It looks like the impersonated user does not have the rights to the temp directory specified for my user "%USERPROFILE%\AppData\Local\Temp" and is attempting to write at that location. It is not using "%SystemRoot%\TEMP" and so when I give the ASP user rights to my temp folder everything works fine. Is thee a means to specify a specific temp directory?

Thanks

Hi Tom,

I represent Aspose.Pdf.Kit and I would like to share with you that this issue is caused due to the privileges set on the temporary folder. Moreover, you may set the temporary folder using Settings.TempPath property.

I hope this helps. If you still find any problem, please do let us know.
Regards,