X - Pdfviewer question!

Hi,
i have some question about pdfpreviewdialog. can you show me how can i achieve this?
Thanks you!
x.1: can i display total page number in printpreviewdialog?
x.2: how to disable print button on printpreviewdialog?
x.3: can access event mouse_wheel on printpreviewdialog?

9 Replies

US Uthandaraja Selva Sundara Kani Syncfusion Team June 3, 2020 04:02 PM UTC

Hi Khanh, 
 
Thanks for contacting Syncfusion support. 
 
We do not have support to “PrintPreviewDialog in our WinForms PdfViewer control”. However, please confirm us whether you are mentioning the “PrintPreviewDialog class which is available in System.Windows.Forms namespace”. It will be helpful for us to analyze more and provide you a better solution if you confirm on this. Otherwise, please provide more details about your requirement. 
 
Regards, 
Uthandaraja S 



TG The GridLock June 3, 2020 10:13 PM UTC

Hi,
How can I add pdfdocument unsave to pdfviewercontrol ? I just converted it from excelfile
and can i hide them:


Also how do i merge multiple pdffile and load into pdfviewercontrol, i just want to look them temporarily! do i have to save the file and,
I am in a situation where I cannot delete its files and folders after merging many pdf files during debugging. After debugging off, it seems that the file is deleted but the folder is not? (Perhaps the problem lies in the file that hasn't been closed yet after view from pdfviewercontrol.) how can i fix this?


US Uthandaraja Selva Sundara Kani Syncfusion Team June 4, 2020 01:48 PM UTC

Hi Khanh, 
 
Thanks for your update. 
 
Please find the details below, 
 
Query 
Details 
How can I add pdfdocument unsave to pdfviewercontrol ? I just converted it from excelfile 
 
We cannot load the PdfDocument object directly into the PDF viewer without saving it because the complete structure of the PDF file format will be created only after saving the PdfDocument object. It is the behavior of PDF viewer. 
 
 
can i hide them: 
 
 
  
 
 
Yes, we can hide the document toolbar items using pdfViewerControl.ToolbarSettings API. In this API, we have exposed all the buttons which are placed in the document toolbar and we can hide the buttons using its IsVisible property. Please find the code snippet below to hide the open button from document toolbar, 
 
 
// Initilialize the PdfViewerControl. 
PdfViewerControl pdfViewerControl = new PdfViewerControl(); 
 
// Hide the open button of document toolbar 
pdfViewerControl.ToolbarSettings.OpenButton.IsVisible = false; 
 
 
Similarly, we can hide the save, print, navigation, magnification buttons of document toolbar. 
 
We have created the sample for the same and it can be downloaded from below link, 
 
 
 
Also how do i merge multiple pdffile and load into pdfviewercontrol, i just want to look them temporarily! do i have to save the file and, 
 
 
 
We can merge the multiple PDF files to single PDF file without saving it in local disk using Stream instance and we can use the same Stream to load the merged PDF file into PDF viewer the following code snippet, 
 
 
PdfDocument finalDoc = new PdfDocument(); 
 
// Creates a string array of source files to be merged. 
 
string[] source = { @"Barcode.pdf", @"Windows Store Apps Succinctly.pdf" }; 
 
// Merge PDF Document. 
 
PdfDocument.Merge(finalDoc, source); 
 
//Saves the final document 
 
MemoryStream stream = new MemoryStream(); 
 
finalDoc.Save(stream); 
 
// Initilialize the PdfViewerControl. 
PdfViewerControl pdfViewerControl = new PdfViewerControl(); 
 
// Load the merged PDF document. 
pdfViewerControl.Load(mergedStream); 
 
 
We have created the sample for the same and it can be downloaded from below link, 
 
 
 
I am in a situation where I cannot delete its files and folders after merging many pdf files during debugging. After debugging off, it seems that the file is deleted but the folder is not? (Perhaps the problem lies in the file that hasn't been closed yet after view from pdfviewercontrol.) how can i fix this? 
 
 
We are unable to reproduce the issue “Could not delete the PDF document which is loaded in PdfViewerControl” in our side. Please find the code snippet below to delete the loaded PDF document, 
 
 
//Load the file. 
pdfViewerControl.Load(@"../../Data/Barcode.pdf"); 
 
// Delete the used files. 
File.Delete(@"../../Data/Barcode.pdf"); 
 
 
Also, we tried to delete the file and directory manually and it deletes correctly. 
 
Kindly modify the provided sample and share it to us to reproduce the issue at our end. It will be helpful for us to analyse more on this and assist you a better solution. 
 
 
Regards, 
Uthandaraja S 



TG The GridLock June 4, 2020 11:27 PM UTC

Hi Uthandaraja,
Here are the steps in my code.
-1st,  create a temporary folder 
-2nd, creat some pdf files and put to this folder 
-3rd, merge these pdf files to one pdf file named: pdf0
-4th, view pdf0 in pdfviewercontrol
-5th, close pdfviewer -> i can save or delete pdf0
now if I delete file and temporary folder(using code file.delete -> directory.delete(path)) [from step 2] -> i can't. can you check this? 
More question: when i convert chart to pdf, can i save this pdffile to memorystream? when i load file to pdfviewer or save file get an blank file!


US Uthandaraja Selva Sundara Kani Syncfusion Team June 5, 2020 12:05 PM UTC

Hi Khanh, 
 
Thanks for your update. 
 
Please find the details below, 
 
Query 
Details 
Here are the steps in my code. 
-1st,  create a temporary folder  
-2nd, creat some pdf files and put to this folder  
-3rd, merge these pdf files to one pdf file named: pdf0 
-4th, view pdf0 in pdfviewercontrol 
-5th, close pdfviewer -> i can save or delete pdf0 
now if I delete file and temporary folder(using code file.delete -> directory.delete(path)) [from step 2] -> i can't. can you check this? 
 
We are unable to reproduce the reported issue in our side with the provided details. Kindly refer the sample from below link to reproduce issue at our end. 
 
 
Please share the below details to analyze more on this and assist you a better solution. 
 
1.       Simple / Modify the sample to reproduce the issue. 
2.       Syncfusion product version. 
3.       Net Framework. 
4.       Visual Studio 
5.       Operating System. 
 
 
More question: when i convert chart to pdf, can i save this pdffile to memorystream? when i load file to pdfviewer or save file get an blank file! 
 
 
Yes, we can save the Chart to PDF file to memory stream and load it in PdfViewer with the below code snippet, 
 
 
            // Intilialize PdfViewerControl. 
            ChartControl chartControl = new ChartControl(); 
 
            // Save the chart to image. 
            chartControl.SaveImage(@"Output.png"); 
 
            //Create a PDF document 
            PdfDocument pdfDoc = new PdfDocument(); 
 
            //Add a page to the empty PDF document 
            pdfDoc.Pages.Add(); 
 
            //Draw chart image in the first page 
            pdfDoc.Pages[0].Graphics.DrawImage(PdfImage.FromFile(@"Output.png"), new PointF(10, 30)); 
 
            //Save the PDF Document to disk. 
            MemoryStream stream = new MemoryStream(); 
 
            pdfDoc.Save(stream); 
 
            PdfViewerControl pdfViewerControl = new PdfViewerControl(); 
 
            pdfViewerControl.Dock = DockStyle.Fill; 
 
            this.Controls.Add(pdfViewerControl); 
             
            pdfViewerControl.Load(stream); 
 
 
We have created the sample for the same and it can be downloaded from below link, 
 
 
Also, we did not face any issue while save the loaded PDF file. If you still facing the mentioned issue, please share the modified sample to reproduce the issue in our side with the below details, 
 
1.       Syncfusion product version. 
2.       Net Framework. 
3.       Visual Studio 
4.       Operating System. 
 
 
 
Regards, 
Uthandaraja S 



TG The GridLock June 6, 2020 07:53 AM UTC

Hi Uthandaraja,
i want to combine this with your code.
Can I store chart in the stream then load to pdfviewercontrol without saving the .png file? (Does saving the .png file affect the folder?
My problem is that
-your code working but if I use drawimage (from your code) , I have a hard time knowing the width and the height and the location of the image almost to the left of the paper.
-While if I use exceltopdfconvert it will always put the image in the middle of the paper and i have a scale image setting but I cannot save it as a pdf when using this method(it returns a blank file)


US Uthandaraja Selva Sundara Kani Syncfusion Team June 8, 2020 12:18 PM UTC

Hi Khanh, 
 
Thanks for your update. 
 
Please find the details below, 
 
Query 
Details 
 
Can I store chart in the stream then load to pdfviewercontrol without saving the .png file? (Does saving the .png file affect the folder? 
 
 
Currently we don't have direct support to achieve your requirement without saving that to image. 
 
your code working but if I use drawimage (from your code) , I have a hard time knowing the width and the height and the location of the image almost to the left of the paper. 
 
 
We can specify the position (X and Y) of the image where we want to start the image using that drawimage method. And we can also mentioned the width and height of that image, based on that size it will be rendered. If we did not mention the width and height, then the image width and height will be used internally to draw the images.   
 
 
While if I use exceltopdfconvert it will always put the image in the middle of the paper and i have a scale image setting but I cannot save it as a pdf when using this method(it returns a blank file) 
 
We suspect that the issue might be code snippet and request you to share the scale image setting you are using, along with complete code snippet of Excel To Pdf Conversion, which will be helpful for us in investigating the query. 
 
 
Regards, 
Uthandaraja S 



TG The GridLock June 9, 2020 07:17 PM UTC

hi Uthandaraja,
Thanks a lot for the info, I'll find out more about this.


US Uthandaraja Selva Sundara Kani Syncfusion Team June 10, 2020 06:06 AM UTC

Hi Khanh, 
 
Most welcome. please let us know if you need any further assistance. 
 
Regards, 
Uthandaraja S 


Loader.
Up arrow icon