Resize Page


#1

Hi,

Is there an option for Resize Page to Drawing while saving pdf as svg?There exists one in Inkscape but I am using Aspose library in my WPF application.

Thanks,
Aruna


#2

@arunasrathore

Thank you for contacting support.

You may Update Page Dimensions as per your requirements and then convert the PDF to SVG.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.


#3

Thank You for you Reply.

I have a drawing in the PDF.There is a margin between the page and the drawing border.Is there a way to get the dimensions of the drawing and then resize the page to it.
I don’t know the dimensions of drawing as It is a pdf exported from AutoCad.

Thanks,
Aruna


#4

@arunasrathore

Would you please share source file and elaborate expected output so that we may investigate further to help you out.


#5

Sample2.pdf (5.2 KB)
Hi,
PFA.
I am trying to to resize page to drawing after or before I convert to SVG i.e I don’t want the margin between the border and the pageI can do the same using Document properties in Inkscape.

Thanks


#6

@arunasrathore

Thank you for sharing requested data.

You may trim white space on a page with below code snippet:

// load the source PDF document
Document document = new Document(dataDir + "Sample2.pdf");

// get page to trim white space
Page pdfPage = document.Pages[1];

// get the content boundaries
Aspose.Pdf.Rectangle contentBBox = pdfPage.CalculateContentBBox();

// set Page CropBox and MediaBox as per content boundries to tirm white
// space
pdfPage.CropBox = (contentBBox);
pdfPage.MediaBox = (contentBBox);

// save the resultant PDF
document.Save(dataDir + "sample2_19.6.pdf");

We hope this will be helpful. Please feel free to contact us if you need any further assistance.


#7

Hi,
Thank you so much for ur help.This works for the pdf.I am converting pdf to svg after this processing.The sample file that I provided works fine when I do that i.e the margins are not seen both in the pdf as well as the svg.But for some other files even though the pdf is updated ,still the converted svg was same with the margins.I am not sure why its not able to use the updated to be converted to svg for those files.
It works when I again import the pdf .

Here is the code for your reference

                           Document doc = new Document(filePath);
	      
	                doc.OptimizeSize = true;
	                doc.FitWindow = true;
	                doc.OptimizeResources();
	               

	                var docPageInfo = doc.PageInfo.Margin;
	                //replace text that might cause issues with the import
	                PdfContentEditor pdfContentEditor = new PdfContentEditor();
	                pdfContentEditor.BindPdf(doc);
	                //replace text on all pages


	                pdfContentEditor.ReplaceText("< ", "&#60; ");


                        // Get particular page
	                // get page to trim white space
	                Page pdfPage = doc.Pages[1];


                    // get the content boundaries
                    Aspose.Pdf.Rectangle contentBBox = pdfPage.CalculateContentBBox();

	                // set Page CropBox and MediaBox as per content boundries to tirm white
	                // space
	                pdfPage.CropBox = (contentBBox);
	                pdfPage.MediaBox = (contentBBox);
                           doc.Save(filePath);
	                
	                // Instantiate an object of SvgSaveOptions
                    
	                Aspose.Pdf.SvgSaveOptions saveOptions = new Aspose.Pdf.SvgSaveOptions();
	                // Do not compress SVG image to Zip archive
	                saveOptions.CompressOutputToZipArchive = false;
                         
	                doc.Save(Path.Combine(_SourceDirectory, fileName + PfdFileTypes.Svg), saveOptions);

#8

@arunasrathore

Thank you for your kind feedback.

Would you please share source and generated ZIP files so that we may try to reproduce it in our environment.


#9

HSample2.pdf (5.2 KB)
Sample2 (2).pdf (5.6 KB)
ello,
Thanks a lot for your support.There has been another issue which I am trying to troubleshoot.
The behaviour with the sample file has been inconsistent in my application.Though I am using the same code now it doesn’t work.I am attaching both the sample file as well as the output pdf.

It now removes the top and right margin only for this file.For doublechecking I downloaded the same which I provided you.

Thanks


#10

@arunasrathore

We are looking into the scenario and will get back to you shortly.


#11

Thank you.I appreciate your help.


#12

Hi,
I would add this,when the fix is working for any file

pdfPage.CropBox = (contentBBox);
pdfPage.MediaBox = (contentBBox);

it seemed the values are not being set for both CropBox and MediaBox.And when it is working the value of CropBox gets set to the same as ContentBBox but the MediaBox is not set.

I am not able to understand this.I thought its almost the opposite behavior of what I expected.

Thanks again


#13

@arunasrathore

Thank you for contacting support.

Would you please try an alternative approach to Trim White-space Around a Page and then share your kind feedback with us so that we may proceed accordingly.


#14

Thank You so much.This solution works for my original files but doesn’t work still for the sample file that I provided you .I am curious as there is not a a fixed set of pdfs in my application and I am looking for a solution which works on any imported pdf.
On the sample file that I provided you,it still only removes the margin on Top and Right.

Thank You


#15

Hi,

Also wanted to convert text to path in the converted svg.Is there a method in ASPOSE to achieve this?

Thank You


#16

@arunasrathore

Thank you for elaborating further.

We have been able to notice problem with trimming on bottom and left side of the page. Therefore, a ticket with ID PDFNET-46562 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

About SVG, would you please create a separate topic while elaborating it so that we may assist you accordingly.

We are sorry for the inconvenience.


#17

Thank youy so much.As you suggested I will create a separate topic for SVG.


#18

@arunasrathore

Thank you for understanding. Please take your time and create the topic as per your convenience. We will take care of your concerns accordingly.