PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jan 20, 2022 8:43 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Jan 11, 2022 4:15 pm 
Offline

Joined: Tue Jul 17, 2018 5:47 pm
Posts: 3
Hello,

I get the following message when I attempt to open a PDF that I created with the attached code I got from here.

"Adobe Acrobat could not open "name of file", because it is either not a supported file type or has been damaged..."

I am unable to open from Windows Explorer directly or through my application. The file does open using the Process.Start method as in the code, but the program is just to create for later use so the Start.Process was left in temporarily.
The PDF is shown as 0 KB even though there is a page and name added using this code. Do I need to add more?

Here is the code:
Note: sWorkerFolder is a path to the file and the file name is entered by the user in a text field.

Dim newPDF As New Pdf.PdfDocument
newPDF.Info.Title = txtPDFFileName.Text.Trim
Dim page As Pdf.PdfPage = newPDF.AddPage
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)

Dim pen As XPen = New XPen(XColor.FromArgb(255, 0, 0))

Dim font As XFont = New XFont("Verdana", 20, XFontStyle.Bold)
' Draw the text
gfx.DrawString("Hello, " & Environment.UserName & "!", font, XBrushes.Black, New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.Center)
' Save the document...
Dim sFileName As String = sWorkFolder & txtPDFFileName.Text.Trim & " WC.pdf"
newPDF.Save(sFileName)
Process.Start(sFileName)


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 11, 2022 9:52 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 699
Location: CCAA
awdigrigoli wrote:
The PDF is shown as 0 KB even though there is a page and name added using this code. Do I need to add more?
A PDF created by PDFsharp containing the text "Hello" should be larger than 1 kB, so seeing 0 kB looks definitely wrong.

To me it is a bit unclear what you do and when the error occurs.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 12, 2022 1:20 pm 
Offline

Joined: Tue Jul 17, 2018 5:47 pm
Posts: 3
The code works to generate a PDF and if I leave the Process.Start(filename) code in place the file opens and looks good.
However, after I close the file and then go back to view it, the error message I provided is displayed when Acrobat opens. The PDF I created does not reappear.
Is the Save() method from PdfDocument not working properly? I don't think that is the issue, but I not sure why the only bit of code I found online to use PDFSharp to create a PDF is not working.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 12, 2022 7:32 pm 
Offline

Joined: Tue Jul 17, 2018 5:47 pm
Posts: 3
I found that I am able to create the file and access it as long as I leave it in the location where it is created. The File.Copy command, not related to PdfSharp is where the issue resides. The copy is somehow corrupting the file.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 13, 2022 8:57 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 699
Location: CCAA
awdigrigoli wrote:
The File.Copy command, not related to PdfSharp is where the issue resides. The copy is somehow corrupting the file.
And this command was not shown in this thread.
Support cases like that made us create the Issue Submission Template.

Thanks for the feedback, issue resolved.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group