PDFCreator and Printing from Revit


#1

I would be grateful for any assistance that can be provided.

I am very new to this site and relatively new to programming with c#.

Can you please point me to a good example of how to utilise PDFcreator to print from Revit.

I know that I have to create a reference to the PDFCreator.ComWrapper. Ultimately I want the prints to be undertaken automatically with file output location and file names present but anything that would get me started would be appreciated.


#2

Hi,

did you already have a look at the C# examples which get installed into the PDFCreator\COM Scripts folder together with PDFCreator? They should be a good starting point, although they aren't related to Revit.

Best regards

Robin


#3

Hi Robin

Thank you for your response it is much appreciated.

I have been going through the examples and what was confusing me was I didn’t appreciate what was happening within the “PrintWindowsTestPage()”. This morning I finally realised (slow me) and the solution became obvious.

Currently working on sorting the paper orientation and size.

Orientation I understand is addressed by “PdfSettings.PageOrientation” and sheet size I am still working on.

Again thank you for your response.


#4

I have been working on this since my last post and Im afraid I just dont understand what im doing wrong.

To keep things simplified I have utilised the c# sample code based on the “testPage_btn_Click” that comes with PDFCreator.
Within the PrintWindowsTestPage() Method I have substituted the original code for a Revit SubmitPrint() routine as below.

private void PrintWindowsTestPage()
        {
            ViewSet ViewSetName = selectViewsData.SelectedViews;
            foreach (Autodesk.Revit.DB.View view in ViewSetName) //For the purpose of the test there is only one view in the ViewSet
            {
                using (Transaction transaction = new Transaction(m_revitDoc, "Print to PDF"))
                {
                    transaction.Start();   
                    PrintManager printManager = m_revitDoc.PrintManager;
                    printManager.PrintSetup.CurrentPrintSetting = printManager.PrintSetup.InSession;
                    printManager.PrintRange=Autodesk.Revit.DB.PrintRange.Select;
                    ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting; 
                    viewSheetSetting.CurrentViewSheetSet.Views=ViewSetName;
                    viewSheetSetting.SaveAs("MyViewSet23");
                    printManager.CombinedFile = true;
                    printManager.PrintToFile=true;
                    PrintSetup pSetup =printManager.PrintSetup;
                    PrintParameters pParam = pSetup.CurrentPrintSetting.PrintParameters;
                    pParam.ZoomType=ZoomType.FitToPage;
                    pParam.PaperPlacement=PaperPlacementType.Center;
                    foreach (Autodesk.Revit.DB.PaperSize pSize in printManager.PaperSizes)
                    {
                        if (pSize.Name.Equals("A1"))// Work required to get actual paper size
                        {
                            pParam.PaperSize=pSize;
                            break;
                        }
                    }
                  
                    printManager.Apply();
                try
                {
                    pSetup.SaveAs("Test");
                }
                catch (Exception ex)
                {
 
                }
                    printManager.SubmitPrint(view);
                    transaction.Commit();
                            
                }
            }
        }

The routine prints the document with the required name in the required location but appears to disregard the Print settings set within the Revit print routine.

I have assumed that once the print settings are set within the Revit routine they do not require setting within the pdfCreator routine?

I have tried to omitted the code “printJob.SetProfileByGuid("DefaultGuid");” from the pdfCreator sample and this appears to have no effect.
Do I need to create my own printJob profile?
If so I can see how for example I could change the sheet profile: printJob.SetProfileSetting("PdfSettings.PageOrientation","Landscape");
But for example how would I change the sheet size?

Can anyone identify what I am doing wrong?


#5

Hi,

PDFCreator should use the page size set by Revit, but the orientation might additionally need to be set inside the PDFCreator settings. You don't need to create a new profile for this but can directly set this for each print job.
The issue could the automatic orientation detection inside PDFCreator, which isn't always able to get the proper orientation, so setting this directly is usually better. Were both the size and orientation incorrect?

Best regards

Robin


#6

Robin
Thanks for your response it is much appreciated.
Yes both paper size and orientation were incorrect.
For clarity the code for PDFCreator is below and is taken from the c# sample

private pdfforge.PDFCreator.UI.ComWrapper.Queue CreateQueue()
{
if (!m_isTypeInitialized)
{
Type queueType = Type.GetTypeFromProgID("PDFCreator.JobQueue");
Activator.CreateInstance(queueType);
m_isTypeInitialized = true;
}

        return new pdfforge.PDFCreator.UI.ComWrapper.Queue();
    }
    private void PrintPDFPageTest()
    {
        var jobQueue = CreateQueue();
        var resultsDir =PDFExportFolderTextBox.Text;
        var convertedFilePath = Path.Combine(resultsDir,"FirstTestPDF.pdf");

        try
        {
            jobQueue.Initialize();
            PrintWindowsTestPage();

            if (!jobQueue.WaitForJob(10))
            {
                 MessageBox.Show("The job didn't arrive within 10 seconds");
            }
            else
            {
                var printJob = jobQueue.NextJob;
                //printJob.SetProfileSetting("PdfSettings.PageOrientation","Landscape");//Tried this and it does affect the orientation.   
                printJob.SetProfileByGuid("DefaultGuid");//Tried with and without this and still same result
                printJob.ConvertTo(convertedFilePath);
                if(!printJob.IsFinished||!printJob.IsSuccessful)
                {
                    MessageBox.Show("Could not be converted:");
                }
            }
        }
        catch(Exception ex)
        {
            MessageBox.Show("An error occurred: "+ex.Message);
            jobQueue.ReleaseCom();
        }
        finally
        {
            jobQueue.ReleaseCom();
        }
    }

Is "printJob.SetProfileByGuid("DefaultGuid");" required or would this override my Revit Print settings?
If I need a new profile I would be grateful if you could clarify how this is done.
You mentioned I dont need to create a new profile to change the orientation, therefore would this be correct "printJob.SetProfileSetting("PdfSettings.PageOrientation","Landscape");"

The more Im testing this I believe my issue is probably with the revit code but I just cannot see why.

Your assistance is much appreciated.

Regards
Stephen


#7

Hi,

there is no need to set the (default) profile, but it won't be the cause of the problem, since not setting any profile will automatically result in using the default profile. The line of code for setting the orientation in your post is correct.
I don't really have any good idea on why the page size isn't as set in Revit. Does everything work if you try it manually?

Best regards

Robin


#8

Hi,
Thank you again for your prompt response and the confirmation regarding (default) profile and the setting of orientation.
Everything works as expected when I plot to PDF manually, which makes me believe it is my the Revit Print Code.
As the revit code is in essence the same if I print to PDFCreator or my HP printer, I have run further tests since my last post and the print settings are still not working. This I believe confirms it is the Revit Print code.
At least I have ruled out the PDFCreator code!
I dont suppose you are familiar with the Revit API?
Regards
Stephen


#9

Hi Stephen,

I am afraid I don|t know anything about the Revit API.
One small thing which might make a difference is the "print to file" option you have set to true; this is usually not recommended and might cause issues, so you could try if disabling it helps.

Best regards

Robin


#10

Hi Robin
Thanks again for the response.
Finally had some success today with both paper size and orientation.
After numerous more tests and amendments to the Revit code with no success I decided to uninstall PDFCreator and reinstall it.
The original installation was left behind by a previous application. The new installation would appear after a few tests to be working like a dream.
Is it possible the Registry had been amended on the previous installation to cause the problems I was experiencing?

Anyway hopefully everything will continue to function as expected.

Again thank you for all you support it has been much appreciated.

Best Regards
Stephen


#11

Old PDFCreator versions did have an option to force a specific paper size and cutting off the rest, so this could have been the cause of the issue (I didn't think of this since these versions are 4-5 years old).