Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PDFSharp compatibility?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
1090 Views, 5 Replies

PDFSharp compatibility?

Anonymous
Not applicable

I'm trying to use PDF document variables in Revit, so I downloaded and installed the PDFSharp NuGet in Visual Studio.  It all installed easily and I don't get any errors in my code; Revit launches with no errors...  But when I launch the button event handler to create a PDF, I get an error.  I've attached it.  I'm wondering if there's some kind of compatibility with Revit and the PDFSharp package.  I honestly have no idea why it's happening, so if anyone has any insight, it would be tremendously helpful! 

0 Likes

PDFSharp compatibility?

I'm trying to use PDF document variables in Revit, so I downloaded and installed the PDFSharp NuGet in Visual Studio.  It all installed easily and I don't get any errors in my code; Revit launches with no errors...  But when I launch the button event handler to create a PDF, I get an error.  I've attached it.  I'm wondering if there's some kind of compatibility with Revit and the PDFSharp package.  I honestly have no idea why it's happening, so if anyone has any insight, it would be tremendously helpful! 

Tags (2)
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

I also am getting this error now:

0 Likes

I also am getting this error now:

Message 3 of 6
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Hi,

 

I am unsure of what you are trying to achieve...

If you want to print drawing to pdf you need to use a installed PDF-printer such as Adobe PDF or CutePDF and then print.
Here is an example:
PrintManager pm = _doc.GetPrintManager();
pm.SelectNewPrinter("Adobe PDF");

 

//Find your printsettings by looking here

 

var printSettingsList = _doc.GetPrintSettingIds().Select(x=>_doc.GetElement(x));

 

//Set appropriate printsetting

 

pm.CurrentPrintSetting = [the printsetting you want]

 

pm.Apply();

 

//find all your views and then iterate over them and submit print for each

 

pm.SubmitPrint([view])

 

 

0 Likes

Hi,

 

I am unsure of what you are trying to achieve...

If you want to print drawing to pdf you need to use a installed PDF-printer such as Adobe PDF or CutePDF and then print.
Here is an example:
PrintManager pm = _doc.GetPrintManager();
pm.SelectNewPrinter("Adobe PDF");

 

//Find your printsettings by looking here

 

var printSettingsList = _doc.GetPrintSettingIds().Select(x=>_doc.GetElement(x));

 

//Set appropriate printsetting

 

pm.CurrentPrintSetting = [the printsetting you want]

 

pm.Apply();

 

//find all your views and then iterate over them and submit print for each

 

pm.SubmitPrint([view])

 

 

Message 4 of 6
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

@Anonymous What I'm trying to accomplish is a little complicated (by my standards) so I'll break it down in to the steps I'm taking:

1. I need to grab all family instances from my drawing;

2. From these family instances, some of them have URLs attached - I then collect those;

3. After I have a List<string> of my URL's, I visit those URL's that have what's known as cut sheets on them;

4. I pull the cut sheet images and store them in to an Image[ ];

5. I then place those images from the array in to a Rectangle, and place the rect on to a PdfPage - these pages are also an array;

6. I then create a PdfDocument by adding the PdfPage[ ] to it;

7. Then users have the option of saving and/or printing the PdfDocument;

 

I'm using the PdfSharp namespace to accomplish this, and there are no problems with the code.  Everything would work fine, except for the fact that every time I click the ribbon button that would execute this code, I get the exception that I've attached.  It tells me it cannot load the file or assembly.  I've looked and verified that the .dll's are installed and in all the correct file paths; I've ensure that the Assembly.cs files are also there.  I have absolutely no idea how to remedy this issue. 

 

If you have any idea what to do, it would be a huge help!!  And let me know if you need more information.

0 Likes

@Anonymous What I'm trying to accomplish is a little complicated (by my standards) so I'll break it down in to the steps I'm taking:

1. I need to grab all family instances from my drawing;

2. From these family instances, some of them have URLs attached - I then collect those;

3. After I have a List<string> of my URL's, I visit those URL's that have what's known as cut sheets on them;

4. I pull the cut sheet images and store them in to an Image[ ];

5. I then place those images from the array in to a Rectangle, and place the rect on to a PdfPage - these pages are also an array;

6. I then create a PdfDocument by adding the PdfPage[ ] to it;

7. Then users have the option of saving and/or printing the PdfDocument;

 

I'm using the PdfSharp namespace to accomplish this, and there are no problems with the code.  Everything would work fine, except for the fact that every time I click the ribbon button that would execute this code, I get the exception that I've attached.  It tells me it cannot load the file or assembly.  I've looked and verified that the .dll's are installed and in all the correct file paths; I've ensure that the Assembly.cs files are also there.  I have absolutely no idea how to remedy this issue. 

 

If you have any idea what to do, it would be a huge help!!  And let me know if you need more information.

Message 5 of 6
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Accepted solution

I see.
When I get that error its usually because another addin is using another version of the 3rd party lib that Im using, and it so happens to be that Revit loaded that addin and 3rd party lib first. Everything is loaded into the same appdomain so it takes the first version it finds, sort of. Thats how the default assembly resolver works, in my experience at least.

Make sure no other addin is loaded except yours, also, we've been having problems with Autodesk loading 3rd party libs, and they are harder to turn off, so you have/had to match their version. I think that has been fixed now though.

 

Another option is to hook up to the AppDomain.AssemblyResolve event and make sure you provide your own version of the lib at runtime.

 

But I've would start with removing all other running addons.

 

/Erik

I see.
When I get that error its usually because another addin is using another version of the 3rd party lib that Im using, and it so happens to be that Revit loaded that addin and 3rd party lib first. Everything is loaded into the same appdomain so it takes the first version it finds, sort of. Thats how the default assembly resolver works, in my experience at least.

Make sure no other addin is loaded except yours, also, we've been having problems with Autodesk loading 3rd party libs, and they are harder to turn off, so you have/had to match their version. I think that has been fixed now though.

 

Another option is to hook up to the AppDomain.AssemblyResolve event and make sure you provide your own version of the lib at runtime.

 

But I've would start with removing all other running addons.

 

/Erik

Message 6 of 6
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

What we're working on is an Add-In for Revit, and PDFSharp is an add-in for us.  I've tried removing and reinstalling it several times, but I get the same result every single time.  I think your solution will be really helpful though!  I appreciate it.  I need to dig around some files today and resolve this issue.

 

Thanks, again, Erik!

 

Cheers!

 

~Geoff

0 Likes

What we're working on is an Add-In for Revit, and PDFSharp is an add-in for us.  I've tried removing and reinstalling it several times, but I get the same result every single time.  I think your solution will be really helpful though!  I appreciate it.  I need to dig around some files today and resolve this issue.

 

Thanks, again, Erik!

 

Cheers!

 

~Geoff

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report