PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 19, 2024 6:26 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Nov 15, 2016 12:21 pm 
Offline

Joined: Tue Nov 15, 2016 12:12 pm
Posts: 2
Scenario: Enhance an existing feature on the server side to complete the process faster. Using a queue mechanism we have tried to go from sequential process to kind-of parallel processing.

Client invokes a Webmethod on a webservice that takes each page of the PDF and saves it a Bitmap image.

Characteristics:

Each document set will have 20 PDFs.

Concurrent requests: 8-12 (8-12 is the concurrent requests when there is a document package being processed, however there are times when there are no requests to this method at all, this is a shared server.) We do not see the exception when we process one document at a time sequentially.

Typical PDF size = 4-6 pages

One in every 20 PDF will have 20-40 pages

docId-reportId combination is unique, no duplicate requests are sent.

Library used PDFSharp-WPF Version 1.32.2608.0 App/Webservice is in .NET 4.0



Code:
public int SplitReportPDFToImages(int docId, int ReportId, int SortOrder, string filePath)
        {
            int retVal = 0;
            string imagPath = ConfigurationManager.AppSettings["REPORT_SPLIT_IMAGES_FOLDER"];
            imagPath = imagPath + docId.ToString();

            string baseFileName = docId.ToString()+"_"+ReportId.ToString()+"_"+SortOrder.ToString()+"_";

            if (!Directory.Exists(imagPath))
            {
                Directory.CreateDirectory(imagPath);
            }
            try
            {
                PdfXpress gPdfXpress = new PdfXpress();
                Document document = null;

                gPdfXpress.Initialize();
                document = new Document(gPdfXpress, filePath);



                RectangleF selectionInInches = new RectangleF(0.0f, 0.0f, 0.0f, 0.0f);
                SizeF resolutionInDpi = new SizeF(96, 96);
                Bitmap bitmap = null;
                RenderOptions options = new RenderOptions();
                // Create a render options object.
                options.ReduceToBitonal = false;
                options.ResolutionX = (double)resolutionInDpi.Width;
                options.ResolutionY = (double)resolutionInDpi.Height;

                // Express the selection area as userspace units
                const double UserspaceDpi = 72.0;
                options.SelectionX = UserspaceDpi * selectionInInches.Left;
                options.SelectionY = UserspaceDpi * selectionInInches.Bottom;
                options.SelectionWidth = UserspaceDpi * selectionInInches.Width;
                options.SelectionHeight = UserspaceDpi * selectionInInches.Height;

                DataTable dtImagesList = new DataTable();
                dtImagesList.Columns.AddRange(new DataColumn[6] { new DataColumn("docId", typeof(int)), new DataColumn("ReportId", typeof(int)), new DataColumn("SortOrder", typeof(int)), new DataColumn("PageNo", typeof(int)),
                    new DataColumn("ImageFileName", typeof(string)),
                    new DataColumn("ImageHeight", typeof(int)) });

                // Render the selection area to a System.Drawing.Bitmap object instance
                int docPageCount = document.PageCount;
                for (int itr = 0; itr < docPageCount; itr++)
                {
                    int pageShown = itr + 1;
                    bitmap = document.RenderPageToBitmap(itr, options);
                    bitmap.Save(String.Format("{0}\\{1}.gif", imagPath, baseFileName + pageShown.ToString()), ImageFormat.Gif);                   
                    int imageHeight = bitmap.Height;
                    bitmap.Dispose();
                    bitmap = null;
                    dtImagesList.Rows.Add(docId, ReportId, SortOrder, pageShown, baseFileName + pageShown.ToString()+".GIF", imageHeight);
                }
                ProjectDao.InsertImagesList(dtImagesList);
                retVal = 1;
                if (document != null)
                {
                    document.Dispose();
                    document = null;
                }
                if (null != gPdfXpress)
                {
                    gpdfXpress.Dispose();
                    gPdfXpress = null;
                }
                return retVal;
            }
            catch (Exception ex)
            {

                return 0;   
            }
        }


Attachments:
File comment: Details of error in Event Viewer
EventVwr-1.png
EventVwr-1.png [ 13.51 KiB | Viewed 9852 times ]
File comment: Always observed an error in eventviewer that an unhandled win32 exception has occurred.
EventVwr.png
EventVwr.png [ 7.52 KiB | Viewed 9856 times ]
File comment: Debugger instances in Task Manager
TaskManager.png
TaskManager.png [ 12.82 KiB | Viewed 9856 times ]


Last edited by pugaz on Tue Nov 15, 2016 2:39 pm, edited 1 time in total.
Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 15, 2016 1:44 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

Quote:
Always observed an error in eventviewer that an unhandled win32 exception has occurred.
Any details?

You can take the source code version of PDFsharp and compile DLLs with complete debugging information. This could help to get further information about the exception.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 15, 2016 2:41 pm 
Offline

Joined: Tue Nov 15, 2016 12:12 pm
Posts: 2
Thomas Hoevel wrote:
Hi!

Quote:
Always observed an error in eventviewer that an unhandled win32 exception has occurred.
Any details?

You can take the source code version of PDFsharp and compile DLLs with complete debugging information. This could help to get further information about the exception.


I have included screenshot from Event Viewer for the error.

I can try the source code option, just curious is there any limit on the number of PDFXpress objects that can be in memory at the same time or is it limited by memory available?


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 16, 2016 9:20 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
What the heck is "PdfXpress"?
PDFsharp does not make any remote procedure calls AFAIK.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 247 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